From f972b579fc4470d95e2abaedda649b7c0a303412 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 4 Oct 2026 21:56:15 +0200 Subject: [PATCH] Release automatically when package.json version changes Build and release now run in one workflow on push to main: after the build passes, if no tag exists for the package.json version, the image is pushed and the tag and Gitea release are created. Running them in sequence avoids the action-cache race between the separate build and tag-triggered release workflows. --- .gitea/workflows/build.yaml | 77 ++++++++++++++++++++++++- .gitea/workflows/old_gitea-release.yaml | 32 ---------- .gitea/workflows/release.yaml | 51 ---------------- 3 files changed, 76 insertions(+), 84 deletions(-) delete mode 100644 .gitea/workflows/old_gitea-release.yaml delete mode 100644 .gitea/workflows/release.yaml diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index a14894c..73bd68d 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -1,4 +1,10 @@ -name: Build and Test +name: Build and Release + +# Releases are driven by the version in package.json: bump it (e.g. +# `npm version patch --no-git-tag-version`) and push to main. If no tag +# v exists yet, the release job pushes the Docker image and creates +# the tag and Gitea release. Build and release run in sequence in one +# workflow, so they never race for the runner's action cache. on: push: @@ -31,3 +37,72 @@ jobs: push: false cache-from: type=gha cache-to: type=gha,mode=max + + release: + needs: build + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + steps: + - uses: https://github.com/actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + + - name: Check version + id: version + run: | + VERSION="v$(node -p "require('./package.json').version")" + echo "tag=$VERSION" >> "$GITHUB_OUTPUT" + if git rev-parse -q --verify "refs/tags/$VERSION" >/dev/null; then + echo "$VERSION already released, nothing to do" + echo "release=false" >> "$GITHUB_OUTPUT" + else + echo "Releasing $VERSION" + echo "release=true" >> "$GITHUB_OUTPUT" + fi + + - name: Set up QEMU + if: steps.version.outputs.release == 'true' + uses: https://github.com/docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + if: steps.version.outputs.release == 'true' + uses: https://github.com/docker/setup-buildx-action@v3 + with: + config-inline: | + [registry."gitea.sanplex.xyz/sansan"] + http = true + insecure = true + + - name: Login to Gitea Container Registry + if: steps.version.outputs.release == 'true' + uses: docker/login-action@v3 + with: + registry: gitea.sanplex.xyz + username: sansan + password: ${{ secrets.TOKEN }} + + - name: Build and push multi-arch image + if: steps.version.outputs.release == 'true' + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: | + gitea.sanplex.xyz/sansan/musicfrontend:${{ steps.version.outputs.tag }} + gitea.sanplex.xyz/sansan/musicfrontend:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Create Release + if: steps.version.outputs.release == 'true' + uses: akkuman/gitea-release-action@v1 + env: + NODE_OPTIONS: '--experimental-fetch' # if nodejs < 18 + with: + tag_name: ${{ steps.version.outputs.tag }} + target_commitish: ${{ github.sha }} + body: | + Docker image: `gitea.sanplex.xyz/sansan/musicfrontend:${{ steps.version.outputs.tag }}` diff --git a/.gitea/workflows/old_gitea-release.yaml b/.gitea/workflows/old_gitea-release.yaml deleted file mode 100644 index 687d91b..0000000 --- a/.gitea/workflows/old_gitea-release.yaml +++ /dev/null @@ -1,32 +0,0 @@ -name: Publish - -on: - push: - branches: - - '*.*' - -jobs: - publish: - runs-on: ubuntu-latest - steps: - - uses: https://github.com/actions/checkout@v4 - - name: Set up Docker Buildx - uses: https://github.com/docker/setup-buildx-action@v3 - with: - config-inline: | - [registry."gitea.sanplex.xyz/sansan"] - http = true - insecure = true - - name: Login to Gitea - uses: docker/login-action@v2 - with: - registry: gitea.sanplex.xyz - username: ${{ github.repository_owner }} - password: ${{ secrets.TOKEN }} - - name: Build and push Docker image - uses: https://github.com/docker/build-push-action@v5 - with: - context: . - file: ./Dockerfile - push: true - tags: "gitea.sanplex.xyz/sansan/musicfrontend:${{gitea.ref_name}}, gitea.sanplex.xyz/sansan/musicfrontend:latest" diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml deleted file mode 100644 index ec0f78b..0000000 --- a/.gitea/workflows/release.yaml +++ /dev/null @@ -1,51 +0,0 @@ -name: Release Docker Image - -on: - push: - tags: - - 'v*' - -jobs: - build-and-push: - runs-on: ubuntu-latest - steps: - - uses: https://github.com/actions/checkout@v4 - - - name: Set up QEMU - uses: https://github.com/docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: https://github.com/docker/setup-buildx-action@v3 - with: - config-inline: | - [registry."gitea.sanplex.xyz/sansan"] - http = true - insecure = true - - - name: Login to Gitea Container Registry - uses: docker/login-action@v3 - with: - registry: gitea.sanplex.xyz - username: sansan - password: ${{ secrets.TOKEN }} - - - name: Build and push multi-arch image - uses: docker/build-push-action@v5 - with: - context: . - file: ./Dockerfile - platforms: linux/amd64,linux/arm64 - push: true - tags: | - gitea.sanplex.xyz/sansan/musicfrontend:${{ gitea.ref_name }} - gitea.sanplex.xyz/sansan/musicfrontend:latest - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Create Release - uses: akkuman/gitea-release-action@v1 - env: - NODE_OPTIONS: '--experimental-fetch' # if nodejs < 18 - with: - body: | - Docker image: `gitea.sanplex.xyz/sansan/musicfrontend:${{ gitea.ref_name }}`