From de02c29fc9545e1a7b4e95686b2d758755d34f04 Mon Sep 17 00:00:00 2001 From: ruinivist Date: Tue, 26 May 2026 20:03:13 +0000 Subject: [PATCH] ci: publish to ghcr --- .github/workflows/publish-ghcr.yml | 78 ++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/publish-ghcr.yml diff --git a/.github/workflows/publish-ghcr.yml b/.github/workflows/publish-ghcr.yml new file mode 100644 index 0000000..224f374 --- /dev/null +++ b/.github/workflows/publish-ghcr.yml @@ -0,0 +1,78 @@ +name: Publish GHCR Image + +on: + push: + tags: + - 'release-*' + +permissions: + contents: read + packages: write + +concurrency: + group: publish-ghcr-${{ github.ref }} + cancel-in-progress: false + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Bun + uses: oven-sh/setup-bun@v2 + with: + bun-version: 1.3.11 + + - name: Install dependencies + run: bun install --frozen-lockfile + + - name: Run typecheck + run: bun run typecheck + + - name: Run tests + run: bun run test + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Derive image metadata + shell: bash + run: | + set -euo pipefail + + version="${GITHUB_REF_NAME#release-}" + version="${version#v}" + + if [[ -z "$version" ]]; then + echo "Release version is empty after stripping prefix from tag: $GITHUB_REF_NAME" >&2 + exit 1 + fi + + image_name="ghcr.io/${GITHUB_REPOSITORY,,}" + + { + echo "VERSION=$version" + echo "IMAGE_NAME=$image_name" + } >> "$GITHUB_ENV" + + - name: Build and push image + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ env.IMAGE_NAME }}:${{ env.VERSION }} + labels: | + org.opencontainers.image.source=https://github.com/${{ github.repository }} + org.opencontainers.image.revision=${{ github.sha }} + org.opencontainers.image.version=${{ env.VERSION }}