mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-09-28 02:06:12 -04:00
CI: Update formatting actions to use git diff filter before formatting
Using git's diff-filter when checking for changed files allows the actions to ignore any deleted files. Combined with explicitly passing glob expressions for source files to git directly allows the command to yield a list of changed files compatible with a given formatter directly.
This commit is contained in:
@@ -3,7 +3,7 @@ description: Checks for changed files compared to specific git reference and glo
|
||||
inputs:
|
||||
baseRef:
|
||||
description: Git reference to check against
|
||||
required: true
|
||||
required: false
|
||||
ref:
|
||||
description: Git reference to check with
|
||||
required: false
|
||||
@@ -15,12 +15,16 @@ inputs:
|
||||
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: ${{ toJSON(steps.checks.outputs.changedFiles) }}
|
||||
value: ${{ steps.checks.outputs.changedFiles }}
|
||||
description: List of changed files
|
||||
runs:
|
||||
using: composite
|
||||
@@ -31,26 +35,42 @@ runs:
|
||||
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
|
||||
|
||||
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'
|
||||
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 ${GIT_BASE_REF} ${GIT_REF} -- ${{ inputs.checkGlob }}))
|
||||
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
|
||||
echo "changedFiles=[\"${file_string// /\",\"}\"]" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "hasChangedFiles=false" >> $GITHUB_OUTPUT
|
||||
echo "changedFiles=[]" >> GITHUB_OUTPUT
|
||||
|
||||
Reference in New Issue
Block a user