Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/actions/conditional/action.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 changes: 15 additions & 24 deletions .github/actions/conditional/conditional.sh
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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')
Expand All @@ -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
Expand Down Expand Up @@ -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 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:

- id: conditional
uses: ./.github/actions/conditional
with:
token: ${{ secrets.GITHUB_TOKEN }}

build:
name: Build
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:

- id: conditional
uses: ./.github/actions/conditional
with:
token: ${{ secrets.GITHUB_TOKEN }}

java:
name: CodeQL Java
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:

- id: conditional
uses: ./.github/actions/conditional
with:
token: ${{ secrets.GITHUB_TOKEN }}

build:
name: Build
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/guides.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:

- id: conditional
uses: ./.github/actions/conditional
with:
token: ${{ secrets.GITHUB_TOKEN }}

build:
name: Build
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/js-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:

- id: conditional
uses: ./.github/actions/conditional
with:
token: ${{ secrets.GITHUB_TOKEN }}

build-keycloak:
name: Build Keycloak
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/operator-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:

- id: conditional
uses: ./.github/actions/conditional
with:
token: ${{ secrets.GITHUB_TOKEN }}

build:
name: Build distribution
Expand Down