Conditional workflows (#16666)
* Conditional workflows Closes #16665 * Added .editorconfig to make sure there's a newline in conditions file * Fix * Tweak * Tweaks
This commit is contained in:
parent
6736f31952
commit
d2ef774788
7 changed files with 145 additions and 73 deletions
50
.github/actions/changed-files/action.yml
vendored
50
.github/actions/changed-files/action.yml
vendored
|
@ -1,50 +0,0 @@
|
||||||
name: Changed Files
|
|
||||||
description: Checks changes against target branch
|
|
||||||
|
|
||||||
outputs:
|
|
||||||
java:
|
|
||||||
description: Changes to Java files
|
|
||||||
value: ${{ steps.changes.outputs.java }}
|
|
||||||
themes:
|
|
||||||
description: Changes to themes
|
|
||||||
value: ${{ steps.changes.outputs.themes }}
|
|
||||||
js-adapter:
|
|
||||||
description: Changes to JavaScript adapter
|
|
||||||
value: ${{ steps.changes.outputs.js-adapter }}
|
|
||||||
|
|
||||||
runs:
|
|
||||||
using: composite
|
|
||||||
steps:
|
|
||||||
- id: changes
|
|
||||||
name: Find changes
|
|
||||||
shell: bash
|
|
||||||
# language=bash
|
|
||||||
run: |
|
|
||||||
BASE_REF=${{ github.base_ref }}
|
|
||||||
|
|
||||||
changed () {
|
|
||||||
git diff --name-only origin/${{ github.base_ref }} | grep -E "$1" &>/dev/null && echo true || echo false
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ "$BASE_REF" != "" ]; then
|
|
||||||
echo "Checking changes against orgin/$BASE_REF"
|
|
||||||
git fetch origin
|
|
||||||
|
|
||||||
JAVA=`changed '^.*/.*.java$'`
|
|
||||||
THEMES=`changed '^themes/src/main/.*$'`
|
|
||||||
JS_ADAPTER=`changed '^adapters/oidc/js/.*$'`
|
|
||||||
else
|
|
||||||
echo "Not a pull request, marking everything as changed"
|
|
||||||
|
|
||||||
JAVA=true
|
|
||||||
THEMES=true
|
|
||||||
JS_ADAPTER=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Java changed: $JAVA"
|
|
||||||
echo "Themes changed: $THEMES"
|
|
||||||
echo "JS adapter changed: $JS_ADAPTER"
|
|
||||||
|
|
||||||
echo "java=$JAVA" >> $GITHUB_OUTPUT
|
|
||||||
echo "themes=$THEMES" >> $GITHUB_OUTPUT
|
|
||||||
echo "js-adapter=$JS_ADAPTER" >> $GITHUB_OUTPUT
|
|
27
.github/actions/conditional/action.yml
vendored
Normal file
27
.github/actions/conditional/action.yml
vendored
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
name: Changed Files
|
||||||
|
description: Checks changes against target branch
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
ci:
|
||||||
|
description: Should "ci.yml" execute
|
||||||
|
value: ${{ steps.changes.outputs.ci }}
|
||||||
|
codeql-java:
|
||||||
|
description: Should "codeql-analysis.yml / java" execute
|
||||||
|
value: ${{ steps.changes.outputs.codeql-java }}
|
||||||
|
codeql-themes:
|
||||||
|
description: Should "codeql-analysis.yml / themes" execute
|
||||||
|
value: ${{ steps.changes.outputs.codeql-themes }}
|
||||||
|
codeql-js_adapter:
|
||||||
|
description: Should "codeql-analysis.yml / js-adapter" execute
|
||||||
|
value: ${{ steps.changes.outputs.codeql-js_adapter }}
|
||||||
|
operator:
|
||||||
|
description: Should "operator-ci.yml" execute
|
||||||
|
value: ${{ steps.changes.outputs.operator }}
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: composite
|
||||||
|
steps:
|
||||||
|
- id: changes
|
||||||
|
name: Find changes
|
||||||
|
shell: bash
|
||||||
|
run: .github/actions/conditional/conditional.sh origin ${{ github.base_ref }}
|
49
.github/actions/conditional/conditional.sh
vendored
Executable file
49
.github/actions/conditional/conditional.sh
vendored
Executable file
|
@ -0,0 +1,49 @@
|
||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
REMOTE=$1
|
||||||
|
BASE_REF=$2
|
||||||
|
|
||||||
|
if [ "$BASE_REF" != "" ]; then
|
||||||
|
if [ "$GITHUB_OUTPUT" != "" ]; then
|
||||||
|
echo "--------------------------------------------------------------------------------"
|
||||||
|
echo "Fetching '$BASE_REF' in '`git remote get-url $REMOTE`'"
|
||||||
|
echo "--------------------------------------------------------------------------------"
|
||||||
|
git fetch --depth 1 $REMOTE $BASE_REF
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "--------------------------------------------------------------------------------"
|
||||||
|
echo "Changes compared to '$BASE_REF' in '`git remote get-url $REMOTE`'"
|
||||||
|
echo "--------------------------------------------------------------------------------"
|
||||||
|
git diff $REMOTE/$BASE_REF --name-only
|
||||||
|
else
|
||||||
|
echo "--------------------------------------------------------------------------------"
|
||||||
|
echo "Not a pull request, marking everything as changed"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "--------------------------------------------------------------------------------"
|
||||||
|
echo "Run conditions"
|
||||||
|
echo "--------------------------------------------------------------------------------"
|
||||||
|
|
||||||
|
cat .github/actions/conditional/conditions | grep '=' | grep -v '#' | while read c; do
|
||||||
|
KEY=`echo $c | cut -d '=' -f 1`
|
||||||
|
PATTERN=`echo $c | cut -d '=' -f 2`
|
||||||
|
|
||||||
|
if [ "$BASE_REF" != "" ]; then
|
||||||
|
DIFF=`echo $PATTERN | xargs git diff $REMOTE/$BASE_REF --name-only`
|
||||||
|
if [ "$DIFF" != "" ]; then
|
||||||
|
CHANGED=true
|
||||||
|
else
|
||||||
|
CHANGED=false
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
CHANGED=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$KEY=$CHANGED"
|
||||||
|
|
||||||
|
if [ "$GITHUB_OUTPUT" != "" ]; then
|
||||||
|
echo "$KEY=$CHANGED" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "--------------------------------------------------------------------------------"
|
12
.github/actions/conditional/conditions
vendored
Normal file
12
.github/actions/conditional/conditions
vendored
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
# File patterns used to decide what workflows/jobs to execute for a given PR
|
||||||
|
#
|
||||||
|
# To test a pattern run '.github/actions/conditional/conditional.sh <remote name> <branch>'
|
||||||
|
# Alternatively, run 'git diff <remote name>/<branch> <pattern>' (from the root directory)
|
||||||
|
|
||||||
|
ci=*/pom.xml */src/main/ */src/test/
|
||||||
|
|
||||||
|
operator=*/pom.xml */src/main/ */src/test/
|
||||||
|
|
||||||
|
codeql-java=*.java
|
||||||
|
codeql-themes=themes/
|
||||||
|
codeql-js_adapter=adapters/oidc/js/
|
23
.github/workflows/ci.yml
vendored
23
.github/workflows/ci.yml
vendored
|
@ -25,10 +25,24 @@ defaults:
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
|
||||||
name: Build
|
conditional:
|
||||||
|
name: Check conditional workflows and jobs
|
||||||
if: github.event_name != 'schedule' || github.repository == 'keycloak/keycloak'
|
if: github.event_name != 'schedule' || github.repository == 'keycloak/keycloak'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
ci: ${{ steps.conditional.outputs.ci }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- id: conditional
|
||||||
|
uses: ./.github/actions/conditional
|
||||||
|
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
if: needs.conditional.outputs.ci == 'true'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: conditional
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
@ -501,7 +515,9 @@ jobs:
|
||||||
check:
|
check:
|
||||||
name: Status Check - Keycloak CI
|
name: Status Check - Keycloak CI
|
||||||
if: always() && ( github.event_name != 'schedule' || github.repository == 'keycloak/keycloak' )
|
if: always() && ( github.event_name != 'schedule' || github.repository == 'keycloak/keycloak' )
|
||||||
needs: [check-set-status]
|
needs:
|
||||||
|
- conditional
|
||||||
|
- check-set-status
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
@ -510,4 +526,5 @@ jobs:
|
||||||
- name: Check status
|
- name: Check status
|
||||||
uses: ./.github/actions/checks-job-pass
|
uses: ./.github/actions/checks-job-pass
|
||||||
with:
|
with:
|
||||||
|
required: ${{ needs.conditional.outputs.ci }}
|
||||||
conclusion: ${{ needs.check-set-status.outputs.conclusion }}
|
conclusion: ${{ needs.check-set-status.outputs.conclusion }}
|
||||||
|
|
34
.github/workflows/codeql-analysis.yml
vendored
34
.github/workflows/codeql-analysis.yml
vendored
|
@ -21,25 +21,25 @@ defaults:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
changes:
|
conditional:
|
||||||
name: Check changes
|
name: Check conditional workflows and jobs
|
||||||
if: github.event_name != 'schedule' || github.repository == 'keycloak/keycloak'
|
if: github.event_name != 'schedule' || github.repository == 'keycloak/keycloak'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
java: ${{ steps.changes.outputs.java }}
|
java: ${{ steps.conditional.outputs.codeql-java }}
|
||||||
themes: ${{ steps.changes.outputs.themes }}
|
themes: ${{ steps.conditional.outputs.codeql-themes }}
|
||||||
js-adapter: ${{ steps.changes.outputs.js-adapter }}
|
js-adapter: ${{ steps.conditional.outputs.codeql-js_adapter }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- id: changes
|
- id: conditional
|
||||||
uses: ./.github/actions/changed-files
|
uses: ./.github/actions/conditional
|
||||||
|
|
||||||
java:
|
java:
|
||||||
name: CodeQL Java
|
name: CodeQL Java
|
||||||
needs: changes
|
needs: conditional
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: needs.changes.outputs.java == 'true'
|
if: needs.conditional.outputs.java == 'true'
|
||||||
outputs:
|
outputs:
|
||||||
conclusion: ${{ steps.check.outputs.conclusion }}
|
conclusion: ${{ steps.check.outputs.conclusion }}
|
||||||
|
|
||||||
|
@ -66,9 +66,9 @@ jobs:
|
||||||
|
|
||||||
js-adapter:
|
js-adapter:
|
||||||
name: CodeQL JavaScript Adapter
|
name: CodeQL JavaScript Adapter
|
||||||
needs: changes
|
needs: conditional
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: needs.changes.outputs.js-adapter == 'true'
|
if: needs.conditional.outputs.js-adapter == 'true'
|
||||||
outputs:
|
outputs:
|
||||||
conclusion: ${{ steps.check.outputs.conclusion }}
|
conclusion: ${{ steps.check.outputs.conclusion }}
|
||||||
|
|
||||||
|
@ -95,9 +95,9 @@ jobs:
|
||||||
|
|
||||||
themes:
|
themes:
|
||||||
name: CodeQL Themes
|
name: CodeQL Themes
|
||||||
needs: changes
|
needs: conditional
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: needs.changes.outputs.themes == 'true'
|
if: needs.conditional.outputs.themes == 'true'
|
||||||
outputs:
|
outputs:
|
||||||
conclusion: ${{ steps.check.outputs.conclusion }}
|
conclusion: ${{ steps.check.outputs.conclusion }}
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ jobs:
|
||||||
check:
|
check:
|
||||||
name: Status Check - CodeQL
|
name: Status Check - CodeQL
|
||||||
if: always() && ( github.event_name != 'schedule' || github.repository == 'keycloak/keycloak' )
|
if: always() && ( github.event_name != 'schedule' || github.repository == 'keycloak/keycloak' )
|
||||||
needs: [changes, java, js-adapter, themes]
|
needs: [conditional, java, js-adapter, themes]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
@ -134,17 +134,17 @@ jobs:
|
||||||
- name: CodeQL Java
|
- name: CodeQL Java
|
||||||
uses: ./.github/actions/checks-job-pass
|
uses: ./.github/actions/checks-job-pass
|
||||||
with:
|
with:
|
||||||
required: ${{ needs.changes.outputs.java }}
|
required: ${{ needs.conditional.outputs.java }}
|
||||||
conclusion: ${{ needs.java.outputs.conclusion }}
|
conclusion: ${{ needs.java.outputs.conclusion }}
|
||||||
|
|
||||||
- name: CodeQL JavaScript Adapter
|
- name: CodeQL JavaScript Adapter
|
||||||
uses: ./.github/actions/checks-job-pass
|
uses: ./.github/actions/checks-job-pass
|
||||||
with:
|
with:
|
||||||
required: ${{ needs.changes.outputs.js-adapter }}
|
required: ${{ needs.conditional.outputs.js-adapter }}
|
||||||
conclusion: ${{ needs.js-adapter.outputs.conclusion }}
|
conclusion: ${{ needs.js-adapter.outputs.conclusion }}
|
||||||
|
|
||||||
- name: CodeQL Themes
|
- name: CodeQL Themes
|
||||||
uses: ./.github/actions/checks-job-pass
|
uses: ./.github/actions/checks-job-pass
|
||||||
with:
|
with:
|
||||||
required: ${{ needs.changes.outputs.themes }}
|
required: ${{ needs.conditional.outputs.themes }}
|
||||||
conclusion: ${{ needs.themes.outputs.conclusion }}
|
conclusion: ${{ needs.themes.outputs.conclusion }}
|
||||||
|
|
23
.github/workflows/operator-ci.yml
vendored
23
.github/workflows/operator-ci.yml
vendored
|
@ -26,10 +26,24 @@ concurrency:
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
|
||||||
name: Build distribution
|
conditional:
|
||||||
|
name: Check conditional workflows and jobs
|
||||||
if: github.event_name != 'schedule' || github.repository == 'keycloak/keycloak'
|
if: github.event_name != 'schedule' || github.repository == 'keycloak/keycloak'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
operator: ${{ steps.conditional.outputs.operator }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- id: conditional
|
||||||
|
uses: ./.github/actions/conditional
|
||||||
|
|
||||||
|
build:
|
||||||
|
name: Build distribution
|
||||||
|
if: needs.conditional.outputs.operator == 'true'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: conditional
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
@ -213,7 +227,9 @@ jobs:
|
||||||
check:
|
check:
|
||||||
name: Status Check - Keycloak Operator CI
|
name: Status Check - Keycloak Operator CI
|
||||||
if: always() && ( github.event_name != 'schedule' || github.repository == 'keycloak/keycloak' )
|
if: always() && ( github.event_name != 'schedule' || github.repository == 'keycloak/keycloak' )
|
||||||
needs: [check-set-status]
|
needs:
|
||||||
|
- conditional
|
||||||
|
- check-set-status
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
@ -222,4 +238,5 @@ jobs:
|
||||||
- name: Check status
|
- name: Check status
|
||||||
uses: ./.github/actions/checks-job-pass
|
uses: ./.github/actions/checks-job-pass
|
||||||
with:
|
with:
|
||||||
|
required: ${{ needs.conditional.outputs.operator }}
|
||||||
conclusion: ${{ needs.check-set-status.outputs.conclusion }}
|
conclusion: ${{ needs.check-set-status.outputs.conclusion }}
|
||||||
|
|
Loading…
Reference in a new issue