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
|
||||
description: Checks changes against target branch
|
||||
|
||||
inputs:
|
||||
token:
|
||||
description: GitHub Token
|
||||
required: true
|
||||
|
||||
outputs:
|
||||
ci:
|
||||
description: Should "ci.yml" execute
|
||||
|
@ -33,4 +38,6 @@ runs:
|
|||
- id: changes
|
||||
name: Find changes
|
||||
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 }}
|
||||
|
|
39
.github/actions/conditional/conditional.sh
vendored
39
.github/actions/conditional/conditional.sh
vendored
|
@ -1,27 +1,22 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
REMOTE="$1"
|
||||
BASE_REF="$2"
|
||||
|
||||
REPOSITORY="$1"
|
||||
REF="$2"
|
||||
CONDITIONS_FILE=".github/actions/conditional/conditions"
|
||||
|
||||
[ "$BASE_REF" != "" ] && IS_PR=true || IS_PR=false
|
||||
[ "$GITHUB_OUTPUT" != "" ] && IS_GITHUB_ACTIONS=true || IS_GITHUB_ACTIONS=false
|
||||
if [[ "$REF" =~ refs/pull/([0-9]+)/merge ]]; then
|
||||
PR=$(echo $REF | cut -f 3 -d '/')
|
||||
IS_PR=true
|
||||
else
|
||||
IS_PR=false
|
||||
fi
|
||||
|
||||
if [ "$IS_PR" == true ]; then
|
||||
# Fetch remote if running on GitHub Actions
|
||||
if [ "$IS_GITHUB_ACTIONS" == true ]; then
|
||||
echo "========================================================================================"
|
||||
echo "Fetching '$BASE_REF' in '$(git remote get-url "$REMOTE")'"
|
||||
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 "Changes in PR: $PR"
|
||||
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"
|
||||
fi
|
||||
|
||||
|
@ -45,10 +40,6 @@ for C in "${CONDITIONS[@]}"; do
|
|||
|
||||
# Convert pattern to regex
|
||||
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
|
||||
REGEX=$(echo "$REGEX" | sed 's|\.|\\.|g')
|
||||
|
@ -60,8 +51,8 @@ for C in "${CONDITIONS[@]}"; do
|
|||
REGEX=$(echo "$REGEX" | sed 's|/$|/.*|g')
|
||||
|
||||
# If no directory separators allow any directory structure before
|
||||
if ( echo "$REGEX" | grep -v -E '\/' &>/dev/null ); then
|
||||
REGEX="(.*\/)?$REGEX"
|
||||
if ( echo "$REGEX" | grep -v -E '/' &>/dev/null ); then
|
||||
REGEX="(.*/)?$REGEX"
|
||||
fi
|
||||
|
||||
# Check if changed files matches regex
|
||||
|
@ -98,7 +89,7 @@ do
|
|||
echo "$JOB=${JOB_CONDITIONS[$JOB]}"
|
||||
|
||||
# Set output for GitHub job
|
||||
if [ "$IS_GITHUB_ACTIONS" == true ]; then
|
||||
echo "$JOB=${JOB_CONDITIONS[$JOB]}" >> $GITHUB_OUTPUT
|
||||
if [ "$GITHUB_OUTPUT" != "" ]; then
|
||||
echo "$JOB=${JOB_CONDITIONS[$JOB]}" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
done
|
||||
|
|
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
@ -35,6 +35,8 @@ jobs:
|
|||
|
||||
- id: conditional
|
||||
uses: ./.github/actions/conditional
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
build:
|
||||
name: Build
|
||||
|
|
2
.github/workflows/codeql-analysis.yml
vendored
2
.github/workflows/codeql-analysis.yml
vendored
|
@ -31,6 +31,8 @@ jobs:
|
|||
|
||||
- id: conditional
|
||||
uses: ./.github/actions/conditional
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
java:
|
||||
name: CodeQL Java
|
||||
|
|
2
.github/workflows/documentation.yml
vendored
2
.github/workflows/documentation.yml
vendored
|
@ -33,6 +33,8 @@ jobs:
|
|||
|
||||
- id: conditional
|
||||
uses: ./.github/actions/conditional
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
build:
|
||||
name: Build
|
||||
|
|
2
.github/workflows/guides.yml
vendored
2
.github/workflows/guides.yml
vendored
|
@ -34,6 +34,8 @@ jobs:
|
|||
|
||||
- id: conditional
|
||||
uses: ./.github/actions/conditional
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
build:
|
||||
name: Build
|
||||
|
|
2
.github/workflows/js-ci.yml
vendored
2
.github/workflows/js-ci.yml
vendored
|
@ -28,6 +28,8 @@ jobs:
|
|||
|
||||
- id: conditional
|
||||
uses: ./.github/actions/conditional
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
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
|
||||
uses: ./.github/actions/conditional
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
build:
|
||||
name: Build distribution
|
||||
|
|
Loading…
Reference in a new issue