From 9abdde26025c7020bcf291061548b8a6b8e725c6 Mon Sep 17 00:00:00 2001 From: "aditya.chandel" <> Date: Tue, 11 Mar 2025 18:54:26 -0600 Subject: [PATCH] Test GitHub Actions workflow --- .github/workflows/docker-build-publish.yml | 55 +++++++++++++++++++--- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker-build-publish.yml b/.github/workflows/docker-build-publish.yml index 168cf2ba2..573577bc9 100644 --- a/.github/workflows/docker-build-publish.yml +++ b/.github/workflows/docker-build-publish.yml @@ -1,31 +1,74 @@ -name: Build and Push to GitHub Container Registry +name: Build, Tag, and Push to GitHub Container Registry on: push: branches: + - develop - master - release: - types: [published] jobs: build-and-push: runs-on: ubuntu-latest permissions: - contents: read + contents: write packages: write steps: - name: Checkout Repository uses: actions/checkout@v4 + with: + fetch-depth: 0 # Ensures full history for tagging - name: Log in to GitHub Container Registry run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + - name: Get Latest Tag + id: get_version + run: | + branch="${GITHUB_REF#refs/heads/}" + if [[ "$branch" == "master" ]]; then + latest_tag=$(git tag --list "v*" --sort=-v:refname | head -n 1) + else + latest_tag=$(git tag --list "develop-v*" --sort=-v:refname | head -n 1) + fi + latest_tag=${latest_tag:-"v0.0.0"} + echo "latest_tag=$latest_tag" >> $GITHUB_ENV + echo "Latest tag: $latest_tag" + + - name: Auto-Increment Version + id: bump_version + run: | + old_version=${{ env.latest_tag }} + IFS='.' read -r -a parts <<< "${old_version//[!0-9.]/}" + new_version="${parts[0]}.${parts[1]}.$((parts[2] + 1))" + + branch="${GITHUB_REF#refs/heads/}" + if [[ "$branch" == "master" ]]; then + new_tag="v${new_version}" + else + new_tag="develop-v${new_version}" + fi + + echo "new_tag=$new_tag" >> $GITHUB_ENV + echo "New version: $new_tag" + + - name: Create Git Tag + run: | + git config --global user.name "github-actions" + git config --global user.email "github-actions@github.com" + git tag ${{ env.new_tag }} + git push origin ${{ env.new_tag }} + + - name: Determine Docker Image Tag + id: docker_tag + run: | + echo "tag=${{ env.new_tag }}" >> $GITHUB_ENV + - name: Build Docker Image run: | - docker build -t ghcr.io/${{ github.actor }}/booklore-app:latest . + docker build -t ghcr.io/${{ github.actor }}/booklore-app:${{ env.tag }} . - name: Push Docker Image to GHCR run: | - docker push ghcr.io/${{ github.actor }}/booklore-app:latest \ No newline at end of file + docker push ghcr.io/${{ github.actor }}/booklore-app:${{ env.tag }} \ No newline at end of file