|
| 1 | +name: Tests |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + schedule: |
| 8 | + # Weekly. |
| 9 | + - cron: "0 0 * * 0" |
| 10 | + |
| 11 | +jobs: |
| 12 | + track-config: |
| 13 | + name: Check track configuration |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + # master is needed in addition to HEAD, |
| 17 | + # because the README check only checks exercises changed since master. |
| 18 | + - uses: actions/checkout@v2 |
| 19 | + with: |
| 20 | + ref: master |
| 21 | + |
| 22 | + - uses: actions/checkout@v2 |
| 23 | + |
| 24 | + - name: Fetch |
| 25 | + run: bin/fetch-configlet |
| 26 | + |
| 27 | + - name: Lint |
| 28 | + run: bin/configlet lint . |
| 29 | + |
| 30 | + - name: Ensure READMEs are updated |
| 31 | + run: sh ./bin/ensure-readmes-are-updated.sh |
| 32 | + |
| 33 | + - name: Check configlet fmt |
| 34 | + run: sh ./bin/check-configlet-fmt.sh |
| 35 | + |
| 36 | + - name: Install yq (for stack resolvers) |
| 37 | + run: | |
| 38 | + sudo add-apt-repository -y ppa:rmescandon/yq |
| 39 | + sudo apt-get -q update |
| 40 | + sudo apt-get -y install yq |
| 41 | +
|
| 42 | + - name: Ensure stack resolvers synced |
| 43 | + run: sh ./bin/ensure-stack-resolvers-synced.sh |
| 44 | + |
| 45 | + - name: Check for invalid UUIDs |
| 46 | + # can be removed once `configlet lint` gains this ability. |
| 47 | + # Check issue https://github.com/exercism/configlet/issues/99 |
| 48 | + run: | |
| 49 | + uuids=$(jq --raw-output '.exercises | map(.uuid) | .[]' config.json) |
| 50 | + bad_uuid=$(echo "$uuids" | grep -vE '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$' || true) |
| 51 | + if [ -n "$bad_uuid" ]; then |
| 52 | + echo "invalid UUIDs found! please correct these to be valid UUIDs:" |
| 53 | + echo "$bad_uuid" |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | +
|
| 57 | + exercises: |
| 58 | + name: Check exercises |
| 59 | + runs-on: ubuntu-latest |
| 60 | + strategy: |
| 61 | + matrix: |
| 62 | + resolver: |
| 63 | + # We say lts-from-exercises here instead of a specific version. Reason: |
| 64 | + # Required CI checks are designated by their name + matrix values. |
| 65 | + # |
| 66 | + # If we wrote lts-A.B here, |
| 67 | + # then we'd ask an admin to make "Check exercises (lts-A.B)" required. |
| 68 | + # But what happens when we update to lts-C.D? |
| 69 | + # Then, an admin would need to make "Check exercises (lts-A.B)" not required, |
| 70 | + # and "Check exercises (lts-C.D)" required. |
| 71 | + # |
| 72 | + # We don't want to ask for that much admin intervention. |
| 73 | + # So we write lts-from-exercises, |
| 74 | + # and an admin only needs to make "Check exercises (lts-from-exercises)" required. |
| 75 | + - lts-from-exercises |
| 76 | + - nightly |
| 77 | + # Discussion seems to indicate that continue-on-error is not exactly equivalent to Travis's allow_failures, but it's the best we can do for now. |
| 78 | + # If failures on nightly cause too much confusion in CI status, |
| 79 | + # consider just not running against the nightly resolver. |
| 80 | + # https://github.com/actions/toolkit/issues/399 |
| 81 | + continue-on-error: ${{ matrix.resolver == 'nightly' }} |
| 82 | + steps: |
| 83 | + - uses: actions/checkout@v2 |
| 84 | + |
| 85 | + - name: Install yq (for stack resolvers) |
| 86 | + run: | |
| 87 | + sudo add-apt-repository -y ppa:rmescandon/yq |
| 88 | + sudo apt-get -q update |
| 89 | + sudo apt-get -y install yq |
| 90 | +
|
| 91 | + - name: Resolve resolver |
| 92 | + id: resolve-resolver |
| 93 | + run: | |
| 94 | + # We need this in two places: |
| 95 | + # 1. cache key |
| 96 | + # 2. --resolver arg to installing hlint |
| 97 | + # It's unsafe to just use lts-from-exercises as the cache key, |
| 98 | + # because that would cause caches from differing LTSes to collide |
| 99 | + # (if we have updated the LTS version of all exercises between job runs). |
| 100 | + if [ "${{ matrix.resolver }}" = "lts-from-exercises" ]; then |
| 101 | + resolver=$(yq read "$(ls -1 exercises/*/stack.yaml | head -1)" resolver) |
| 102 | + else |
| 103 | + resolver=${{ matrix.resolver }} |
| 104 | + fi |
| 105 | + echo "::set-output name=resolver::$resolver" |
| 106 | +
|
| 107 | + - name: Week number |
| 108 | + id: week-no |
| 109 | + run: | |
| 110 | + # We use this to form part of the cache key. |
| 111 | + # This will get us to periodically rebuild from scratch, |
| 112 | + # just to make sure that everything still works from scratch. |
| 113 | + # Because we also have a weekly build at the start of every week, |
| 114 | + # most of the time caches should hit. |
| 115 | + echo "::set-output name=week-no::$(date -u +%Y-%U)" |
| 116 | +
|
| 117 | + - uses: actions/cache@v2 |
| 118 | + id: cache |
| 119 | + with: |
| 120 | + path: | |
| 121 | + ~/.stack |
| 122 | + ~/.foldercache |
| 123 | + ~/.local/bin/hlint |
| 124 | + key: ${{ steps.resolve-resolver.outputs.resolver }}-${{ steps.week-no.outputs.week-no }}-${{ hashFiles('exercises/**/package.yaml') }} |
| 125 | + restore-keys: ${{ steps.resolve-resolver.outputs.resolver }}-${{ steps.week-no.outputs.week-no }}- |
| 126 | + |
| 127 | + - uses: actions/setup-haskell@v1 |
| 128 | + with: |
| 129 | + enable-stack: true |
| 130 | + stack-version: 'latest' |
| 131 | + |
| 132 | + - name: Install hlint |
| 133 | + run: | |
| 134 | + if [ -x ${HOME}/.local/bin/hlint ]; then |
| 135 | + echo already installed |
| 136 | + else |
| 137 | + stack --resolver ${{ steps.resolve-resolver.outputs.resolver }} install hlint |
| 138 | + fi |
| 139 | + ${HOME}/.local/bin/hlint --version |
| 140 | +
|
| 141 | + - name: HLint |
| 142 | + run: ${HOME}/.local/bin/hlint ${{ github.workspace }} |
| 143 | + |
| 144 | + - name: Check exercises |
| 145 | + run: | |
| 146 | + # Explicit set exercises' resolver only if it's not the current one. |
| 147 | + if [ "${{ matrix.resolver }}" != "lts-from-exercises" ]; then |
| 148 | + export SET_RESOLVER="--resolver ${{ matrix.resolver }}" |
| 149 | + fi |
| 150 | +
|
| 151 | + for exercise in ${{ github.workspace }}/exercises/*/; do |
| 152 | + time bin/test-stub $exercise |
| 153 | + time bin/test-all-examples $exercise |
| 154 | + done |
0 commit comments