From 5bb9da3c0d49449245fade9813e9a48dfa6d76ad Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Fri, 28 Jul 2023 07:04:16 +0200 Subject: [PATCH] Refactor conditional in GH workflows (#22020) Closes #22019 --- .github/actions/checks-job-pass/action.yml | 34 ---------------------- .github/actions/checks-success/action.yml | 16 ---------- .github/actions/status-check/action.yml | 27 +++++++++++++++++ .github/workflows/ci.yml | 29 ++++-------------- .github/workflows/codeql-analysis.yml | 24 ++++----------- .github/workflows/documentation.yml | 25 ++-------------- .github/workflows/guides.yml | 25 ++-------------- .github/workflows/js-ci.yml | 27 ++++------------- .github/workflows/operator-ci.yml | 29 ++++-------------- 9 files changed, 53 insertions(+), 183 deletions(-) delete mode 100644 .github/actions/checks-job-pass/action.yml delete mode 100644 .github/actions/checks-success/action.yml create mode 100644 .github/actions/status-check/action.yml diff --git a/.github/actions/checks-job-pass/action.yml b/.github/actions/checks-job-pass/action.yml deleted file mode 100644 index 30b782a7e8..0000000000 --- a/.github/actions/checks-job-pass/action.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Check if a job passed -description: Fails if the job is required and was not successful - -inputs: - required: - description: Is the job required - required: true - default: true - conclusion: - description: Job conclusion (success if passed, most likely empty otherwise) - required: true - -outputs: - status: - description: "Check status" - value: ${{ steps.changes.outputs.java }} - -runs: - using: "composite" - steps: - - id: check-job - name: Check job - shell: bash - run: | - if [ "${{ inputs.required }}" == "false" ]; then - echo "Not required to run, skipping" - else - if [ "${{ inputs.conclusion }}" == "success" ]; then - echo "Success" - else - echo "Required to run, but didn't succeed" - exit 1 - fi - fi diff --git a/.github/actions/checks-success/action.yml b/.github/actions/checks-success/action.yml deleted file mode 100644 index 64377fb426..0000000000 --- a/.github/actions/checks-success/action.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Mark job as successful -description: Workaround for GitHub Actions not setting conclusion on jobs passed through needs - -outputs: - conclusion: - description: Conclusion - value: ${{ steps.check.outputs.conclusion }} - -runs: - using: composite - steps: - - id: check - name: Set success - shell: bash - run: | - echo "conclusion=success" >> $GITHUB_OUTPUT diff --git a/.github/actions/status-check/action.yml b/.github/actions/status-check/action.yml new file mode 100644 index 0000000000..2c832764ea --- /dev/null +++ b/.github/actions/status-check/action.yml @@ -0,0 +1,27 @@ +name: Check required jobs +description: Check if all required jobs where successful or skipped + +inputs: + jobs: + description: Jobs (value must be toJSON(needs)) + required: true + +runs: + using: "composite" + steps: + - id: check-jobs + name: Check jobs + shell: bash + run: | + JOBS='${{ inputs.jobs }}' + + echo "Job status:" + echo $JOBS | jq -r 'to_entries[] | " - \(.key): \(.value.result)"' + + for i in $(echo $JOBS | jq -r 'to_entries[] | .value.result'); do + if [ "$i" != "success" ] && [ "$i" != "skipped" ]; then + echo "" + echo "Status check not okay!" + exit 1 + fi + done diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 182bf0ff41..4463140def 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -572,8 +572,9 @@ jobs: with: job-name: Migration Tests - check-set-status: - name: Set check conclusion + check: + name: Status Check - Keycloak CI + if: always() needs: - unit-tests - base-integration-tests @@ -591,28 +592,8 @@ jobs: - sssd-unit-tests - migration-tests runs-on: ubuntu-latest - outputs: - conclusion: ${{ steps.check.outputs.conclusion }} - steps: - uses: actions/checkout@v3 - - - id: check - uses: ./.github/actions/checks-success - - check: - name: Status Check - Keycloak CI - if: always() - needs: - - conditional - - check-set-status - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Check status - uses: ./.github/actions/checks-job-pass + - uses: ./.github/actions/status-check with: - required: ${{ needs.conditional.outputs.ci }} - conclusion: ${{ needs.check-set-status.outputs.conclusion }} + jobs: ${{ toJSON(needs) }} diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 0500c485a1..94f0ede8a4 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -60,9 +60,6 @@ jobs: env: CODEQL_ACTION_EXTRA_OPTIONS: '{"database":{"interpret-results":["--max-paths",0]}}' - - id: check - uses: ./.github/actions/checks-success - themes: name: CodeQL Themes needs: conditional @@ -89,26 +86,15 @@ jobs: env: CODEQL_ACTION_EXTRA_OPTIONS: '{"database":{"interpret-results":["--max-paths",0]}}' - - id: check - uses: ./.github/actions/checks-success - check: name: Status Check - CodeQL if: always() - needs: [conditional, java, themes] + needs: + - java + - themes runs-on: ubuntu-latest - steps: - uses: actions/checkout@v3 - - - name: CodeQL Java - uses: ./.github/actions/checks-job-pass + - uses: ./.github/actions/status-check with: - required: ${{ needs.conditional.outputs.java }} - conclusion: ${{ needs.java.outputs.conclusion }} - - - name: CodeQL Themes - uses: ./.github/actions/checks-job-pass - with: - required: ${{ needs.conditional.outputs.themes }} - conclusion: ${{ needs.themes.outputs.conclusion }} + jobs: ${{ toJSON(needs) }} diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 65898867fb..0f6988213e 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -98,33 +98,14 @@ jobs: run: | ./mvnw test -Dtest=ExternalLinksTest -am -pl docs/documentation/tests,docs/documentation/dist -nsu -B -e -Pdocumentation - check-set-status: - name: Set check conclusion - needs: - - build - runs-on: ubuntu-latest - outputs: - conclusion: ${{ steps.check.outputs.conclusion }} - - steps: - - uses: actions/checkout@v3 - - - id: check - uses: ./.github/actions/checks-success - check: name: Status Check - Keycloak Documentation if: always() needs: - - conditional - - check-set-status + - build runs-on: ubuntu-latest - steps: - uses: actions/checkout@v3 - - - name: Check status - uses: ./.github/actions/checks-job-pass + - uses: ./.github/actions/status-check with: - required: ${{ needs.conditional.outputs.documentation == 'true' }} - conclusion: ${{ needs.check-set-status.outputs.conclusion }} + jobs: ${{ toJSON(needs) }} \ No newline at end of file diff --git a/.github/workflows/guides.yml b/.github/workflows/guides.yml index b295581ff5..3a70163d10 100644 --- a/.github/workflows/guides.yml +++ b/.github/workflows/guides.yml @@ -45,33 +45,14 @@ jobs: - name: Build Keycloak uses: ./.github/actions/build-keycloak - check-set-status: - name: Set check conclusion - needs: - - build - runs-on: ubuntu-latest - outputs: - conclusion: ${{ steps.check.outputs.conclusion }} - - steps: - - uses: actions/checkout@v3 - - - id: check - uses: ./.github/actions/checks-success - check: name: Status Check - Keycloak Guides if: always() needs: - - conditional - - check-set-status + - build runs-on: ubuntu-latest - steps: - uses: actions/checkout@v3 - - - name: Check status - uses: ./.github/actions/checks-job-pass + - uses: ./.github/actions/status-check with: - required: ${{ needs.conditional.outputs.guides == 'true' && needs.conditional.outputs.ci != 'true' }} - conclusion: ${{ needs.check-set-status.outputs.conclusion }} + jobs: ${{ toJSON(needs) }} diff --git a/.github/workflows/js-ci.yml b/.github/workflows/js-ci.yml index 453289eca7..e61d2d13c9 100644 --- a/.github/workflows/js-ci.yml +++ b/.github/workflows/js-ci.yml @@ -265,8 +265,9 @@ jobs: name: server-log-${{ matrix.container }}-${{ matrix.browser }} path: ~/server.log - check-set-status: - name: Set check conclusion + check: + name: Status Check - Keycloak JavaScript CI + if: always() needs: - admin-client - keycloak-js @@ -276,26 +277,8 @@ jobs: - admin-ui - admin-ui-e2e runs-on: ubuntu-latest - outputs: - conclusion: ${{ steps.check.outputs.conclusion }} steps: - uses: actions/checkout@v3 - - - id: check - uses: ./.github/actions/checks-success - - check: - name: Status Check - Keycloak JavaScript CI - if: always() - needs: - - conditional - - check-set-status - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Check status - uses: ./.github/actions/checks-job-pass + - uses: ./.github/actions/status-check with: - required: ${{ needs.conditional.outputs.js-ci }} - conclusion: ${{ needs.check-set-status.outputs.conclusion }} + jobs: ${{ toJSON(needs) }} diff --git a/.github/workflows/operator-ci.yml b/.github/workflows/operator-ci.yml index a6221288be..639d1b98ef 100644 --- a/.github/workflows/operator-ci.yml +++ b/.github/workflows/operator-ci.yml @@ -199,35 +199,16 @@ jobs: # Wait for the CRs to be ready ./scripts/check-examples-installed.sh - check-set-status: - name: Set check conclusion + check: + name: Status Check - Keycloak Operator CI + if: always() needs: - test-local - test-remote - test-olm runs-on: ubuntu-latest - outputs: - conclusion: ${{ steps.check.outputs.conclusion }} - steps: - uses: actions/checkout@v3 - - - id: check - uses: ./.github/actions/checks-success - - check: - name: Status Check - Keycloak Operator CI - if: always() - needs: - - conditional - - check-set-status - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Check status - uses: ./.github/actions/checks-job-pass + - uses: ./.github/actions/status-check with: - required: ${{ needs.conditional.outputs.operator }} - conclusion: ${{ needs.check-set-status.outputs.conclusion }} + jobs: ${{ toJSON(needs) }}