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:
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) }}

View file

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

View file

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

View file

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

View file

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

View file

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