Skip to content

Commit fc7e538

Browse files
authored
replace TRAVIS_PULL_REQUEST with GITHUB_EVENT_NAME (#1007)
When moving off of Travis in #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 #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
1 parent fe13133 commit fc7e538

File tree

5 files changed

+21
-40
lines changed

5 files changed

+21
-40
lines changed

.github/workflows/tests.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ jobs:
4747
- name: Checkout code
4848
uses: actions/checkout@v2
4949

50-
# Sets TRAVIS_PULL_REQUEST to false if this is not a pull request.
51-
- name: set TRAVIS_PULL_REQUEST
52-
env:
53-
PR_NUMBER: ${{ github.event.pull_request.number }}
54-
run: echo "TRAVIS_PULL_REQUEST=${PR_NUMBER:-false}" >> $GITHUB_ENV
55-
5650
- name: Fetch configlet
5751
run: ./bin/fetch-configlet
5852

@@ -93,16 +87,7 @@ jobs:
9387
toolchain: ${{ matrix.rust }}
9488
default: true
9589

96-
# Sets TRAVIS_PULL_REQUEST to false if this is not a pull request.
97-
- name: set TRAVIS_PULL_REQUEST
98-
env:
99-
PR_NUMBER: ${{ github.event.pull_request.number }}
100-
run: echo "TRAVIS_PULL_REQUEST=${PR_NUMBER:-false}" >> $GITHUB_ENV
101-
10290
# run scripts as steps
103-
# TODO: the TRAVIS_PULL_REQUEST variable is a holdover from before the
104-
# migration to GitHub Actions. The scripts that use it do so in order to
105-
# run only on changed files.
10691
- name: Check exercises
10792
env:
10893
DENYWARNINGS: ${{ matrix.deny_warnings }}

_test/check-configlet-fmt.sh

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,15 @@
66
# Check if config.json or maintainers.json were modified
77
check_pattern="config.json\|config/maintainers.json"
88

9-
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
9+
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
1010
# Check the changes on the current branch against master branch
11-
git diff --name-only remotes/origin/master | grep "$check_pattern"
12-
else
13-
# Check the commits on the master branch made during the week
14-
# This is because Travis cron is set to test the master branch weekly.
15-
git diff --name-only "@{7 days ago}" | grep "$check_pattern"
16-
fi
17-
18-
if [ $? != 0 ]; then
19-
echo "config.json or maintainers.json were not changed - configlet fmt is aborted."
20-
21-
exit 0
11+
if ! git diff --name-only remotes/origin/master | grep -q "$check_pattern"; then
12+
echo "config.json or maintainers.json were not changed - configlet fmt is aborted."
13+
exit 0
14+
fi
2215
fi
16+
# If it's not a pull request, just always run it.
17+
# This script is cheap anyway.
2318

2419
repo=$(cd "$(dirname "$0")/.." && pwd)
2520
configlet="${repo}/bin/configlet"

_test/check-exercise-crate.sh

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@
44

55
EXERCISE_CRATE_PATH="util/exercise"
66

7-
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
7+
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
88
# Check the changes on the current branch against master branch
9-
git diff --name-only remotes/origin/master | grep "$EXERCISE_CRATE_PATH"
10-
else
11-
# Check the commits on the master branch made during the week
12-
# This is because Travis cron is set to test the master branch weekly.
13-
git diff --name-only "@{7 days ago}" | grep "$EXERCISE_CRATE_PATH"
9+
if ! git diff --name-only remotes/origin/master | grep -q "$EXERCISE_CRATE_PATH"; then
10+
echo "exercise crate was not modified. The script is aborted."
11+
exit 0
12+
fi
1413
fi
14+
# If it's not a pull request, just always run it.
15+
# Two scenarios:
16+
# 1. It's being run locally,
17+
# in which case we assume the person running it really does want to run it.
18+
# 2. It's being run on CI for master,
19+
# in which case we should check regardless of changes to exercise crate,
20+
# in case there's a new toolchain release, etc.
1521

16-
if [ $? != 0 ]; then
17-
echo "exercise crate was not modified. The script is aborted."
18-
19-
exit 0
20-
fi
2122

2223
TRACK_ROOT="$(git rev-parse --show-toplevel)"
2324

_test/check-exercises.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fi
2828

2929
repo=$(cd "$(dirname "$0")/.." && pwd)
3030

31-
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
31+
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
3232
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}')"
3333
else
3434
files=$repo/exercises/*

_test/ensure-stubs-compile.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
repo=$(cd "$(dirname "$0")/.." && pwd)
44

5-
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
5+
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
66
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}')"
77
else
88
changed_exercises=$repo/exercises/*

0 commit comments

Comments
 (0)