Skip to content

First support for testing containers. #9

First support for testing containers.

First support for testing containers. #9

Workflow file for this run

# MIT License
#
# Copyright (c) 2018 sclorg team at Red Hat
#
# Upload a Python package when a release is created
# https://packaging.python.org/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows
name: Test PR for container-ci-suite
on:
issue_comment:
types: [created]
jobs:
build:
# This job only runs for '[test]' pull request comments by owner, member
name: Schedule test on Testing Farm service for Fedora
runs-on: ubuntu-latest
if: |
github.event.issue.pull_request
&& contains(github.event.comment.body, '/test')
&& contains(fromJson('["OWNER","MEMBER"]'), github.event.comment.author_association)
steps:
- name: Get pull request number
id: pr_nr
run: |
PR_URL="${{ github.event.comment.issue_url }}"
echo "::set-output name=PR_NR::${PR_URL##*/}"
- name: Checkout repo
uses: actions/checkout@v2
with:
ref: "refs/pull/${{ steps.pr_nr.outputs.PR_NR }}/head"
- name: Get sha
id: sha
run: |
# Store SHA into outputs
echo "::set-output name=SHA::$(git rev-parse HEAD)"
- name: Schedule a test on Testing Farm for Fedora
id: sched_test
run: |
# Update ubuntu-latest in order to install curl and jq
sudo apt-get update && sudo apt-get -y install curl jq
cat << EOF > request.json
{
"api_key": "${{ secrets.TF_PUBLIC_API_KEY }}",
"test": {"fmf": {
"url": "https://github.com/sclorg/sclorg-testing-farm",
"ref": "main",
"name": "container-ci-suite"
}},
"environments": [{
"arch": "x86_64",
"os": {"compose": "Fedora-34"},
"variables": {
"REPO_URL": "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY",
"REPO_NAME": "$GITHUB_REPOSITORY",
"PR_NUMBER": "${{ steps.pr_nr.outputs.PR_NR }}"
}
}]
}
EOF
cat request.json
curl ${{ secrets.TF_ENDPOINT }}/requests --data @request.json --header "Content-Type: application/json" --output response.json
cat response.json
req_id=$(jq -r .id response.json)
echo "$req_id"
# Store REQ_ID into outputs for later on usage
echo "::set-output name=REQ_ID::$req_id"
outputs:
REQ_ID: ${{ steps.sched_test.outputs.REQ_ID }}
SHA: ${{ steps.sha.outputs.SHA }}
running:
needs: build
name: Check running tests on Testing Farm service
runs-on: ubuntu-20.04
outputs:
REQ_ID: ${{ steps.req_sha.outputs.REQ_ID }}
SHA: ${{ steps.req_sha.outputs.SHA }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Check if REQ_ID and SHA exists
id: req_sha
run: |
# Update ubuntu-20.04 in order to install curl and jq
# each job is separate machine
sudo apt-get update && sudo apt-get -y install curl jq
# Propagate REQ_ID and SHA into the finish section
echo "::set-output name=REQ_ID::${{ needs.build.outputs.REQ_ID }}"
echo "::set-output name=SHA::${{ needs.build.outputs.SHA }}"
- name: Switch to running state of Testing Farm request
id: running
run: |
# Create running.json file for query, whether job is finished or not.
cat << EOF > running.json
{
"sha": "${{ needs.build.outputs.SHA }}",
"state": "pending",
"context": "Testing Farm",
"description": "Build started",
"target_url": "http://artifacts.dev.testing-farm.io/${{ needs.build.outputs.REQ_ID }}/"
}
EOF
# Update GitHub status description to 'Build started'
curl -X POST -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$GITHUB_REPOSITORY/statuses/${{ needs.build.outputs.SHA }} \
--data @running.json
- name: Check test is still running
id: still_running
run: |
CMD=${{ secrets.TF_ENDPOINT }}/requests/${{ needs.build.outputs.REQ_ID }}
curl $CMD > job.json
state=$(jq -r .state job.json)
# Wait till job is not finished. As soon as state is complete or failure then go to the finish action
while [ "$state" == "running" ] || [ "$state" == "new" ] || [ "$state" == "pending" ] || [ "$state" == "queued" ]; do
# Wait 30s. We do not need to query Testing Farm each second
sleep 30
curl $CMD > job.json
state=$(jq -r .state job.json)
done
finish:
needs: running
name: Tests are finished - switching to proper state
runs-on: ubuntu-20.04
steps:
- name: Check if REQ_ID exists
run: echo "${{ needs.running.outputs.REQ_ID }}"
- name: Check if SHA exists
run: echo "${{ needs.running.outputs.SHA }}"
- name: Get final state of Testing Farm request
id: final_state
run: |
# Update ubuntu-20.04 in order to install curl and jq
# each job is separate machine
sudo apt-get update && sudo apt-get -y install curl jq
curl ${{ secrets.TF_ENDPOINT }}/requests/${{ needs.running.outputs.REQ_ID }} > job.json
cat job.json
state=$(jq -r .state job.json)
result=$(jq -r .result.overall job.json)
new_state="success"
infra_error=" "
echo "State is $state and result is: $result"
if [ "$state" == "complete" ]; then
if [ "$result" != "passed" ]; then
new_state="failure"
fi
else
# Mark job in case of infrastructure issues. Report to Testing Farm team
infra_error=" - Infra problems"
new_state="failure"
fi
echo "New State is: $new_state"
echo "Infra state is: $infra_error"
echo "::set-output name=FINAL_STATE::$new_state"
echo "::set-output name=INFRA_STATE::$infra_error"
- name: Switch to final state of Testing Farm request
run: |
cat << EOF > final.json
{
"sha": "${{needs.running.outputs.SHA}}",
"state": "${{steps.final_state.outputs.FINAL_STATE}}",
"context": "Testing Farm",
"description": "Build finished${{steps.final_state.outputs.INFRA_STATE}}",
"target_url": "http://artifacts.dev.testing-farm.io/${{ needs.running.outputs.REQ_ID }}/"
}
EOF
cat final.json
# Switch Github status to proper state
curl -X POST -H "Authorization: Bearer ${{secrets.GITHUB_TOKEN}}" -H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$GITHUB_REPOSITORY/statuses/${{ needs.running.outputs.SHA }} \
--data @final.json