From 86fbe303d55e618730165081dfe9ebdd150faa46 Mon Sep 17 00:00:00 2001 From: Remo Senekowitsch Date: Mon, 20 Nov 2023 11:14:30 +0100 Subject: [PATCH 1/3] Add workflow to suggest skipping tests --- .../workflows/no-important-files-changed.yml | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .github/workflows/no-important-files-changed.yml diff --git a/.github/workflows/no-important-files-changed.yml b/.github/workflows/no-important-files-changed.yml new file mode 100644 index 000000000..1547652bf --- /dev/null +++ b/.github/workflows/no-important-files-changed.yml @@ -0,0 +1,68 @@ +name: No important files changed + +on: + pull_request: + types: [opened] + +permissions: + pull-requests: write + +jobs: + no_important_files_changed: + name: No important files changed + runs-on: ubuntu-22.04 + steps: + - name: Checkout code + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Check if important files changed + id: check + env: + TARGET_BRANCH: ${{ github.base_ref }} + run: | + set -exo pipefail + + # fetch a ref to the target branch so we can diff against it + git remote set-branches origin '*' + git fetch --depth 1 origin $TARGET_BRANCH + + for changed_file in $(git diff --name-only origin/$TARGET_BRANCH); do + if ! echo "$changed_file" | grep --quiet --extended-regexp 'exercises/(practice|concept)' ; then + continue + fi + slug="$(echo "$changed_file" | sed --regexp-extended 's#exercises/[^/]+/([^/]+)/.*#\1#' )" + path_before_slug="$(echo "$changed_file" | sed --regexp-extended "s#(.*)/$slug/.*#\\1#" )" + path_after_slug="$( echo "$changed_file" | sed --regexp-extended "s#.*/$slug/(.*)#\\1#" )" + + if ! [ -f "$path_before_slug/$slug/.meta/config.json" ]; then + # cannot determine if important files changed without .meta/config.json + continue + fi + + # returns 0 if the filter matches, 1 otherwise + # | contains($path_after_slug) + if jq --exit-status \ + --arg path_after_slug "$path_after_slug" \ + '[.files.test, .files.invalidator, .files.editor] | flatten | index($path_after_slug)' \ + "$path_before_slug/$slug/.meta/config.json" \ + > /dev/null; + then + echo "important_files_changed=true" >> "$GITHUB_OUTPUT" + exit 0 + fi + done + + echo "important_files_changed=false" >> "$GITHUB_OUTPUT" + + - name: Suggest to add [no important files changed] + if: steps.check.outputs.important_files_changed == 'true' + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea + with: + script: | + 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 + }) From 6c1b2461b47959185ae8be6a5bf0138619627a6f Mon Sep 17 00:00:00 2001 From: Remo Senekowitsch Date: Tue, 23 Jan 2024 18:08:35 +0100 Subject: [PATCH 2/3] Only run on PRs targeting main branch --- .github/workflows/no-important-files-changed.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/no-important-files-changed.yml b/.github/workflows/no-important-files-changed.yml index 1547652bf..83ed70d87 100644 --- a/.github/workflows/no-important-files-changed.yml +++ b/.github/workflows/no-important-files-changed.yml @@ -3,6 +3,7 @@ name: No important files changed on: pull_request: types: [opened] + branches: [main] permissions: pull-requests: write @@ -17,16 +18,14 @@ jobs: - name: Check if important files changed id: check - env: - TARGET_BRANCH: ${{ github.base_ref }} run: | set -exo pipefail - # fetch a ref to the target branch so we can diff against it - git remote set-branches origin '*' - git fetch --depth 1 origin $TARGET_BRANCH + # fetch a ref to the main branch so we can diff against it + git remote set-branches origin main + git fetch --depth 1 origin main - for changed_file in $(git diff --name-only origin/$TARGET_BRANCH); do + for changed_file in $(git diff --name-only origin/main); do if ! echo "$changed_file" | grep --quiet --extended-regexp 'exercises/(practice|concept)' ; then continue fi From 3484ea1d3b3fc321f16f3ea1096df2f409471de3 Mon Sep 17 00:00:00 2001 From: Remo Senekowitsch Date: Wed, 24 Jan 2024 14:07:19 +0100 Subject: [PATCH 3/3] better wording Co-authored-by: Jeremy Walker --- .github/workflows/no-important-files-changed.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/no-important-files-changed.yml b/.github/workflows/no-important-files-changed.yml index 83ed70d87..83d6fab52 100644 --- a/.github/workflows/no-important-files-changed.yml +++ b/.github/workflows/no-important-files-changed.yml @@ -58,7 +58,7 @@ jobs: uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea with: script: | - 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```" + const body = "This PR touches files which potentially affect the outcome of the tests of an exercise. This will cause all students' solutions to affected exercises to be re-tested.\n\nIf this PR does **not** affect the result of the test (or, for example, adds an edge case that is not worth rerunning all tests for), **please add the following to the merge-commit message** which will stops student's tests from re-running. Please copy-paste to avoid typos.\n```\n[no important files changed]\n```\n\n For more information, refer to the [documentation](https://exercism.org/docs/building/tracks#h-avoiding-triggering-unnecessary-test-runs). If you are unsure whether to add the message or not, please ping `@exercism/maintainers-admin` in a comment. Thank you!" github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner,