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

Add workflow to suggest skipping tests #1790

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
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
68 changes: 68 additions & 0 deletions .github/workflows/no-important-files-changed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: No important files changed

on:
pull_request:
types: [opened]
ErikSchierboom marked this conversation as resolved.
Show resolved Hide resolved

permissions:
pull-requests: write
Comment on lines +8 to +9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that you're being explicit about the permissions!


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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should check to see if the target branch is main instead? The reason for that is that only when something is merged to main will be actually be doing anything on the website side of things. That way this workflow wouldn't run when someone PR's something to a branch (which we don't care about from the website side of things).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 👍


# 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```"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to tweak the wording a bit, but that's for later.

senekor marked this conversation as resolved.
Show resolved Hide resolved
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
})