From db9e8934505afa4df7c9b1b10b0e2c358da6fd54 Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Tue, 17 Nov 2020 15:45:21 +0000 Subject: [PATCH 1/3] replace TRAVIS_PULL_REQUEST with GITHUB_EVENT_NAME When moving off of Travis in https://github.com/exercism/rust/pull/975, there were some instances of TRAVIS_PULL_REQUEST left over as a transitionary strategy. Now we have been hurt by leaving TRAVIS_PULL_REQUEST in: In https://github.com/exercism/rust/pull/1006 a new GitHub Actions job was added that forgot to set TRAVIS_PULL_REQUEST and caused incorrect behaviour. So let's remove TRAVIS_PULL_REQUEST and instead change it to GITHUB_EVENT_NAME. Documentation: https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables --- .github/workflows/tests.yml | 15 --------------- _test/check-configlet-fmt.sh | 19 +++++++------------ _test/check-exercise-crate.sh | 23 ++++++++++++----------- _test/check-exercises.sh | 2 +- _test/ensure-stubs-compile.sh | 2 +- 5 files changed, 21 insertions(+), 40 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fd99bf274..f22ba68f0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -47,12 +47,6 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - # Sets TRAVIS_PULL_REQUEST to false if this is not a pull request. - - name: set TRAVIS_PULL_REQUEST - env: - PR_NUMBER: ${{ github.event.pull_request.number }} - run: echo "TRAVIS_PULL_REQUEST=${PR_NUMBER:-false}" >> $GITHUB_ENV - - name: Fetch configlet run: ./bin/fetch-configlet @@ -93,16 +87,7 @@ jobs: toolchain: ${{ matrix.rust }} default: true - # Sets TRAVIS_PULL_REQUEST to false if this is not a pull request. - - name: set TRAVIS_PULL_REQUEST - env: - PR_NUMBER: ${{ github.event.pull_request.number }} - run: echo "TRAVIS_PULL_REQUEST=${PR_NUMBER:-false}" >> $GITHUB_ENV - # run scripts as steps - # TODO: the TRAVIS_PULL_REQUEST variable is a holdover from before the - # migration to GitHub Actions. The scripts that use it do so in order to - # run only on changed files. - name: Check exercises env: DENYWARNINGS: ${{ matrix.deny_warnings }} diff --git a/_test/check-configlet-fmt.sh b/_test/check-configlet-fmt.sh index 54a5b4d7e..0013a644b 100755 --- a/_test/check-configlet-fmt.sh +++ b/_test/check-configlet-fmt.sh @@ -6,20 +6,15 @@ # Check if config.json or maintainers.json were modified check_pattern="config.json\|config/maintainers.json" -if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then +if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then # Check the changes on the current branch against master branch - git diff --name-only remotes/origin/master | grep "$check_pattern" -else - # Check the commits on the master branch made during the week - # This is because Travis cron is set to test the master branch weekly. - git diff --name-only "@{7 days ago}" | grep "$check_pattern" -fi - -if [ $? != 0 ]; then - echo "config.json or maintainers.json were not changed - configlet fmt is aborted." - - exit 0 + if ! git diff --name-only remotes/origin/master | grep -q "$check_pattern"; then + echo "config.json or maintainers.json were not changed - configlet fmt is aborted." + exit 0 + fi fi +# If it's not a pull request, just always run it. +# This script is cheap anyway. repo=$(cd "$(dirname "$0")/.." && pwd) configlet="${repo}/bin/configlet" diff --git a/_test/check-exercise-crate.sh b/_test/check-exercise-crate.sh index 65e55fa11..d3210d73c 100755 --- a/_test/check-exercise-crate.sh +++ b/_test/check-exercise-crate.sh @@ -4,20 +4,21 @@ EXERCISE_CRATE_PATH="util/exercise" -if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then +if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then # Check the changes on the current branch against master branch - git diff --name-only remotes/origin/master | grep "$EXERCISE_CRATE_PATH" -else - # Check the commits on the master branch made during the week - # This is because Travis cron is set to test the master branch weekly. - git diff --name-only "@{7 days ago}" | grep "$EXERCISE_CRATE_PATH" + if ! git diff --name-only remotes/origin/master | grep -q "$EXERCISE_CRATE_PATH"; then + echo "exercise crate was not modified. The script is aborted." + exit 0 + fi fi +# If it's not a pull request, just always run it. +# Two scenarios: +# 1. It's being run locally, +# in which case we assume the person running it really does want to run it. +# 2. It's being run on CI for master, +# in which case we should check regardless of changes to exercise crate, +# in case there's a new toolchain release, etc. -if [ $? != 0 ]; then - echo "exercise crate was not modified. The script is aborted." - - exit 0 -fi TRACK_ROOT="$(git rev-parse --show-toplevel)" diff --git a/_test/check-exercises.sh b/_test/check-exercises.sh index 6aa45da79..7dd0c3121 100755 --- a/_test/check-exercises.sh +++ b/_test/check-exercises.sh @@ -28,7 +28,7 @@ fi repo=$(cd "$(dirname "$0")/.." && pwd) -if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then +if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then files="$(git diff --diff-filter=d --name-only remotes/origin/master | grep "exercises/" | cut -d '/' -f -2 | sort -u | awk -v repo=$repo '{print repo"/"$1}')" else files=$repo/exercises/* diff --git a/_test/ensure-stubs-compile.sh b/_test/ensure-stubs-compile.sh index 8880dbf90..41bde709f 100755 --- a/_test/ensure-stubs-compile.sh +++ b/_test/ensure-stubs-compile.sh @@ -2,7 +2,7 @@ repo=$(cd "$(dirname "$0")/.." && pwd) -if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then +if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then changed_exercises="$(git diff --diff-filter=d --name-only remotes/origin/master | grep "exercises/" | cut -d '/' -f -2 | sort -u | awk -v repo=$repo '{print repo"/"$1}')" else changed_exercises=$repo/exercises/* From 58af7b0885a49682848eda2c5ddf9b22169d0a33 Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Tue, 17 Nov 2020 16:10:16 +0000 Subject: [PATCH 2/3] proof commit: violate configlet fmt --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index 0f02de0c2..5c871f0b5 100644 --- a/config.json +++ b/config.json @@ -9,7 +9,7 @@ ], "exercises": [ { - "slug": "hello-world", + "slug": "hello-world", "uuid": "13ec1ebe-d71b-436f-ab12-25305e814171", "core": true, "auto_approve": true, From e65aeb8638338433be0d16a5914f443088e9a5ef Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Tue, 17 Nov 2020 16:11:55 +0000 Subject: [PATCH 3/3] Revert "proof commit: violate configlet fmt" This reverts commit 58af7b0885a49682848eda2c5ddf9b22169d0a33. --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index 5c871f0b5..0f02de0c2 100644 --- a/config.json +++ b/config.json @@ -9,7 +9,7 @@ ], "exercises": [ { - "slug": "hello-world", + "slug": "hello-world", "uuid": "13ec1ebe-d71b-436f-ab12-25305e814171", "core": true, "auto_approve": true,