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: depth: 2 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: | git fetch migrations_added=$(git diff origin/${{ github.base_ref }} --name-only db/migrate/ | wc -l) echo "Migrations added: $migrations_added" bundle exec rake db:schema:load db:migrate:status db:migrate:redo git diff --exit-code db/schema.rb 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 copyright_notice: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: token: ${{ secrets.ACTIONS_TOKEN }} ref: ${{ github.head_ref }} - uses: VinnyBabuManjaly/copyright-action@v1.0.0 with: CopyrightString: '# Copyright (C) 2024 Manuel Bustillo\n\n' FileType: '.rb' Path: 'app/, config/, db/, spec/' - uses: VinnyBabuManjaly/copyright-action@v1.0.0 with: CopyrightString: '<%# Copyright (C) 2024 Manuel Bustillo %>\n\n' FileType: '.erb' Path: 'app/' - name: Commit changes run: | git config --local user.email "bustikiller@bustikiller.com" git config --local user.name "Manuel Bustillo" git add . if [ -n "$(git status --porcelain)" ]; then echo "there are changes"; git commit -m "Add copyright notice" git push exit 1 else echo "no changes"; fi build-static-assets: runs-on: ubuntu-latest timeout-minutes: 30 needs: - unit_tests - rubocop - check-licenses - copyright_notice 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