pinchflat/.github/workflows/release-please.yml
2026-06-14 13:45:17 -05:00

161 lines
5.1 KiB
YAML

name: Release Please
on:
push:
branches: ['master']
jobs:
test:
name: Lint and Test
runs-on: ubuntu-latest
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
- 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
release-please:
name: Release Please
runs-on: ubuntu-latest
needs: test
permissions:
contents: write
pull-requests: write
outputs:
release_created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
steps:
- uses: googleapis/release-please-action@v4
id: release
with:
config-file: release-please-config.json
manifest-file: .release-please-manifest.json
# After a release is published: update mix.exs to "semver (calver)" so the
# running app displays both (e.g. "1.0.0 (2026.06.14)").
# Mix will warn that this isn't strict semver, which is fine for a Docker app.
update-mix-version:
name: Update mix.exs version string
runs-on: ubuntu-latest
needs: release-please
if: needs.release-please.outputs.release_created == 'true'
permissions:
contents: write
steps:
- name: Checkout master
uses: actions/checkout@v4
with:
ref: master
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set combined version in mix.exs
run: |
SEMVER=$(echo '${{ needs.release-please.outputs.tag_name }}' | sed 's/^v//')
DATE=$(date +"%Y.%-m.%-d")
DISPLAY="${SEMVER} (${DATE})"
sed -i "s|^ version: \".*\",| version: \"${DISPLAY}\",|" mix.exs
- name: Commit and push
run: |
SEMVER=$(echo '${{ needs.release-please.outputs.tag_name }}' | sed 's/^v//')
DATE=$(date +"%Y.%-m.%-d")
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add mix.exs
git diff --cached --quiet || git commit -m "chore: set app version to ${SEMVER} (${DATE}) [skip ci]"
git push
docker:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: [test, release-please]
permissions:
contents: read
packages: write
env:
dev_arch: 'linux/amd64'
release_arch: 'linux/amd64,linux/arm64'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Strip v prefix from release tag
id: version
if: needs.release-please.outputs.release_created == 'true'
run: |
echo "value=$(echo '${{ needs.release-please.outputs.tag_name }}' | sed 's/^v//')" >> $GITHUB_OUTPUT
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
docker.io/communitymaintained/pinchflat
ghcr.io/${{ github.repository }}
tags: |
type=raw,value=${{ steps.version.outputs.value }},enable=${{ needs.release-please.outputs.release_created == 'true' }}
type=raw,value=latest,enable=${{ needs.release-please.outputs.release_created == 'true' }}
type=raw,value=dev,enable=${{ needs.release-please.outputs.release_created != 'true' }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- 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: ${{ needs.release-please.outputs.release_created == 'true' && env.release_arch || env.dev_arch }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max