gregschmit/rails-rest-framework

View on GitHub
.github/workflows/pipeline.yml

Summary

Maintainability
Test Coverage
name: Pipeline
on: push
jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: ruby/setup-ruby@v1
        with:
          bundler-cache: true
      - name: Run code checks
        run: bundle exec rubocop
  test:
    needs: check
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        ruby: [2.7.5, 3.0.6, 3.1.4, 3.2.2]
        rails: [6.0.6, 6.1.7, 7.0.4, 7.1.3]
        exclude:
          - ruby: 3.1.4
            rails: 6.0.6
          - ruby: 3.2.2
            rails: 6.0.6
    env:
      RAILS_VERSION: ${{ matrix.rails }}
      CUSTOM_RUBY_VERSION: ${{ matrix.ruby }}
    steps:
      - uses: actions/checkout@v4
      - name: Remove `Gemfile.lock` because this is a matrix job
        run: rm Gemfile.lock
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: ${{ matrix.ruby }}
          bundler-cache: true
      - name: Execute migrations
        run: bin/rails db:migrate
      - name: Run tests
        run: BACKTRACE=1 bin/rails test
      - name: Check if coverage LCOV file exists
        id: lcov_exists
        uses: andstor/file-existence-action@v3
        with:
          files: coverage/lcov.info
      - name: Submit coverage to `coveralls.io` if LCOV file exists
        uses: coverallsapp/github-action@master
        if: steps.lcov_exists.outputs.files_exists == 'true'
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
  deploy:
    needs: test
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
          fetch-tags: true
      - uses: webfactory/ssh-agent@v0.9.0
        with:
          ssh-private-key: ${{ secrets.APPSERVER_DEPLOY_SSH_KEY }}
      - name: Setup appserver known_hosts
        run: cat config/appserver.known_hosts >> ~/.ssh/known_hosts
      - name: Set up Docker Buildx for cache
        uses: docker/setup-buildx-action@v3
      - name: Expose GitHub Runtime for cache
        uses: crazy-max/ghaction-github-runtime@v3
      - uses: ruby/setup-ruby@v1
        with:
          bundler-cache: true
      - name: Build and deploy using Kamal
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          PRODUCTION_KEY: ${{ secrets.PRODUCTION_KEY }}
        # We use `kamal setup` rather than `kamal deploy` so if we add or reprovision nodes, they
        # get configured and the env is always pushed.
        run: bundle exec kamal setup
      - uses: snok/container-retention-policy@v2
        with:
          image-names: rails-rest-framework
          cut-off: one minute ago UTC+2
          skip-tags: latest
          account-type: personal
          token: ${{ secrets.GITHUB_TOKEN }}
          token-type: github-token
  release:
    needs: test
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/')
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
          fetch-tags: true
      - uses: ruby/setup-ruby@v1
        with:
          bundler-cache: true
      - name: Build the gem
        run: gem build rest_framework.gemspec -o rest_framework.gem
      - name: Display VERSION
        run: cat VERSION
      - name: Push to RubyGems
        env:
          GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
        run: gem push rest_framework.gem