feat: new cache tweak #release #27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI (Auto-tag + Build & Push Docker on SemVer) | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| tags: [ "v*.*.*", "*.*.*" ] | |
| workflow_dispatch: {} | |
| env: | |
| REGISTRY: docker.io | |
| IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/gabs-redis-langcache | |
| DOCKERFILE: ./Dockerfile | |
| permissions: | |
| contents: write # <-- gives GITHUB_TOKEN push access to create tags | |
| jobs: | |
| # 1️⃣ main branch: bump + tag if '#release' present | |
| auto-release: | |
| if: ${{ github.ref == 'refs/heads/main' && contains(join(github.event.commits.*.message, ' '), '#release') }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Bump patch version and create tag | |
| run: | | |
| set -e | |
| LAST=$(git tag -l 'v*' --sort=-v:refname | head -n1) | |
| [ -z "$LAST" ] && LAST="v0.0.0" | |
| VER=${LAST#v} | |
| IFS='.' read -r MA MI PA <<<"$VER" | |
| NEW_TAG="v$MA.$MI.$((PA+1))" | |
| echo "Creating $NEW_TAG" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag -a "$NEW_TAG" -m "release $NEW_TAG" | |
| git push origin "$NEW_TAG" | |
| # 2️⃣ tag events: build + push ONLY semver tags | |
| build-and-push: | |
| if: startsWith(github.ref, 'refs/tags/') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: docker/setup-qemu-action@v3 | |
| - uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Extract Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=semver,pattern={{version}} | |
| labels: | | |
| org.opencontainers.image.title=${{ github.event.repository.name }} | |
| org.opencontainers.image.source=${{ github.repository }} | |
| org.opencontainers.image.revision=${{ github.sha }} | |
| - name: Build & Push SemVer image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ${{ env.DOCKERFILE }} | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| provenance: false |