feat: add faster cache refresh #30
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 (Auto-tag + Push Docker) | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| workflow_dispatch: {} | |
| env: | |
| REGISTRY: docker.io | |
| IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/gabs-redis-langcache | |
| DOCKERFILE: ./Dockerfile | |
| # Needed so GITHUB_TOKEN can create tags | |
| permissions: | |
| contents: write | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| new_tag: ${{ steps.bump.outputs.new_tag }} | |
| steps: | |
| - name: Checkout (full history) | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Determine version bump from commit message | |
| id: bump | |
| shell: bash | |
| run: | | |
| set -e | |
| # Get the last tag | |
| LAST=$(git tag -l 'v*.*.*' --sort=-v:refname | head -n1) | |
| [ -z "$LAST" ] && LAST="v0.0.0" | |
| # Parse version | |
| VER=${LAST#v} | |
| IFS='.' read -r MAJOR MINOR PATCH <<<"$VER" | |
| # Get commit message | |
| COMMIT_MSG="${{ github.event.head_commit.message }}" | |
| echo "Commit message: $COMMIT_MSG" | |
| # Determine bump type from conventional commit | |
| if echo "$COMMIT_MSG" | grep -qiE '^(feat|feature)(\(.*\))?!:|^BREAKING CHANGE:'; then | |
| # Breaking change -> major bump | |
| MAJOR=$((MAJOR+1)) | |
| MINOR=0 | |
| PATCH=0 | |
| BUMP_TYPE="major" | |
| elif echo "$COMMIT_MSG" | grep -qiE '^(feat|feature)(\(.*\))?:'; then | |
| # Feature -> minor bump | |
| MINOR=$((MINOR+1)) | |
| PATCH=0 | |
| BUMP_TYPE="minor" | |
| else | |
| # Everything else (fix, chore, docs, etc.) -> patch bump | |
| PATCH=$((PATCH+1)) | |
| BUMP_TYPE="patch" | |
| fi | |
| NEW_TAG="v$MAJOR.$MINOR.$PATCH" | |
| echo "Last tag: $LAST" | |
| echo "Bump type: $BUMP_TYPE" | |
| echo "New tag: $NEW_TAG" | |
| # Export for next steps | |
| echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT | |
| echo "version=$MAJOR.$MINOR.$PATCH" >> $GITHUB_OUTPUT | |
| echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT | |
| - name: Create and push tag | |
| shell: bash | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag -a "${{ steps.bump.outputs.new_tag }}" -m "release ${{ steps.bump.outputs.new_tag }} (${{ steps.bump.outputs.bump_type }} bump)" | |
| git push origin "${{ steps.bump.outputs.new_tag }}" | |
| - 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: Build & Push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ${{ env.DOCKERFILE }} | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| tags: | | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.bump.outputs.version }} | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest | |
| labels: | | |
| org.opencontainers.image.title=${{ github.event.repository.name }} | |
| org.opencontainers.image.source=${{ github.repository }} | |
| org.opencontainers.image.revision=${{ github.sha }} | |
| org.opencontainers.image.version=${{ steps.bump.outputs.version }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| provenance: false | |
| - name: Summary | |
| run: | | |
| echo "## 🚀 Release Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Version**: ${{ steps.bump.outputs.new_tag }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Bump Type**: ${{ steps.bump.outputs.bump_type }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Docker Image**: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.bump.outputs.version }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Commit**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY |