Refactor conditional in GH workflows (#22020)

Closes #22019
This commit is contained in:
Stian Thorgersen 2023-07-28 07:04:16 +02:00 committed by GitHub
parent 12eb81580e
commit 5bb9da3c0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 53 additions and 183 deletions

View file

@ -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

View file

@ -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

27
.github/actions/status-check/action.yml vendored Normal file
View file

@ -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

View file

@ -572,8 +572,9 @@ jobs:
with: with:
job-name: Migration Tests job-name: Migration Tests
check-set-status: check:
name: Set check conclusion name: Status Check - Keycloak CI
if: always()
needs: needs:
- unit-tests - unit-tests
- base-integration-tests - base-integration-tests
@ -591,28 +592,8 @@ jobs:
- sssd-unit-tests - sssd-unit-tests
- migration-tests - migration-tests
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs:
conclusion: ${{ steps.check.outputs.conclusion }}
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: ./.github/actions/status-check
- 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
with: with:
required: ${{ needs.conditional.outputs.ci }} jobs: ${{ toJSON(needs) }}
conclusion: ${{ needs.check-set-status.outputs.conclusion }}

View file

@ -60,9 +60,6 @@ jobs:
env: env:
CODEQL_ACTION_EXTRA_OPTIONS: '{"database":{"interpret-results":["--max-paths",0]}}' CODEQL_ACTION_EXTRA_OPTIONS: '{"database":{"interpret-results":["--max-paths",0]}}'
- id: check
uses: ./.github/actions/checks-success
themes: themes:
name: CodeQL Themes name: CodeQL Themes
needs: conditional needs: conditional
@ -89,26 +86,15 @@ jobs:
env: env:
CODEQL_ACTION_EXTRA_OPTIONS: '{"database":{"interpret-results":["--max-paths",0]}}' CODEQL_ACTION_EXTRA_OPTIONS: '{"database":{"interpret-results":["--max-paths",0]}}'
- id: check
uses: ./.github/actions/checks-success
check: check:
name: Status Check - CodeQL name: Status Check - CodeQL
if: always() if: always()
needs: [conditional, java, themes] needs:
- java
- themes
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: ./.github/actions/status-check
- name: CodeQL Java
uses: ./.github/actions/checks-job-pass
with: with:
required: ${{ needs.conditional.outputs.java }} jobs: ${{ toJSON(needs) }}
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 }}

View file

@ -98,33 +98,14 @@ jobs:
run: | run: |
./mvnw test -Dtest=ExternalLinksTest -am -pl docs/documentation/tests,docs/documentation/dist -nsu -B -e -Pdocumentation ./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: check:
name: Status Check - Keycloak Documentation name: Status Check - Keycloak Documentation
if: always() if: always()
needs: needs:
- conditional - build
- check-set-status
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: ./.github/actions/status-check
- name: Check status
uses: ./.github/actions/checks-job-pass
with: with:
required: ${{ needs.conditional.outputs.documentation == 'true' }} jobs: ${{ toJSON(needs) }}
conclusion: ${{ needs.check-set-status.outputs.conclusion }}

View file

@ -45,33 +45,14 @@ jobs:
- name: Build Keycloak - name: Build Keycloak
uses: ./.github/actions/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: check:
name: Status Check - Keycloak Guides name: Status Check - Keycloak Guides
if: always() if: always()
needs: needs:
- conditional - build
- check-set-status
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: ./.github/actions/status-check
- name: Check status
uses: ./.github/actions/checks-job-pass
with: with:
required: ${{ needs.conditional.outputs.guides == 'true' && needs.conditional.outputs.ci != 'true' }} jobs: ${{ toJSON(needs) }}
conclusion: ${{ needs.check-set-status.outputs.conclusion }}

View file

@ -265,8 +265,9 @@ jobs:
name: server-log-${{ matrix.container }}-${{ matrix.browser }} name: server-log-${{ matrix.container }}-${{ matrix.browser }}
path: ~/server.log path: ~/server.log
check-set-status: check:
name: Set check conclusion name: Status Check - Keycloak JavaScript CI
if: always()
needs: needs:
- admin-client - admin-client
- keycloak-js - keycloak-js
@ -276,26 +277,8 @@ jobs:
- admin-ui - admin-ui
- admin-ui-e2e - admin-ui-e2e
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs:
conclusion: ${{ steps.check.outputs.conclusion }}
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: ./.github/actions/status-check
- 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
with: with:
required: ${{ needs.conditional.outputs.js-ci }} jobs: ${{ toJSON(needs) }}
conclusion: ${{ needs.check-set-status.outputs.conclusion }}

View file

@ -199,35 +199,16 @@ jobs:
# Wait for the CRs to be ready # Wait for the CRs to be ready
./scripts/check-examples-installed.sh ./scripts/check-examples-installed.sh
check-set-status: check:
name: Set check conclusion name: Status Check - Keycloak Operator CI
if: always()
needs: needs:
- test-local - test-local
- test-remote - test-remote
- test-olm - test-olm
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs:
conclusion: ${{ steps.check.outputs.conclusion }}
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: ./.github/actions/status-check
- 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
with: with:
required: ${{ needs.conditional.outputs.operator }} jobs: ${{ toJSON(needs) }}
conclusion: ${{ needs.check-set-status.outputs.conclusion }}