Fix conditional checking for PR testing (#21947)
* Fix conditional checking for PR testing Closes #21946 * Update .github/actions/conditional/action.yml Co-authored-by: Jon Koops <jonkoops@gmail.com> --------- Co-authored-by: Jon Koops <jonkoops@gmail.com>
This commit is contained in:
parent
bb8ba1af5a
commit
8848dfed74
8 changed files with 35 additions and 25 deletions
9
.github/actions/conditional/action.yml
vendored
9
.github/actions/conditional/action.yml
vendored
|
@ -1,6 +1,11 @@
|
||||||
name: Changed Files
|
name: Changed Files
|
||||||
description: Checks changes against target branch
|
description: Checks changes against target branch
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
token:
|
||||||
|
description: GitHub Token
|
||||||
|
required: true
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
ci:
|
ci:
|
||||||
description: Should "ci.yml" execute
|
description: Should "ci.yml" execute
|
||||||
|
@ -33,4 +38,6 @@ runs:
|
||||||
- id: changes
|
- id: changes
|
||||||
name: Find changes
|
name: Find changes
|
||||||
shell: bash
|
shell: bash
|
||||||
run: .github/actions/conditional/conditional.sh origin ${{ github.base_ref }}
|
run: .github/actions/conditional/conditional.sh ${{ github.repository }} ${{ github.ref }}
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ inputs.token }}
|
||||||
|
|
37
.github/actions/conditional/conditional.sh
vendored
37
.github/actions/conditional/conditional.sh
vendored
|
@ -1,27 +1,22 @@
|
||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
|
|
||||||
REMOTE="$1"
|
REPOSITORY="$1"
|
||||||
BASE_REF="$2"
|
REF="$2"
|
||||||
|
|
||||||
CONDITIONS_FILE=".github/actions/conditional/conditions"
|
CONDITIONS_FILE=".github/actions/conditional/conditions"
|
||||||
|
|
||||||
[ "$BASE_REF" != "" ] && IS_PR=true || IS_PR=false
|
if [[ "$REF" =~ refs/pull/([0-9]+)/merge ]]; then
|
||||||
[ "$GITHUB_OUTPUT" != "" ] && IS_GITHUB_ACTIONS=true || IS_GITHUB_ACTIONS=false
|
PR=$(echo $REF | cut -f 3 -d '/')
|
||||||
|
IS_PR=true
|
||||||
|
else
|
||||||
|
IS_PR=false
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$IS_PR" == true ]; then
|
if [ "$IS_PR" == true ]; then
|
||||||
# Fetch remote if running on GitHub Actions
|
|
||||||
if [ "$IS_GITHUB_ACTIONS" == true ]; then
|
|
||||||
echo "========================================================================================"
|
echo "========================================================================================"
|
||||||
echo "Fetching '$BASE_REF' in '$(git remote get-url "$REMOTE")'"
|
echo "Changes in PR: $PR"
|
||||||
echo "--------------------------------------------------------------------------------"
|
|
||||||
git fetch --depth 1 "$REMOTE" "$BASE_REF"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Get list of changes files
|
|
||||||
echo "========================================================================================"
|
|
||||||
echo "Changes compared to '$BASE_REF' in '$(git remote get-url "$REMOTE")'"
|
|
||||||
echo "----------------------------------------------------------------------------------------"
|
echo "----------------------------------------------------------------------------------------"
|
||||||
CHANGED_FILES=$(git diff "$REMOTE/$BASE_REF" --name-only)
|
|
||||||
|
CHANGED_FILES=$(gh api -X GET --paginate repos/$REPOSITORY/pulls/$PR/files --jq .[].filename)
|
||||||
echo "$CHANGED_FILES"
|
echo "$CHANGED_FILES"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -45,10 +40,6 @@ for C in "${CONDITIONS[@]}"; do
|
||||||
|
|
||||||
# Convert pattern to regex
|
# Convert pattern to regex
|
||||||
REGEX="$PATTERN"
|
REGEX="$PATTERN"
|
||||||
#REGEX=$(echo "$PATTERN" | sed 's|\.|\\.|g' | sed 's|/$|/.*|g' | sed 's|^*|.*|g')
|
|
||||||
|
|
||||||
# Escape '/' characters
|
|
||||||
REGEX=$(echo "$REGEX" | sed 's|\/|\\/|g')
|
|
||||||
|
|
||||||
# Escape '.' to make it match the '.' character only
|
# Escape '.' to make it match the '.' character only
|
||||||
REGEX=$(echo "$REGEX" | sed 's|\.|\\.|g')
|
REGEX=$(echo "$REGEX" | sed 's|\.|\\.|g')
|
||||||
|
@ -60,8 +51,8 @@ for C in "${CONDITIONS[@]}"; do
|
||||||
REGEX=$(echo "$REGEX" | sed 's|/$|/.*|g')
|
REGEX=$(echo "$REGEX" | sed 's|/$|/.*|g')
|
||||||
|
|
||||||
# If no directory separators allow any directory structure before
|
# If no directory separators allow any directory structure before
|
||||||
if ( echo "$REGEX" | grep -v -E '\/' &>/dev/null ); then
|
if ( echo "$REGEX" | grep -v -E '/' &>/dev/null ); then
|
||||||
REGEX="(.*\/)?$REGEX"
|
REGEX="(.*/)?$REGEX"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if changed files matches regex
|
# Check if changed files matches regex
|
||||||
|
@ -98,7 +89,7 @@ do
|
||||||
echo "$JOB=${JOB_CONDITIONS[$JOB]}"
|
echo "$JOB=${JOB_CONDITIONS[$JOB]}"
|
||||||
|
|
||||||
# Set output for GitHub job
|
# Set output for GitHub job
|
||||||
if [ "$IS_GITHUB_ACTIONS" == true ]; then
|
if [ "$GITHUB_OUTPUT" != "" ]; then
|
||||||
echo "$JOB=${JOB_CONDITIONS[$JOB]}" >> $GITHUB_OUTPUT
|
echo "$JOB=${JOB_CONDITIONS[$JOB]}" >> $GITHUB_OUTPUT
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
@ -35,6 +35,8 @@ jobs:
|
||||||
|
|
||||||
- id: conditional
|
- id: conditional
|
||||||
uses: ./.github/actions/conditional
|
uses: ./.github/actions/conditional
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: Build
|
name: Build
|
||||||
|
|
2
.github/workflows/codeql-analysis.yml
vendored
2
.github/workflows/codeql-analysis.yml
vendored
|
@ -31,6 +31,8 @@ jobs:
|
||||||
|
|
||||||
- id: conditional
|
- id: conditional
|
||||||
uses: ./.github/actions/conditional
|
uses: ./.github/actions/conditional
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
java:
|
java:
|
||||||
name: CodeQL Java
|
name: CodeQL Java
|
||||||
|
|
2
.github/workflows/documentation.yml
vendored
2
.github/workflows/documentation.yml
vendored
|
@ -33,6 +33,8 @@ jobs:
|
||||||
|
|
||||||
- id: conditional
|
- id: conditional
|
||||||
uses: ./.github/actions/conditional
|
uses: ./.github/actions/conditional
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: Build
|
name: Build
|
||||||
|
|
2
.github/workflows/guides.yml
vendored
2
.github/workflows/guides.yml
vendored
|
@ -34,6 +34,8 @@ jobs:
|
||||||
|
|
||||||
- id: conditional
|
- id: conditional
|
||||||
uses: ./.github/actions/conditional
|
uses: ./.github/actions/conditional
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: Build
|
name: Build
|
||||||
|
|
2
.github/workflows/js-ci.yml
vendored
2
.github/workflows/js-ci.yml
vendored
|
@ -28,6 +28,8 @@ jobs:
|
||||||
|
|
||||||
- id: conditional
|
- id: conditional
|
||||||
uses: ./.github/actions/conditional
|
uses: ./.github/actions/conditional
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
build-keycloak:
|
build-keycloak:
|
||||||
name: Build Keycloak
|
name: Build Keycloak
|
||||||
|
|
2
.github/workflows/operator-ci.yml
vendored
2
.github/workflows/operator-ci.yml
vendored
|
@ -35,6 +35,8 @@ jobs:
|
||||||
|
|
||||||
- id: conditional
|
- id: conditional
|
||||||
uses: ./.github/actions/conditional
|
uses: ./.github/actions/conditional
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: Build distribution
|
name: Build distribution
|
||||||
|
|
Loading…
Reference in a new issue