GitHub Actions with basic settings

When setting up an app to work with GHA on GitHub (not self-hosted) you may stumble upon some solvable issues. Here, I want to remind myself and maybe save someone’s time in setting up their own verification script. It doesn’t need much explanation, the configuration rather speaks for itself. Enjoy!

name: verify

on:
  push:
    branches:
        - develop

env:
  RUBY_VERSION: '2.7.8' # Yes, still on it but we plan...
  RACK_ENV: test
  TZ: "/usr/share/zoneinfo/Europe/Warsaw"
  CACHED_PATHS: |
    ~/.cache
    ~/.bundle
    vendor/bundle
  CONFIG_FILES_COPY: |
    cp .rspec.sample .rspec
    cp .env.sample .env

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - name: SETUP Checkout code
        uses: actions/checkout@v4.1.0

      # Private gems need public keys in their deploy keys
      # while repos that use them need private keys
      # which you can configure as organisation wide
      - name: SETUP Use ssh-agent
        uses: webfactory/ssh-agent@v0.8.0
        with:
          ssh-private-key: |
            ${{ secrets.GEM_ONE_PRIVATE_KEY }}
            ${{ secrets.GEM_TWO_PRIVATE_KEY }}
            ${{ secrets.GEM_THREE_PRIVATE_KEY }}

      - name: SETUP Cache packages
        uses: actions/cache@v3
        with:
          path: ${{ env.CACHED_PATHS }}
          key: "${{ runner.os }}-${{ hashFiles('Gemfile.lock') }}}"

      - name: SETUP Ruby and install gems
        uses: ruby/setup-ruby@v1
        with:
          bundler-cache: true
          ruby-version: ${{ env.RUBY_VERSION }}

      - name: SETUP Copy sample configs
        run: ${{ env.CONFIG_FILES_COPY }}

      - name: SETUP Secrets for env
        run: |
          echo "ENV_VAR_ONE=${{ secrets.VAR_ONE }}" >> $GITHUB_ENV
          echo "ENV_VAR_TWO=${{ secrets.VAR_TWO }}" >> $GITHUB_ENV

      - name: TEST Rubocop
        run: bundle exec rubocop

      - name: TEST RSpec
        run: bundle exec rspec --profile 10 --format progress

      - name: TEST Bundle audit
        run: |
          gem install bundle-audit
          bundle audit check --update

      - name: Google Chat Notification
        uses: Co-qn/google-chat-notification@releases/v1
        with:
          name: ${{ github.event.repository.name }} - ${{ github.event.commits[0].author.name }} -
          url: ${{ vars.GOOGLE_CHAT_WEBHOOK }}
          status: ${{ job.status }}
        if: always()

Leave a Reply

Your email address will not be published. Required fields are marked *