Update ci.yml #5
Workflow file for this run
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 (Build & Push Docker, Update Release) | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| tags: [ "v*.*.*" ] | |
| workflow_dispatch: {} | |
| env: | |
| REGISTRY: docker.io | |
| IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/gabs-redis-langcache # ajuste se necessário | |
| DOCKERFILE: ./Dockerfile | |
| jobs: | |
| build-and-push: | |
| name: Build & Push to Docker Hub | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # para criar/atualizar Release em tags | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker 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 }} | |
| # IMPORTANTE: garante que nenhum DOCKER_CONTEXT indesejado atrapalhe | |
| - name: Sanitize Docker context env | |
| run: echo "DOCKER_CONTEXT=" >> $GITHUB_ENV | |
| - name: Extract Docker metadata (tags & labels) | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=sha | |
| type=ref,event=branch | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| 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 | |
| id: build | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . # <- use o path aqui, não em env | |
| file: ${{ env.DOCKERFILE }} | |
| push: true | |
| labels: ${{ steps.meta.outputs.labels }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| provenance: false | |
| # Só em tags tipo v1.2.3: cria/atualiza Release | |
| - name: Compose release notes | |
| if: startsWith(github.ref, 'refs/tags/') | |
| id: notes | |
| run: | | |
| TAG="${GITHUB_REF#refs/tags/}" | |
| DIGEST="${{ steps.build.outputs.digest }}" | |
| { | |
| echo "## 🐳 Docker Image" | |
| echo "" | |
| echo "- Registry: \`${{ env.REGISTRY }}\`" | |
| echo "- Image: \`${{ env.IMAGE_NAME }}\`" | |
| echo "- Tags publicados:" | |
| echo '${{ steps.meta.outputs.tags }}' | tr ' ' '\n' | sed 's/^/- /' | |
| echo "" | |
| echo "### Digest" | |
| echo "\`${DIGEST}\`" | |
| echo "" | |
| echo "### Commit" | |
| echo "\`${GITHUB_SHA}\`" | |
| } > release-notes.md | |
| cat release-notes.md | |
| - name: Create/Update GitHub Release | |
| if: startsWith(github.ref, 'refs/tags/') | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: release-notes.md | |
| body_path: release-notes.md | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |