feat: new cache optimization #release #25
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
| # .github/workflows/ci.yml | |
| name: CI (Build & Push Docker + Auto Release) | |
| 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 # required to create and push tags | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Buildx | |
| 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: Sanitize Docker context env | |
| run: echo "DOCKER_CONTEXT=" >> $GITHUB_ENV | |
| - name: Extract Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| # 👇 Only push semver tags on tag events | |
| tags: | | |
| type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/') }} | |
| type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} | |
| type=ref,event=branch,enable=${{ github.ref == 'refs/heads/main' }} | |
| type=sha,enable=${{ github.ref == 'refs/heads/main' }} | |
| labels: | | |
| org.opencontainers.image.title=${{ github.event.repository.name }} | |
| org.opencontainers.image.source=${{ github.repository }} | |
| org.opencontainers.image.revision=${{ github.sha }} | |
| - name: Debug tags | |
| run: echo "→ ${{ steps.meta.outputs.tags }}" | |
| - name: Build & Push multi-arch | |
| 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 | |
| auto-release: | |
| needs: build-and-push | |
| # Fire only on main branch pushes containing '#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 | |
| id: bump | |
| 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" |