From dabfbe38250f644277803214ff22ac898d1c3f07 Mon Sep 17 00:00:00 2001 From: Kabir Khan Date: Thu, 5 Sep 2024 17:05:38 +0200 Subject: [PATCH] Add trigger and reporter for new cloud tests job --- .github/workflows/cloud-test-pr-reporter.yml | 53 +++++++ .../workflows/cloud-test-pr-trigger-old.yml | 134 ++++++++++++++++++ .github/workflows/cloud-test-pr-trigger.yml | 125 ++++++++-------- 3 files changed, 245 insertions(+), 67 deletions(-) create mode 100644 .github/workflows/cloud-test-pr-reporter.yml create mode 100644 .github/workflows/cloud-test-pr-trigger-old.yml diff --git a/.github/workflows/cloud-test-pr-reporter.yml b/.github/workflows/cloud-test-pr-reporter.yml new file mode 100644 index 000000000000..37ed4c6b673a --- /dev/null +++ b/.github/workflows/cloud-test-pr-reporter.yml @@ -0,0 +1,53 @@ +name: Report Cloud Test Status +on: + repository_dispatch: + types: [report-cloud-tests-pr-pending, report-cloud-tests-pr-complete] +env: + DESC: ${{ github.event.client_payload.desc }} + GH_TOKEN: ${{ github.token }} + PR_HEAD_SHA: ${{ github.event.client_payload.prHeadSha }} + RUN_URL: ${{ github.event.client_payload.runUrl }} + STATE: ${{ github.event.client_payload.state }} + +jobs: + reporter: + permissions: + checks: write + statuses: write + runs-on: ubuntu-latest + steps: + - name: Output + env: + #MESSAGE: ${{ github.event.client_payload.message }} + MESSAGE: ${{ toJSON(github.event.client_payload) }} + run: echo $MESSAGE + + - name: Report status + run: | + JSON_STRING=$(jq -c -n \ + --arg state "$STATE" \ + --arg tgt "$RUN_URL" \ + --arg desc "$DESC" \ + '{state: $state, target_url: $tgt, description: $desc, context: "Cloud Tests Remote Run"}' ) + + set -x + + resp=$(curl -L -X POST \ + -H "Accept: application/vnd.github.v3+json" \ + -H "Authorization: Bearer ${GH_TOKEN}"\ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/${{ github.repository }}/statuses/${PR_HEAD_SHA} \ + -d "${JSON_STRING}") + + ret=$? + + set +x + + if [ $ret -eq 0 ]; then + sleep 2 + else + echo "Workflow failed to trigger" + echo "$resp" + exit 1 + fi + diff --git a/.github/workflows/cloud-test-pr-trigger-old.yml b/.github/workflows/cloud-test-pr-trigger-old.yml new file mode 100644 index 000000000000..6f3aa9cbec94 --- /dev/null +++ b/.github/workflows/cloud-test-pr-trigger-old.yml @@ -0,0 +1,134 @@ +name: Cloud Tests Trigger Old +on: + pull_request_target: + branches: + - main + paths-ignore: + - ".mvn/**" + - "docs/**" + - ".github/workflows/build-manual.yml" + - ".github/workflows/shared-wildfly-build.yml" + - '.gitattributes' + - '.gitignore' + - '.gitleaks.toml' + - 'build.bat' + - 'build.sh' + - "CODE_OF_CONDUCT.md" + - "CONTRIBUTING.md" + - "integration-tests.bat" + - "integration-tests.sh" + - "LICENSE.txt" + - "mvnw" + - "mvnw.cmd" + - "README.md" + - "SECURITY.md" + - "**/README.md" + - "**/README.adoc" + +# Only run the latest job +concurrency: + group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' + cancel-in-progress: true +env: + # Repository where the cloud tests will be run + REPOSITORY: wildfly-extras/wildfly-cloud-tests + # Branch in the above repository where the remote job will commit its results + STATUS_BRANCH: run-status + # This must be set to a PAT with 'repo' permission for the target repository + TOKEN: ${{ secrets.REMOTE_DISPATCH_TOKEN }} + # Just an identifier for the event - this one triggers the cloud tests + EVENT_TYPE: trigger-cloud-tests-run + # Parameters for polling the $STATUS_BRANCH for the results (they currently take 18-25 minutes) + # Initial wait before polling starts + RESULT_INITIAL_WAIT_SECONDS: 1200 + # Time between each poll + RESULT_POLL_WAIT_SECONDS: 300 + # Maximum number of polls before we time out + RESULT_MAX_POLL_ATTEMPTS: 10 +permissions: {} +jobs: + run-tests: + runs-on: ubuntu-latest + steps: + + - name: Checkout run-status branch + if: ${{ env.TOKEN }} + uses: actions/checkout@v4 + with: + repository: ${{ env.REPOSITORY }} + ref: ${{ env.STATUS_BRANCH }} + + - name: Remote Dispatch + if: ${{ env.TOKEN }} + run: | + echo $GITHUB_REPOSITORY + FILENAME="$GITHUB_RUN_ID-$GITHUB_RUN_NUMBER-$GITHUB_RUN_ATTEMPT.json" + echo "FILENAME=$FILENAME" >> $GITHUB_ENV + + REFERENCE="refs/pull/${{github.event.number}}/merge" + + CLIENT_PAYLOAD=$( jq -n \ + --arg tr "$GITHUB_REPOSITORY" \ + --arg ref "$REFERENCE" \ + --arg sf "$FILENAME" \ + '{triggerRepo: $tr, ref: $ref, statusFile: $sf}' ) + + echo "CLIENT_PAYLOAD: $CLIENT_PAYLOAD" + + resp=$(curl -X POST -s "https://api.github.com/repos/${REPOSITORY}/dispatches" \ + -H "Accept: application/vnd.github.v3+json" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${TOKEN}" \ + -d "{\"event_type\": \"${EVENT_TYPE}\", \"client_payload\": ${CLIENT_PAYLOAD} }") + if [ -z "$resp" ] + then + sleep 2 + else + echo "Workflow failed to trigger" + echo "$resp" + exit 1 + fi + - name: Wait for remote job completion + if: ${{ env.TOKEN }} + run: | + echo "Waiting/polling for remote test execution to complete" + echo "Sleeping $RESULT_INITIAL_WAIT_SECONDS seconds before polling" + sleep $RESULT_INITIAL_WAIT_SECONDS + i=0 + while [[ "${RESULT}" != '0' ]] + do + echo "debug - fetching" + git fetch origin + echo "debug - resetting" + git reset --hard origin/$STATUS_BRANCH + + echo "debug - is $FILENAME there?" + # Check file is there and break if it is + if [ -f "$FILENAME" ]; then + echo "debug - file is there" + break + fi + + + echo "debug - incrementing counter" + i=$((i+1)) + echo "debug - checking max poll attempts" + if [ $i -eq $RESULT_MAX_POLL_ATTEMPTS ]; then + 1>&2 echo "Timeout receiving the results" + exit 1 + fi + echo "Sleeping $RESULT_POLL_WAIT_SECONDS seconds before polling again" + sleep $RESULT_POLL_WAIT_SECONDS + done + # cat $FILENAME + STATUS="$(jq -r .status $FILENAME)" + MESSAGE="$(jq -r .message $FILENAME)" + + # echo "Status: $STATUS" + + if [[ "${STATUS}" == "failed" ]]; then + echo -e "\e[31m${MESSAGE}\e[0m" + exit 1 + fi + + echo -e "\e[32m${MESSAGE}\e[0m" diff --git a/.github/workflows/cloud-test-pr-trigger.yml b/.github/workflows/cloud-test-pr-trigger.yml index e0ee7166f765..f4a7622052cf 100644 --- a/.github/workflows/cloud-test-pr-trigger.yml +++ b/.github/workflows/cloud-test-pr-trigger.yml @@ -32,54 +32,45 @@ concurrency: env: # Repository where the cloud tests will be run REPOSITORY: wildfly-extras/wildfly-cloud-tests - # Branch in the above repository where the remote job will commit its results - STATUS_BRANCH: run-status # This must be set to a PAT with 'repo' permission for the target repository - TOKEN: ${{ secrets.REMOTE_DISPATCH_TOKEN }} + TOKEN: ${{ secrets.CLOUD_TESTS_REMOTE_DISPATCH_TOKEN }} # Just an identifier for the event - this one triggers the cloud tests - EVENT_TYPE: trigger-cloud-tests-run - # Parameters for polling the $STATUS_BRANCH for the results (they currently take 18-25 minutes) - # Initial wait before polling starts - RESULT_INITIAL_WAIT_SECONDS: 1200 - # Time between each poll - RESULT_POLL_WAIT_SECONDS: 300 - # Maximum number of polls before we time out - RESULT_MAX_POLL_ATTEMPTS: 10 + EVENT_TYPE: trigger-cloud-tests-pr + permissions: {} jobs: run-tests: runs-on: ubuntu-latest steps: - - name: Checkout run-status branch - if: ${{ env.TOKEN }} - uses: actions/checkout@v4 - with: - repository: ${{ env.REPOSITORY }} - ref: ${{ env.STATUS_BRANCH }} - - name: Remote Dispatch + env: + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} if: ${{ env.TOKEN }} run: | echo $GITHUB_REPOSITORY - FILENAME="$GITHUB_RUN_ID-$GITHUB_RUN_NUMBER-$GITHUB_RUN_ATTEMPT.json" + echo "FILENAME=$FILENAME" >> $GITHUB_ENV - REFERENCE="refs/pull/${{github.event.number}}/merge" CLIENT_PAYLOAD=$( jq -n \ --arg tr "$GITHUB_REPOSITORY" \ - --arg ref "$REFERENCE" \ - --arg sf "$FILENAME" \ - '{triggerRepo: $tr, ref: $ref, statusFile: $sf}' ) + --arg githubSha "$GITHUB_SHA" \ + --arg prHeadSha "$PR_HEAD_SHA" \ + '{triggerRepo: $tr, githubSha: $githubSha, prHeadSha: $prHeadSha}' ) echo "CLIENT_PAYLOAD: $CLIENT_PAYLOAD" + set -x + resp=$(curl -X POST -s "https://api.github.com/repos/${REPOSITORY}/dispatches" \ -H "Accept: application/vnd.github.v3+json" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer ${TOKEN}" \ -d "{\"event_type\": \"${EVENT_TYPE}\", \"client_payload\": ${CLIENT_PAYLOAD} }") + + set +x + if [ -z "$resp" ] then sleep 2 @@ -88,47 +79,47 @@ jobs: echo "$resp" exit 1 fi - - name: Wait for remote job completion - if: ${{ env.TOKEN }} - run: | - echo "Waiting/polling for remote test execution to complete" - echo "Sleeping $RESULT_INITIAL_WAIT_SECONDS seconds before polling" - sleep $RESULT_INITIAL_WAIT_SECONDS - i=0 - while [[ "${RESULT}" != '0' ]] - do - echo "debug - fetching" - git fetch origin - echo "debug - resetting" - git reset --hard origin/$STATUS_BRANCH - - echo "debug - is $FILENAME there?" - # Check file is there and break if it is - if [ -f "$FILENAME" ]; then - echo "debug - file is there" - break - fi - - - echo "debug - incrementing counter" - i=$((i+1)) - echo "debug - checking max poll attempts" - if [ $i -eq $RESULT_MAX_POLL_ATTEMPTS ]; then - 1>&2 echo "Timeout receiving the results" - exit 1 - fi - echo "Sleeping $RESULT_POLL_WAIT_SECONDS seconds before polling again" - sleep $RESULT_POLL_WAIT_SECONDS - done - # cat $FILENAME - STATUS="$(jq -r .status $FILENAME)" - MESSAGE="$(jq -r .message $FILENAME)" - - # echo "Status: $STATUS" - - if [[ "${STATUS}" == "failed" ]]; then - echo -e "\e[31m${MESSAGE}\e[0m" - exit 1 - fi - - echo -e "\e[32m${MESSAGE}\e[0m" +# - name: Wait for remote job completion +# if: ${{ env.TOKEN }} +# run: | +# echo "Waiting/polling for remote test execution to complete" +# echo "Sleeping $RESULT_INITIAL_WAIT_SECONDS seconds before polling" +# sleep $RESULT_INITIAL_WAIT_SECONDS +# i=0 +# while [[ "${RESULT}" != '0' ]] +# do +# echo "debug - fetching" +# git fetch origin +# echo "debug - resetting" +# git reset --hard origin/$STATUS_BRANCH +# +# echo "debug - is $FILENAME there?" +# # Check file is there and break if it is +# if [ -f "$FILENAME" ]; then +# echo "debug - file is there" +# break +# fi +# +# +# echo "debug - incrementing counter" +# i=$((i+1)) +# echo "debug - checking max poll attempts" +# if [ $i -eq $RESULT_MAX_POLL_ATTEMPTS ]; then +# 1>&2 echo "Timeout receiving the results" +# exit 1 +# fi +# echo "Sleeping $RESULT_POLL_WAIT_SECONDS seconds before polling again" +# sleep $RESULT_POLL_WAIT_SECONDS +# done +# # cat $FILENAME +# STATUS="$(jq -r .status $FILENAME)" +# MESSAGE="$(jq -r .message $FILENAME)" +# +# # echo "Status: $STATUS" +# +# if [[ "${STATUS}" == "failed" ]]; then +# echo -e "\e[31m${MESSAGE}\e[0m" +# exit 1 +# fi +# +# echo -e "\e[32m${MESSAGE}\e[0m"