|
| 1 | +name: CI |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | +env: |
| 8 | + RAILS_ENV: test |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + name: "Test" |
| 12 | + runs-on: ubuntu-latest |
| 13 | + env: |
| 14 | + DATABASE_URL: postgres://postgres:postgres@localhost:5432/ci |
| 15 | + services: |
| 16 | + postgres: |
| 17 | + image: postgres:16-alpine |
| 18 | + env: |
| 19 | + POSTGRES_DB: ci |
| 20 | + POSTGRES_USER: postgres |
| 21 | + POSTGRES_PASSWORD: postgres |
| 22 | + ports: |
| 23 | + - 5432:5432 |
| 24 | + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + - uses: ruby/setup-ruby@v1 |
| 28 | + with: |
| 29 | + bundler-cache: true |
| 30 | + - uses: oven-sh/setup-bun@v2 |
| 31 | + with: |
| 32 | + bun-version: 1.1.8 |
| 33 | + - run: bun install |
| 34 | + - run: bundle exec rake db:migrate |
| 35 | + - run: bundle exec rake test:all |
| 36 | + rubocop: |
| 37 | + name: "Lint / rubocop" |
| 38 | + runs-on: ubuntu-latest |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@v4 |
| 41 | + - uses: ruby/setup-ruby@v1 |
| 42 | + with: |
| 43 | + bundler-cache: true |
| 44 | + - run: bin/rubocop |
| 45 | + brakeman: |
| 46 | + name: "Security / brakeman" |
| 47 | + runs-on: ubuntu-latest |
| 48 | + steps: |
| 49 | + - uses: actions/checkout@v4 |
| 50 | + - uses: ruby/setup-ruby@v1 |
| 51 | + with: |
| 52 | + bundler-cache: true |
| 53 | + - run: bundle exec brakeman --exit-on-warn --no-progress --color --output /dev/stdout |
| 54 | + bundle-audit: |
| 55 | + name: "Security / bundle-audit" |
| 56 | + runs-on: ubuntu-latest |
| 57 | + steps: |
| 58 | + - uses: actions/checkout@v4 |
| 59 | + - uses: ruby/setup-ruby@v1 |
| 60 | + with: |
| 61 | + bundler-cache: true |
| 62 | + - run: bundle exec bundle-audit check --update -v |
| 63 | + build-and-push-image: |
| 64 | + name: "Build and push Docker image" |
| 65 | + if: github.ref == 'refs/heads/main' |
| 66 | + runs-on: ubuntu-latest |
| 67 | + env: |
| 68 | + REGISTRY: ghcr.io |
| 69 | + IMAGE_NAME: ${{ github.repository }} |
| 70 | + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. |
| 71 | + permissions: |
| 72 | + contents: read |
| 73 | + packages: write |
| 74 | + |
| 75 | + steps: |
| 76 | + - name: Checkout repository |
| 77 | + uses: actions/checkout@v4 |
| 78 | + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. |
| 79 | + - name: Log in to the Container registry |
| 80 | + uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 |
| 81 | + with: |
| 82 | + registry: ${{ env.REGISTRY }} |
| 83 | + username: ${{ github.actor }} |
| 84 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 85 | + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. |
| 86 | + - name: Extract metadata (tags, labels) for Docker |
| 87 | + id: meta |
| 88 | + uses: docker/metadata-action@a64d0487d7069df33b279515d35d60fa80e2ea62 |
| 89 | + with: |
| 90 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 91 | + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. |
| 92 | + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. |
| 93 | + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. |
| 94 | + - name: Build and push Docker image |
| 95 | + id: push |
| 96 | + uses: docker/build-push-action@15560696de535e4014efeff63c48f16952e52dd1 |
| 97 | + with: |
| 98 | + context: . |
| 99 | + push: true |
| 100 | + tags: ${{ steps.meta.outputs.tags }} |
| 101 | + labels: ${{ steps.meta.outputs.labels }} |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | + |
0 commit comments