From f12ae0b81fff7ed04fb7896272800536f0ddf334 Mon Sep 17 00:00:00 2001 From: Owen Date: Tue, 10 Nov 2026 08:34:44 +0100 Subject: [PATCH] Add CI workflow with test and release build (#127) --- .github/workflows/ci.yml | 96 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..277ac3c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,96 @@ +name: CI + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +concurrency: + group: ci-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + test: + name: Test + runs-on: ubuntu-24.04 + env: + MIX_ENV: test + + services: + postgres: + image: postgres:18.0 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + ports: + - 5432:5432 + options: >- + --health-cmd "pg_isready -U postgres" + --health-interval 5s + --health-timeout 5s + --health-retries 10 + + steps: + - uses: actions/checkout@v4 + - uses: jdx/mise-action@v2 + + - uses: actions/cache@v4 + with: + path: | + deps + _build + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-mix-test-${{ hashFiles('mix.lock', 'mise.toml') }} + restore-keys: | + ${{ runner.os }}-mix-test- + + - run: mix local.hex --force + - run: mix local.rebar --force + - run: mix deps.get + - run: mix format --check-formatted + - run: mix precommit + + build-release: + name: Build release + needs: test + runs-on: ubuntu-24.04 + env: + MIX_ENV: prod + SECRET_KEY_BASE: build-only-secret-key-base-build-only-secret-key-base-build-only-secret-key-base + DATABASE_URL: ecto://postgres:postgres@127.0.0.1:5432/chesstrainer_build + SES_REGION: eu-north-1 + SES_ACCESS_KEY_ID: build + SES_SECRET_ACCESS_KEY: build + + steps: + - uses: actions/checkout@v4 + - uses: jdx/mise-action@v2 + + - uses: actions/cache@v4 + with: + path: | + deps + _build + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-mix-prod-${{ hashFiles('mix.lock', 'mise.toml') }} + restore-keys: | + ${{ runner.os }}-mix-prod- + + - run: mix local.hex --force + - run: mix local.rebar --force + - run: mix deps.get --only prod + - run: mix assets.setup + - run: mix assets.deploy + - run: mix release + - run: tar -czf chesstrainer-release.tar.gz -C _build/prod/rel/chesstrainer . + + - uses: actions/upload-artifact@v4 + with: + name: chesstrainer-release + path: chesstrainer-release.tar.gz + retention-days: 7