|
| 1 | +--- |
| 2 | +# This file is @generated by `bin/rails generate test_strategy test_strategy_timings.csv` |
| 3 | +# Please edit the template and regenerate, rather than edit this file. |
| 4 | + |
| 5 | +name: Tests |
| 6 | + |
| 7 | +on: [pull_request] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + actions: read |
| 12 | + |
| 13 | +jobs: |
| 14 | + remaining_test_matrix: |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + ruby-version: |
| 19 | + - '3.1.6' |
| 20 | + test-group: |
| 21 | + - "[a-b]" |
| 22 | + - "[c]" |
| 23 | + - "[d-m]" |
| 24 | + - "[n-z]" |
| 25 | + |
| 26 | + name: "Ruby ${{ matrix.ruby-version }} Tests (${{ matrix.test-group }})" |
| 27 | + |
| 28 | + runs-on: ubuntu-latest |
| 29 | + |
| 30 | + services: |
| 31 | + postgres: |
| 32 | + image: postgres |
| 33 | + env: |
| 34 | + POSTGRES_USER: rails |
| 35 | + POSTGRES_PASSWORD: rails_password |
| 36 | + options: >- |
| 37 | + --health-cmd pg_isready |
| 38 | + --health-interval 10s |
| 39 | + --health-timeout 5s |
| 40 | + --health-retries 5 |
| 41 | + --name postgres |
| 42 | + ports: |
| 43 | + - 5432:5432 |
| 44 | + |
| 45 | + env: |
| 46 | + DB_HOST: localhost |
| 47 | + DB_PORT: 5432 |
| 48 | + DB_USERNAME: rails |
| 49 | + DB_PASSWORD: rails_password |
| 50 | + |
| 51 | + # Prep the whole stack in test-only mode: |
| 52 | + RAILS_ENV: test |
| 53 | + |
| 54 | + steps: |
| 55 | + - uses: actions/checkout@v3 |
| 56 | + - name: Set timezone to Europe/London |
| 57 | + run: sudo timedatectl set-timezone Europe/London |
| 58 | + - name: Use bundled npm files |
| 59 | + run: printf 'disable-self-update-check true\nyarn-offline-mirror "./vendor/npm-packages-offline-cache"\nyarn-offline-mirror-pruning false\n' > .yarnrc |
| 60 | + - name: Set up Ruby + Bundle |
| 61 | + uses: ruby/setup-ruby@v1 |
| 62 | + with: |
| 63 | + bundler-cache: true |
| 64 | + ruby-version: ${{ matrix.ruby-version }} |
| 65 | + - name: Inject configuration |
| 66 | + run: cp config/database.yml{.ci,} |
| 67 | + - name: Prepare the database |
| 68 | + run: bin/rails db:setup |
| 69 | + - name: Precompile assets |
| 70 | + # Since ruby/setup-ruby@v1 moved to Node.js v18 we need the extra options |
| 71 | + # until we move to newer webpacker / stop using it. |
| 72 | + # I've tried using a newer hash function in config/webpack/environment.js |
| 73 | + # by adding the following line, but this didn't help with github actions |
| 74 | + # # environment.config.set('output.hashFunction', 'sha256') |
| 75 | + # https://stackoverflow.com/questions/69692842/error-message-error0308010cdigital-envelope-routinesunsupported/73465262#73465262 |
| 76 | + run: NODE_OPTIONS=--openssl-legacy-provider bin/rails yarn:install assets:clobber assets:precompile |
| 77 | + - name: Run tests |
| 78 | + run: PARALLEL_WORKERS=1 bin/rails test 'test/**/${{ matrix.test-group }}*_test.rb' |
| 79 | + |
| 80 | + # A utility job upon which Branch Protection can depend, |
| 81 | + # thus remaining agnostic of the matrix. |
| 82 | + remaining_tests: |
| 83 | + if: ${{ always() }} |
| 84 | + runs-on: ubuntu-latest |
| 85 | + # name: Matrix |
| 86 | + needs: remaining_test_matrix |
| 87 | + steps: |
| 88 | + - name: Check build matrix status |
| 89 | + if: ${{ needs.remaining_test_matrix.result != 'success' }} |
| 90 | + run: exit 1 |
| 91 | + |
| 92 | + notify: |
| 93 | + # Run only on master, but regardless of whether tests past: |
| 94 | + if: ${{ always() }} |
| 95 | + # if: ${{ always() && github.ref == 'refs/heads/master' }} |
| 96 | + |
| 97 | + needs: |
| 98 | + - remaining_tests |
| 99 | + |
| 100 | + runs-on: ubuntu-latest |
| 101 | + |
| 102 | + steps: |
| 103 | + - uses: actions/setup-node@v3 |
| 104 | + # with: |
| 105 | + # node-version: '16.x' |
| 106 | + - id: slack-payload-generator |
| 107 | + env: |
| 108 | + COMMIT_MESSAGE: ${{ github.event.commits[0].message }} |
| 109 | + run: |- |
| 110 | + node -e " |
| 111 | + const passed = '${{ needs.integration_tests.result }}' === 'success' && '${{ needs.models_tests.result }}' === 'success' && '${{ needs.remaining_tests.result }}' === 'success' |
| 112 | +
|
| 113 | + const text = process.env.COMMIT_MESSAGE |
| 114 | +
|
| 115 | + let attachments = [ |
| 116 | + { |
| 117 | + fallback: text, |
| 118 | + text: text, |
| 119 | + fields: [ |
| 120 | + { title: 'Author', value: '${{ github.actor }}', short: true }, |
| 121 | + { title: 'Revision', value: '${{ github.sha }}', short: true } |
| 122 | + ] |
| 123 | + // ts: @commit.author[:time].to_i |
| 124 | + } |
| 125 | + ] |
| 126 | +
|
| 127 | + if (passed) { |
| 128 | + attachments.push({ |
| 129 | + color: 'good', |
| 130 | + text: 'Tests passed' |
| 131 | + }) |
| 132 | + } else { |
| 133 | + attachments.push({ |
| 134 | + color: 'danger', |
| 135 | + text: 'Test(s) failed' |
| 136 | + }) |
| 137 | + } |
| 138 | +
|
| 139 | + let payload = { |
| 140 | + channel: '${{ secrets.SLACK_CHANNEL }}', |
| 141 | + username: 'GitHub CI', |
| 142 | + icon_emoji: ':robot_face:', |
| 143 | + attachments: attachments |
| 144 | + } |
| 145 | +
|
| 146 | + console.log('json=' + JSON.stringify(payload)) |
| 147 | + " >> "$GITHUB_OUTPUT" |
| 148 | + - uses: 8398a7/action-slack@v3 |
| 149 | + with: |
| 150 | + status: custom |
| 151 | + fields: workflow,commit,author |
| 152 | + custom_payload: ${{ steps.slack-payload-generator.outputs.json }} |
| 153 | + env: |
| 154 | + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |
0 commit comments