diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml index b1f9bc5..1ffdef0 100644 --- a/.forgejo/workflows/build.yml +++ b/.forgejo/workflows/build.yml @@ -1,19 +1,20 @@ -# Runs only on pushes to main. -# Builds the Docker image and pushes it to the Forgejo container registry. -# Registry-side layer caching means unchanged layers (npm install, pip install) -# are reused between builds — typically cuts build time from ~4 min to ~45 sec. +# Runs on pushes to main and on version tags (v*). # -# The resulting image can then be deployed manually via Portainer. +# Branch push (main): builds and pushes :latest + : +# Tag push (v1.2.0): builds and pushes :latest + : + :v1.2.0 +# +# To cut a versioned release: +# git tag v1.2.0 && git push origin v1.2.0 # # Required secrets (repo → Settings → Secrets → Actions): # REGISTRY_USER — your Forgejo username -# REGISTRY_TOKEN — Forgejo PAT with write:packages scope (create at -# git.fabledsword.com → Settings → Applications → Generate Token) +# REGISTRY_TOKEN — Forgejo PAT with write:packages scope name: Build & push image on: push: branches: [main] + tags: ["v*"] paths: - "src/**" - "frontend/**" @@ -34,6 +35,16 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Generate image tags + id: tags + run: | + TAGS="${{ env.IMAGE }}:latest,${{ env.IMAGE }}:${{ github.sha }}" + if [[ "${{ github.ref }}" == refs/tags/* ]]; then + TAGS="$TAGS,${{ env.IMAGE }}:${{ github.ref_name }}" + echo "Releasing version ${{ github.ref_name }}" + fi + echo "value=$TAGS" >> $GITHUB_OUTPUT + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -49,8 +60,6 @@ jobs: with: context: . push: true - tags: | - ${{ env.IMAGE }}:latest - ${{ env.IMAGE }}:${{ github.sha }} + tags: ${{ steps.tags.outputs.value }} cache-from: type=registry,ref=${{ env.IMAGE }}:cache cache-to: type=registry,ref=${{ env.IMAGE }}:cache,mode=max