From 7bef33dd3c8fa14ea6f270f3d190beb7b8f59372 Mon Sep 17 00:00:00 2001 From: Scott Dickerson Date: Thu, 12 Sep 2024 13:56:11 -0400 Subject: [PATCH] :seedling: Skip PR CI actions for docs/hacks changes (#2084) When a PR only contains changes to root level markdown, or anything under `docs/` or `hack/`, there is no need to run the CI github actions. To satisfy branch protection rules that may exist that require the "unit-test" job to run, the `ci-repo.yml` action looks up details about a PR and will skip the unit test if it detects that the only changes made in the PR are docs or hacks. The ignores do not apply to pushes to main, pushes to release, or workflow calls. Signed-off-by: Scott J Dickerson Signed-off-by: Shevijacobson --- .github/workflows/ci-global.yml | 4 ++ .github/workflows/ci-image-build.yml | 4 ++ .github/workflows/ci-repo.yml | 59 ++++++++++++++++++++++++++-- 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-global.yml b/.github/workflows/ci-global.yml index f6d8d6d618..3497b0acc9 100644 --- a/.github/workflows/ci-global.yml +++ b/.github/workflows/ci-global.yml @@ -6,6 +6,10 @@ on: - "main" pull_request: + paths-ignore: + - "docs/**" + - "hack/**" + - "*.md" branches: - "main" diff --git a/.github/workflows/ci-image-build.yml b/.github/workflows/ci-image-build.yml index 6199750d93..6a165b27df 100644 --- a/.github/workflows/ci-image-build.yml +++ b/.github/workflows/ci-image-build.yml @@ -2,6 +2,10 @@ name: CI (test image build for a PR with build related changes) on: pull_request: + paths-ignore: + - "docs/**" + - "hack/**" + - "*.md" branches: - "main" - "release-*" diff --git a/.github/workflows/ci-repo.yml b/.github/workflows/ci-repo.yml index 9920661914..3089ef5174 100644 --- a/.github/workflows/ci-repo.yml +++ b/.github/workflows/ci-repo.yml @@ -20,10 +20,12 @@ concurrency: cancel-in-progress: true jobs: - unit-test-lookup-image: + unit-test-lookup: runs-on: ubuntu-latest outputs: builder-image: ${{ steps.grepBuilder.outputs.builder }} + should-test: ${{ steps.check-changes.outputs.should-test }} + steps: - uses: actions/checkout@v4 @@ -31,15 +33,64 @@ jobs: id: grepBuilder run: | builder=$(grep 'as builder' Dockerfile | sed -e 's/^FROM \(.*\) as builder$/\1/') - echo "Builder image: \`$builder\`" >> "$GITHUB_STEP_SUMMARY" echo "builder=$builder" >> "$GITHUB_OUTPUT" + - name: Did docs and hacks change? + id: docs-and-hacks + uses: tj-actions/changed-files@v44 + with: + files: | + docs/** + hack/** + *.md + + - name: Check if only docs and hacks changes have been made in a PR + id: check-changes + env: + IS_PR: ${{ !!github.event.pull_request }} + ONLY_DOCS: ${{ steps.docs-and-hacks.outputs.only_modified }} + run: | + SHOULD_TEST=$( + if [[ $IS_PR == true ]] && [[ $ONLY_DOCS == true ]]; then + echo "false" + else + echo "true" + fi + ) + + echo "is-pr=$IS_PR" >> "$GITHUB_OUTPUT" + echo "changes_only_docs=${ONLY_DOCS:-false}" >> "$GITHUB_OUTPUT" + echo "should-test=$SHOULD_TEST" >> "$GITHUB_OUTPUT" + + - name: Summarize findings + env: + ONLY_DOCS: ${{ steps.docs-and-hacks.outputs.only_modified }} + MODIFIED_FILES: ${{ steps.docs-and-hacks.outputs.all_modified_files }} + run: | + cat >> "$GITHUB_STEP_SUMMARY" <> "$GITHUB_STEP_SUMMARY" + for file in ${MODIFIED_FILES}; do + echo " - \`$file\`" >> "$GITHUB_STEP_SUMMARY" + done + fi + unit-test: runs-on: ubuntu-latest - needs: unit-test-lookup-image + needs: unit-test-lookup + if: ${{ needs.unit-test-lookup.outputs.should-test == 'true' }} # Use the same container as the Dockerfile's "FROM * as builder" - container: ${{ needs.unit-test-lookup-image.outputs.builder-image }} + container: ${{ needs.unit-test-lookup.outputs.builder-image }} steps: - uses: actions/checkout@v4