diff --git a/.github/workflows/no-important-files-changed.yml b/.github/workflows/no-important-files-changed.yml index 1a02b7742..4835eff83 100644 --- a/.github/workflows/no-important-files-changed.yml +++ b/.github/workflows/no-important-files-changed.yml @@ -9,16 +9,38 @@ on: permissions: pull-requests: write +# TODO maybe use step output instead ? +# https://stackoverflow.com/questions/60589373/how-to-force-job-to-exit-in-github-actions-step +# https://docs.github.com/en/actions/learn-github-actions/contexts#steps-context + jobs: + check_if_important_files_changed: + name: Check if important files changed + runs-on: ubuntu-22.04 + outputs: + what: ${{ steps.check_if_important_files_changed.outputs.important_files_changed }} + steps: + - name: Check if important files changed + run: | + const body = "This PR touches files which probably affect the outcome of the tests of an exercise. If this is not the case, please add the following to the merge commit message. Copy-paste to avoid typos. This will prevent tests from rerunning unnecessarily. For more information, refer to the [documentation](https://exercism.org/docs/building/tracks#h-avoiding-triggering-unnecessary-test-runs).\n```\n[no important files changed]\n```" + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: body + }) + echo "important_files_changed=$important_files_changed" >> "$GITHUB_OUTPUT" no_important_files_changed: name: No important files changed + needs: check_if_important_files_changed + if: needs.check_if_important_files_changed.outputs.important_files_changed == 'true' runs-on: ubuntu-22.04 steps: - name: Suggest to add [no important files changed] uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea with: script: | - const body = "This PR touches the test files of an exercise. If the changes are only cosmetic, please add the following to the merge commit message. Copy-paste to avoid typos. This will prevent tests from rerunning unnecessarily. For more information, refer to the [documentation](https://exercism.org/docs/building/tracks#h-avoiding-triggering-unnecessary-test-runs).\n```\n[no important files changed]\n```" + const body = "This PR touches files which probably affect the outcome of the tests of an exercise. If this is not the case, please add the following to the merge commit message. Copy-paste to avoid typos. This will prevent tests from rerunning unnecessarily. For more information, refer to the [documentation](https://exercism.org/docs/building/tracks#h-avoiding-triggering-unnecessary-test-runs).\n```\n[no important files changed]\n```" github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, diff --git a/bin/check_if_important_files_changed.sh b/bin/check_if_important_files_changed.sh new file mode 100755 index 000000000..07b773700 --- /dev/null +++ b/bin/check_if_important_files_changed.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -eo pipefail + +cd "$(git rev-parse --show-toplevel)" + +git diff --name-only origin/main + +# TODO +# - detect changed exercises based on the diff +# - check .meta/config.json for each of those exercises +# to determine if important files changed +# - output "true" if so, anything else (e.g. "false") otherwise