Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(validate-wkflow): add file-changes detection to restrict irrelevant job execution #6

Merged
Merged
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
66 changes: 66 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,67 @@ permissions: {}

jobs:

eval-changes:
name: Evaluate changes
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 50 # Must at least retrieve a set of commits to compare changes
# primarily because of any 'Rebase and Merge' PR action in GitHub

- name: Evaluate | Check specific file types for changes
id: changed-files
uses: tj-actions/[email protected]
if: github.event_name == 'push' || github.event_name == 'pull_request'
with:
base_sha: ${{ github.event.push.before || github.event.pull_request.base.sha }}
# action.yml is not considered as src because we can't test it
files_yaml: |
ci:
- .github/workflows/validate.yml
- .github/workflows/ci.yml
docs:
- AUTHORS.rst
- CONTRIBUTING.rst
- LICENSE
- README.md
src:
- src/**
tests:
- tests/**

- name: Evaluate | Detect if any of the combinations of file sets have changed
id: all-changes
if: ${{ steps.changed-files.outcome == 'success' }}
run: |
printf '%s\n' "any_changed=false" >> $GITHUB_OUTPUT
if [ "${{ steps.changed-files.outputs.ci_any_changed }}" == "true" ] || \
[ "${{ steps.changed-files.outputs.docs_any_changed }}" == "true" ] || \
[ "${{ steps.changed-files.outputs.src_any_changed }}" == "true" ] || \
[ "${{ steps.changed-files.outputs.tests_any_changed }}" == "true" ]; then
printf '%s\n' "any_changed=true" >> $GITHUB_OUTPUT
fi

- name: Evaluate | Handle manual trigger (lie that all files changed)
id: manual-trigger
if: github.event_name == 'workflow_dispatch'
run: |
printf '%s\n' "ci_any_changed=true" >> $GITHUB_OUTPUT
printf '%s\n' "docs_any_changed=true" >> $GITHUB_OUTPUT
printf '%s\n' "src_any_changed=true" >> $GITHUB_OUTPUT
printf '%s\n' "tests_any_changed=true" >> $GITHUB_OUTPUT
printf '%s\n' "any_changed=true" >> $GITHUB_OUTPUT

outputs:
any-file-changes: ${{ steps.all-changes.outputs.any_changed || steps.manual-trigger.outputs.any_changed }}
ci-changes: ${{ steps.changed-files.outputs.ci_any_changed || steps.manual-trigger.outputs.ci_any_changed }}
doc-changes: ${{ steps.changed-files.outputs.docs_any_changed || steps.manual-trigger.outputs.docs_any_changed }}
src-changes: ${{ steps.changed-files.outputs.src_any_changed || steps.manual-trigger.outputs.src_any_changed }}
test-changes: ${{ steps.changed-files.outputs.tests_any_changed || steps.manual-trigger.outputs.tests_any_changed }}


commitlint:
runs-on: ubuntu-latest

Expand All @@ -31,8 +92,13 @@ jobs:
validate-action:
name: Validate Action Build & Execution
runs-on: ubuntu-latest
if: needs.eval-changes.outputs.src-changes == 'true' || needs.eval-changes.outputs.test-changes == 'true' || needs.eval-changes.outputs.ci-changes == 'true'
needs:
- eval-changes

env:
TEST_CONTAINER_TAG: psr-publish-action:latest

steps:
- name: Setup | Checkout Repository
uses: actions/checkout@v4
Expand Down