140 lines
4.2 KiB
YAML
140 lines
4.2 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches-ignore: ['master']
|
|
pull_request:
|
|
branches: ['master']
|
|
|
|
jobs:
|
|
test:
|
|
name: Lint and Test
|
|
runs-on: ubuntu-latest
|
|
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
|
|
env:
|
|
COMPOSE_FILE: ./docker-compose.ci.yml
|
|
MIX_ENV: test
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Pull prebuilt images
|
|
run: docker compose pull
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Build docker image
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: ./docker/dev.Dockerfile
|
|
load: true
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Run Docker image
|
|
run: docker compose up --detach
|
|
|
|
# NOTE: All exec commands use the -T flag to compensate for
|
|
# a bug in the GitHub Actions runner where its stdin/stderr
|
|
# will erroneously report that it's a TTY.
|
|
# Aside from handling this bug the -T flag is not required
|
|
# See https://github.com/actions/runner/issues/241 and https://github.com/docker/compose/issues/8537
|
|
- name: Install Elixir and JS deps
|
|
run: |
|
|
docker compose exec -T phx mix deps.get && yarn install && cd assets && yarn install && cd ..
|
|
|
|
- name: Create and Migrate database
|
|
run: |
|
|
docker compose exec -T phx mix ecto.create
|
|
docker compose exec -T phx mix ecto.migrate
|
|
|
|
- name: Run code checks
|
|
run: docker compose exec -T phx mix check --no-fix --no-retry
|
|
|
|
docker-pr:
|
|
name: Build PR Image
|
|
runs-on: ubuntu-latest
|
|
needs: test
|
|
# Fork PRs can't write to GHCR, so skip them to avoid auth failures
|
|
if: |
|
|
github.event_name == 'pull_request' &&
|
|
!startsWith(github.head_ref, 'release-please') &&
|
|
github.event.pull_request.head.repo.full_name == github.repository
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Get short SHA and lowercase repo
|
|
id: meta
|
|
run: |
|
|
echo "sha=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT
|
|
echo "repo=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: ./docker/selfhosted.Dockerfile
|
|
platforms: linux/amd64
|
|
push: true
|
|
tags: ghcr.io/${{ steps.meta.outputs.repo }}:pr-${{ github.event.pull_request.number }}-${{ steps.meta.outputs.sha }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
docker-rc:
|
|
name: Build RC Image
|
|
runs-on: ubuntu-latest
|
|
needs: test
|
|
if: |
|
|
github.event_name == 'pull_request' &&
|
|
startsWith(github.head_ref, 'release-please') &&
|
|
github.event.pull_request.head.repo.full_name == github.repository
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Get version and lowercase repo
|
|
id: meta
|
|
run: |
|
|
echo "version=$(cat version.txt)" >> $GITHUB_OUTPUT
|
|
echo "repo=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: ./docker/selfhosted.Dockerfile
|
|
platforms: linux/amd64
|
|
push: true
|
|
tags: ghcr.io/${{ steps.meta.outputs.repo }}:rc-${{ steps.meta.outputs.version }}-${{ github.run_number }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|