Fix builds for Rails integration tests #151
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Rails integration tests | |
on: | |
pull_request: | |
push: | |
branches: | |
- main | |
jobs: | |
set-matrix: | |
runs-on: ubuntu-latest | |
name: Set Rails versions | |
outputs: | |
RAILS_VERSIONS: ${{ steps.compute-outputs.outputs.RAILS_VERSIONS }} | |
steps: | |
# Get latest Rails versions for 5.x.x, 6.x.x and 7.x.x | |
- id: compute-outputs | |
name: Compute outputs | |
run: | | |
rails_versions=$(curl https://rubygems.org/api/v1/versions/rails.json | jq 'group_by(.number[:1])[] | (.[0].number) | select(.[:1]|tonumber > 4)' | jq -s -c) | |
echo 'RAILS_VERSIONS=["5.2.8.1","6.1.7.8","7.1.3.4"]' >> $GITHUB_OUTPUT | |
build-rails: | |
strategy: | |
fail-fast: false | |
matrix: | |
# Build containers with the latest 5.x.x, 6.x.x and 7.x.x Rails versions | |
rails: ${{ fromJSON(needs.set-matrix.outputs.RAILS_VERSIONS) }} | |
runs-on: ubuntu-latest | |
name: Build and cache Docker containers | |
needs: set-matrix | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and cache | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfile | |
build-args: | | |
RAILS_VERSION=${{ matrix.rails }} | |
MAIL_NOTIFY_BRANCH=${{ github.ref }} | |
push: false | |
tags: mail-notify-integration-rails-${{ matrix.rails }}:latest | |
outputs: type=docker, dest=/tmp/rails-${{ matrix.rails }}-image.tar | |
cache-from: type=gha,scope=build-${{ matrix.rails }} | |
cache-to: type=gha,mode=min,scope=build-${{ matrix.rails }} | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: rails-${{ matrix.rails }}-image | |
path: /tmp/rails-${{ matrix.rails }}-image.tar | |
mailer-previews: | |
strategy: | |
fail-fast: false | |
# Run against the latest 5.x.x, 6.x.x and 7.x.x Rails versions | |
matrix: | |
rails: ${{ fromJSON(needs.set-matrix.outputs.RAILS_VERSIONS) }} | |
runs-on: ubuntu-latest | |
needs: | |
- set-matrix | |
- build-rails | |
steps: | |
- name: Download image | |
uses: actions/download-artifact@v4 | |
with: | |
name: rails-${{ matrix.rails }}-image | |
path: /tmp | |
- name: Load image | |
run: docker load --input /tmp/rails-${{ matrix.rails }}-image.tar | |
- name: Run integration tests | |
env: | |
NOTIFY_API_KEY: ${{ secrets.NOTIFY_API_KEY }} | |
run: | | |
docker run --rm -e "NOTIFY_API_KEY=$NOTIFY_API_KEY" \ | |
mail-notify-integration-rails-${{ matrix.rails }}:latest bin/rails test:system | |
sending: | |
strategy: | |
fail-fast: false | |
# Run against the latest 5.x.x, 6.x.x and 7.x.x Rails versions | |
matrix: | |
rails: ${{ fromJSON(needs.set-matrix.outputs.RAILS_VERSIONS) }} | |
runs-on: ubuntu-latest | |
needs: | |
- set-matrix | |
- build-rails | |
steps: | |
- name: Download image | |
uses: actions/download-artifact@v4 | |
with: | |
name: rails-${{ matrix.rails }}-image | |
path: /tmp | |
- name: Load image | |
run: docker load --input /tmp/rails-${{ matrix.rails }}-image.tar | |
- name: Run integration tests | |
env: | |
NOTIFY_API_KEY: ${{ secrets.NOTIFY_API_KEY }} | |
run: | | |
docker run --rm -e "NOTIFY_API_KEY=$NOTIFY_API_KEY" \ | |
mail-notify-integration-rails-${{ matrix.rails }}:latest bin/rails test | |
results: | |
if: ${{ always() }} | |
runs-on: ubuntu-latest | |
name: All integration tests | |
needs: | |
- mailer-previews | |
- sending | |
steps: | |
# If any of the previous actions failed, we return a non-zero exit code | |
- run: exit 1 | |
if: >- | |
${{ | |
contains(needs.*.result, 'failure') | |
|| contains(needs.*.result, 'cancelled') | |
|| contains(needs.*.result, 'skipped') | |
}} |