Skip to content

Commit

Permalink
CI: Port check-changes action from obs-studio
Browse files Browse the repository at this point in the history
Co-authored-by: PatTheMav <[email protected]>
  • Loading branch information
RytoEX and PatTheMav committed Oct 17, 2024
1 parent 4dafce8 commit f459def
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions .github/actions/check-changes/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Check For Changed Files
description: Checks for changed files compared to specific git reference and glob expression
inputs:
baseRef:
description: Git reference to check against
required: false
ref:
description: Git reference to check with
required: false
default: HEAD
checkGlob:
description: Glob expression to limit check to specific files
required: false
useFallback:
description: Use fallback compare against prior commit
required: false
default: 'true'
diffFilter:
description: git diff-filter string to use
required: false
default: ''
outputs:
hasChangedFiles:
value: ${{ steps.checks.outputs.hasChangedFiles }}
description: True if specified files were changed in comparison to specified git reference
changedFiles:
value: ${{ steps.checks.outputs.changedFiles }}
description: List of changed files
runs:
using: composite
steps:
- name: Check For Changed Files ✅
shell: bash
id: checks
env:
GIT_BASE_REF: ${{ inputs.baseRef }}
GIT_REF: ${{ inputs.ref }}
GITHUB_EVENT_FORCED: ${{ github.event.forced }}
GITHUB_REF_BEFORE: ${{ github.event.before }}
USE_FALLBACK: ${{ inputs.useFallback }}
DIFF_FILTER: ${{ inputs.diffFilter }}
run: |
: Check for Changed Files ✅
if [[ "${RUNNER_DEBUG}" ]]; then set -x; fi
shopt -s extglob
shopt -s dotglob
# 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a "hidden" sha1 hash of
# the "empty tree", retrived via 'git hash-object -t tree /dev/null',
# and used here as a last-resort fallback to always provide a valid
# git ref.
if [[ "${GIT_BASE_REF}" ]]; then
if ! git cat-file -e "${GIT_BASE_REF}" &> /dev/null; then
echo "::warning::Provided base reference ${GIT_BASE_REF} is invalid"
if [[ "${USE_FALLBACK}" == 'true' ]]; then
GIT_BASE_REF='HEAD~1'
fi
fi
else
if ! git cat-file -e ${GITHUB_REF_BEFORE} &> /dev/null; then
GITHUB_REF_BEFORE='4b825dc642cb6eb9a060e54bf8d69288fbee4904'
fi
GIT_BASE_REF='HEAD~1'
case "${GITHUB_EVENT_NAME}" in
pull_request) GIT_BASE_REF="origin/${GITHUB_BASE_REF}" ;;
push) if [[ "${GITHUB_EVENT_FORCED}" != 'true' ]]; then GIT_BASE_REF="${GITHUB_REF_BEFORE}"; fi ;;
*) ;;
esac
fi
changes=($(git diff --name-only --diff-filter="${DIFF_FILTER}" ${GIT_BASE_REF} ${GIT_REF} -- ${{ inputs.checkGlob }}))
if (( ${#changes[@]} )); then
file_string="${changes[*]}"
echo "hasChangedFiles=true" >> $GITHUB_OUTPUT
echo "changedFiles=[\"${file_string// /\",\"}\"]" >> $GITHUB_OUTPUT
else
echo "hasChangedFiles=false" >> $GITHUB_OUTPUT
echo "changedFiles=[]" >> GITHUB_OUTPUT
fi

0 comments on commit f459def

Please sign in to comment.