diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 000000000..0b217d738 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,149 @@ +name: CI + +# Run this workflow every time a new commit is pushed to the repository +on: + push: + branches: + - master + pull_request: + +jobs: + ensure-conventions: + name: Ensure conventions are followed + runs-on: ubuntu-latest + + steps: + # Checks out a copy of your repository on the ubuntu-latest machine + - name: Checkout code + uses: actions/checkout@v2 + + - name: Ensure src/lib.rs files exist + run: bash ./_test/ensure-lib-src-rs-exist.sh + + - name: Count ignores + run: sh ./_test/count-ignores.sh + + - name: Check UUIDs + run: sh ./_test/check-uuids.sh + + - name: Verify exercise difficulties + run: ./_test/verify-exercise-difficulties.sh + + - name: Check exercises for authors + run: ./_test/check-exercises-for-authors.sh + + configlet: + name: Setup configlet + runs-on: ubuntu-latest + + steps: + # Checks out master locally so that it is available to the scripts. + - name: Checkout master + uses: actions/checkout@v2 + with: + ref: master + + # Checks out a copy of your repository on the ubuntu-latest machine + - 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 + + - name: Check configlet format + run: ./_test/check-configlet-fmt.sh + + - name: Ensure readmes are updated + run: sh ./_test/ensure-readmes-are-updated.sh + + - name: Lint configlet + run: ./bin/configlet lint . + + + compilation: + name: Check compilation + runs-on: ubuntu-latest + + strategy: + # Allows running the job multiple times with different configurations + matrix: + rust: ["stable", "beta"] + deny_warnings: ['', '1'] + + steps: + # Checks out master locally so that it is available to the scripts. + - name: Checkout master + uses: actions/checkout@v2 + with: + ref: master + + # Checks out a copy of your repository on the ubuntu-latest machine + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup toolchain + uses: actions-rs/toolchain@v1 + with: + 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 }} + run: ./_test/check-exercises.sh + continue-on-error: ${{ matrix.rust == 'beta' && matrix.deny_warnings == '1' }} + + - name: Ensure stubs compile + env: + DENYWARNINGS: ${{ matrix.deny_warnings }} + run: sh ./_test/ensure-stubs-compile.sh + continue-on-error: ${{ matrix.rust == 'beta' && matrix.deny_warnings == '1' }} + + - name: Check exercise crate + env: + DENYWARNINGS: ${{ matrix.deny_warnings }} + run: sh ./_test/check-exercise-crate.sh + continue-on-error: ${{ matrix.rust == 'beta' && matrix.deny_warnings == '1' }} + + nightly-compilation: + name: Check exercises on nightly (benchmark enabled) + runs-on: ubuntu-latest + continue-on-error: true # It's okay if the nightly job fails + + steps: + # Checks out master locally so that it is available to the scripts. + - name: Checkout master + uses: actions/checkout@v2 + with: + ref: master + + # Checks out a copy of your repository on the ubuntu-latest machine + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup nightly toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + default: true + + - name: Check exercises + env: + BENCHMARK: '1' + run: ./_test/check-exercises.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index eb332772d..000000000 --- a/.travis.yml +++ /dev/null @@ -1,31 +0,0 @@ ---- -language: rust -script: -- "./_test/check-exercises.sh" -- "bash ./_test/ensure-lib-src-rs-exist.sh" -- "sh ./_test/ensure-stubs-compile.sh" -- "sh ./_test/count-ignores.sh" -- "./bin/fetch-configlet" -- "./_test/check-configlet-fmt.sh" -- "sh ./_test/ensure-readmes-are-updated.sh" -- "./bin/configlet lint ." -- "sh ./_test/check-uuids.sh" -- "./_test/verify-exercise-difficulties.sh" -- "./_test/check-exercises-for-authors.sh" -- "sh ./_test/check-exercise-crate.sh" -sudo: false -rust: - - stable - - beta -env: - - DENYWARNINGS= - - DENYWARNINGS=1 -matrix: - include: - - rust: nightly - env: BENCHMARK=1 - script: "./_test/check-exercises.sh" - allow_failures: - - rust: nightly - - rust: beta - env: DENYWARNINGS=1 diff --git a/_test/check-configlet-fmt.sh b/_test/check-configlet-fmt.sh index 281e5205a..54a5b4d7e 100755 --- a/_test/check-configlet-fmt.sh +++ b/_test/check-configlet-fmt.sh @@ -8,7 +8,7 @@ check_pattern="config.json\|config/maintainers.json" if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then # Check the changes on the current branch against master branch - git diff --name-only master | grep "$check_pattern" + 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. diff --git a/_test/check-exercise-crate.sh b/_test/check-exercise-crate.sh index 79cc11301..65e55fa11 100755 --- a/_test/check-exercise-crate.sh +++ b/_test/check-exercise-crate.sh @@ -6,7 +6,7 @@ EXERCISE_CRATE_PATH="util/exercise" if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then # Check the changes on the current branch against master branch - git diff --name-only master | grep "$EXERCISE_CRATE_PATH" + 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. @@ -23,7 +23,7 @@ TRACK_ROOT="$(git rev-parse --show-toplevel)" if !(cd "$TRACK_ROOT/$EXERCISE_CRATE_PATH" && cargo check); then echo "\nAn error has occurred while building the exercise crate.\nPlease make it compile." - + exit 1 else echo "\nexercise crate has been successfully built." diff --git a/_test/check-exercises.sh b/_test/check-exercises.sh index f97615c96..0ea61e2b7 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 - files="$(git diff --diff-filter=d --name-only master | grep "exercises/" | cut -d '/' -f -2 | sort -u | awk -v repo=$repo '{print repo"/"$1}')" + 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/* fi diff --git a/_test/ensure-readmes-are-updated.sh b/_test/ensure-readmes-are-updated.sh index e84b57a73..33abb130c 100755 --- a/_test/ensure-readmes-are-updated.sh +++ b/_test/ensure-readmes-are-updated.sh @@ -12,7 +12,7 @@ newline=$'\n ' missing_readmes="" wrong_readmes="" -for exercise in $(git diff --diff-filter=d --name-only master..$(git rev-parse --abbrev-ref HEAD) | grep exercises/ | cut -d'/' -f2 -s | sort -fu); do +for exercise in $(git diff --diff-filter=d --name-only remotes/origin/master..$(git rev-parse --abbrev-ref HEAD) | grep exercises/ | cut -d'/' -f2 -s | sort -fu); do echo "Checking readme for $exercise" readme_path="exercises/${exercise}/README.md" if [ ! -f $readme_path ]; then diff --git a/_test/ensure-stubs-compile.sh b/_test/ensure-stubs-compile.sh index e2822aa98..8880dbf90 100755 --- a/_test/ensure-stubs-compile.sh +++ b/_test/ensure-stubs-compile.sh @@ -3,7 +3,7 @@ repo=$(cd "$(dirname "$0")/.." && pwd) if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then - changed_exercises="$(git diff --diff-filter=d --name-only master | grep "exercises/" | cut -d '/' -f -2 | sort -u | awk -v repo=$repo '{print repo"/"$1}')" + 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/* fi