name: Run unit tests on: push: branches: - main pull_request: concurrency: group: ${{ github.ref }} cancel-in-progress: true jobs: unit_tests: runs-on: ubuntu-latest services: &services postgres: image: postgres env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres ports: - 5432 steps: - uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} - uses: ruby/setup-ruby@v1.207.0 - run: bundle install - &postgres_wait name: Wait until Postgres is ready to accept connections run: | apt-get update && apt-get install -f -y postgresql-client until pg_isready -h postgres -U postgres -d postgres do sleep 1 echo "Trying again" done - run: | bundle exec rake db:schema:load bundle exec rake db:migrate:redo STEP=5 - run: | bundle exec rspec env: RAILS_ENV: test DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres - name: Clean up containers generated by this flow if: failure() run: docker ps --filter network=$JOB_CONTAINER_NAME-$GITHUB_JOB-network --filter name=$JOB_CONTAINER_NAME-* --format "{{.ID}}" | xargs docker rm -f rubocop: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} - uses: ruby/setup-ruby@v1.207.0 - run: bundle install - run: bundle exec rubocop --force-exclusion --parallel check-licenses: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} - uses: ruby/setup-ruby@v1.207.0 - name: Install project dependencies run: bundle install --jobs `getconf _NPROCESSORS_ONLN` - name: Run license finder run: license_finder build-static-assets: runs-on: ubuntu-latest timeout-minutes: 30 needs: - unit_tests - rubocop - check-licenses steps: - uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to the private Docker registry uses: docker/login-action@v3 with: registry: ${{ secrets.PRIVATE_REGISTRY_HOST }} username: ${{ secrets.PRIVATE_REGISTRY_USERNAME }} password: ${{ secrets.PRIVATE_REGISTRY_TOKEN }} - name: Build and push intermediate stages (build) uses: docker/build-push-action@v6 with: context: . target: build push: ${{ github.ref == 'refs/heads/main' }} tags: ${{ secrets.PRIVATE_REGISTRY_HOST }}/${{ env.GITHUB_REPOSITORY }}:build cache-from: type=registry,ref=${{ secrets.PRIVATE_REGISTRY_HOST }}/${{ env.GITHUB_REPOSITORY }}:build cache-to: type=inline - name: Build and push (final) uses: docker/build-push-action@v6 with: context: . push: ${{ github.ref == 'refs/heads/main' }} tags: ${{ secrets.PRIVATE_REGISTRY_HOST }}/${{ env.GITHUB_REPOSITORY }}:latest cache-from: type=registry,ref=${{ secrets.PRIVATE_REGISTRY_HOST }}/${{ env.GITHUB_REPOSITORY }}:latest cache-to: type=inline