Refactor Docker workflow to enhance GitVersion integration and improv… #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
| name: Build and push | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| env: | |
| CONTEXT_DIR: Sources | |
| DOCKERFILE: Dockerfile | |
| DOCKER_NAMESPACE: bvdcode # поменяй при необходимости | |
| DOCKER_IMAGE_NAME: mattermost-real-retention | |
| jobs: | |
| push_to_registry: | |
| name: push docker image to hub | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| packages: write | |
| steps: | |
| - name: Checkout (full history + tags) | |
| uses: actions/checkout@v4 | |
| with: | |
| lfs: true | |
| fetch-depth: 0 # <-- убираем shallow | |
| fetch-tags: true # <-- тянем теги, GitVersion без них бесполезен | |
| - name: Install GitVersion | |
| uses: gittools/actions/gitversion/setup@v3.1.11 | |
| with: | |
| versionSpec: 5.x | |
| - name: Determine Version | |
| id: gitversion | |
| uses: gittools/actions/gitversion/execute@v3.1.11 | |
| - name: Display GitVersion outputs | |
| run: | | |
| echo "SemVer: ${{ steps.gitversion.outputs.SemVer }}" | |
| echo "CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}" | |
| echo "Major.Minor: v${{ steps.gitversion.outputs.Major }}.${{ steps.gitversion.outputs.Minor }}" | |
| - name: Compose tags | |
| id: tags | |
| shell: bash | |
| run: | | |
| V_MINOR="v${{ steps.gitversion.outputs.Major }}.${{ steps.gitversion.outputs.Minor }}" | |
| echo "minor_tag=$V_MINOR" >> "$GITHUB_OUTPUT" | |
| echo "docker_tag=${{ env.DOCKER_NAMESPACE }}/${{ env.DOCKER_IMAGE_NAME }}:$V_MINOR" >> "$GITHUB_OUTPUT" | |
| echo "docker_tag_latest=${{ env.DOCKER_NAMESPACE }}/${{ env.DOCKER_IMAGE_NAME }}:latest" >> "$GITHUB_OUTPUT" | |
| # ghcr (опционально). Если нужно строго lower-case, раскомментируй нижнюю строку и задай OWNER вручную | |
| echo "ghcr_tag=ghcr.io/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:$V_MINOR" >> "$GITHUB_OUTPUT" | |
| echo "ghcr_tag_latest=ghcr.io/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:latest" >> "$GITHUB_OUTPUT" | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build & push to Docker Hub (vX.Y + latest) | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ${{ env.CONTEXT_DIR }} | |
| file: ${{ env.CONTEXT_DIR }}/${{ env.DOCKERFILE }} | |
| push: true | |
| tags: | | |
| ${{ steps.tags.outputs.docker_tag }} | |
| ${{ steps.tags.outputs.docker_tag_latest }} | |
| - name: Login to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build & push to GHCR (vX.Y + latest) | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ${{ env.CONTEXT_DIR }} | |
| file: ${{ env.CONTEXT_DIR }}/${{ env.DOCKERFILE }} | |
| push: true | |
| tags: | | |
| ${{ steps.tags.outputs.ghcr_tag }} | |
| ${{ steps.tags.outputs.ghcr_tag_latest }} | |
| - name: Create GitHub Release (only if version advanced) | |
| if: ${{ steps.gitversion.outputs.CommitsSinceVersionSource > 0 }} | |
| uses: ncipollo/release-action@v1 | |
| with: | |
| tag: ${{ steps.tags.outputs.minor_tag }} # vX.Y | |
| name: Release ${{ steps.tags.outputs.minor_tag }} | |
| draft: false | |
| prerelease: false | |
| token: ${{ secrets.DEPLOY_GITHUB_TOKEN }} |