|
| 1 | +name: CI (Build & Push Docker, Update Release) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "main" ] |
| 6 | + tags: [ "v*.*.*" ] |
| 7 | + workflow_dispatch: {} |
| 8 | + |
| 9 | +env: |
| 10 | + REGISTRY: docker.io |
| 11 | + IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/gabs-redis-langcache # ajuste se o repositório no Docker Hub tiver outro nome |
| 12 | + DOCKER_CONTEXT: . |
| 13 | + DOCKERFILE: ./Dockerfile |
| 14 | + |
| 15 | +jobs: |
| 16 | + build-and-push: |
| 17 | + name: Build & Push to Docker Hub |
| 18 | + runs-on: ubuntu-latest |
| 19 | + permissions: |
| 20 | + contents: write # necessário para atualizar/ criar Release em tags |
| 21 | + steps: |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Set up Docker Buildx |
| 26 | + uses: docker/setup-buildx-action@v3 |
| 27 | + |
| 28 | + - name: Log in to Docker Hub |
| 29 | + uses: docker/login-action@v3 |
| 30 | + with: |
| 31 | + registry: ${{ env.REGISTRY }} |
| 32 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 33 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 34 | + |
| 35 | + - name: Extract Docker metadata (tags & labels) |
| 36 | + id: meta |
| 37 | + uses: docker/metadata-action@v5 |
| 38 | + with: |
| 39 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 40 | + tags: | |
| 41 | + type=sha |
| 42 | + type=ref,event=branch |
| 43 | + type=raw,value=latest,enable={{is_default_branch}} |
| 44 | + type=semver,pattern={{version}} |
| 45 | + labels: | |
| 46 | + org.opencontainers.image.title=${{ github.event.repository.name }} |
| 47 | + org.opencontainers.image.source=${{ github.repository }} |
| 48 | + org.opencontainers.image.revision=${{ github.sha }} |
| 49 | +
|
| 50 | + - name: Build & Push |
| 51 | + id: build |
| 52 | + uses: docker/build-push-action@v6 |
| 53 | + with: |
| 54 | + context: ${{ env.DOCKER_CONTEXT }} |
| 55 | + file: ${{ env.DOCKERFILE }} |
| 56 | + push: true |
| 57 | + labels: ${{ steps.meta.outputs.labels }} |
| 58 | + tags: ${{ steps.meta.outputs.tags }} |
| 59 | + cache-from: type=gha |
| 60 | + cache-to: type=gha,mode=max |
| 61 | + provenance: false |
| 62 | + |
| 63 | + # Somente em tags (ex.: v1.2.3), cria/atualiza a Release do GitHub com notas automáticas |
| 64 | + - name: Compose release notes |
| 65 | + if: startsWith(github.ref, 'refs/tags/') |
| 66 | + id: notes |
| 67 | + run: | |
| 68 | + TAG="${GITHUB_REF#refs/tags/}" |
| 69 | + DIGEST="${{ steps.build.outputs.digest }}" |
| 70 | + { |
| 71 | + echo "## 🐳 Docker Image" |
| 72 | + echo "" |
| 73 | + echo "- Registry: \`${{ env.REGISTRY }}\`" |
| 74 | + echo "- Image: \`${{ env.IMAGE_NAME }}\`" |
| 75 | + echo "- Tags publicados:" |
| 76 | + # Mostra as tags resolvidas pelo metadata-action |
| 77 | + echo '${{ steps.meta.outputs.tags }}' | tr ' ' '\n' | sed 's/^/- /' |
| 78 | + echo "" |
| 79 | + echo "### Digest" |
| 80 | + echo "\`${DIGEST}\`" |
| 81 | + echo "" |
| 82 | + echo "### Commit" |
| 83 | + echo "\`${GITHUB_SHA}\`" |
| 84 | + } > release-notes.md |
| 85 | + cat release-notes.md |
| 86 | +
|
| 87 | + - name: Create/Update GitHub Release |
| 88 | + if: startsWith(github.ref, 'refs/tags/') |
| 89 | + uses: softprops/action-gh-release@v2 |
| 90 | + with: |
| 91 | + files: | |
| 92 | + release-notes.md |
| 93 | + body_path: release-notes.md |
| 94 | + generate_release_notes: true |
| 95 | + env: |
| 96 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments