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 }}`