From 165cc3bdcae37a40c84ed0da692245f297d78654 Mon Sep 17 00:00:00 2001 From: Anshul Sharma Date: Sat, 12 Apr 2025 20:25:03 +0530 Subject: [PATCH 1/5] adding workflow --- .github/workflows/docker_build.yaml | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/docker_build.yaml diff --git a/.github/workflows/docker_build.yaml b/.github/workflows/docker_build.yaml new file mode 100644 index 000000000..8ed3d5447 --- /dev/null +++ b/.github/workflows/docker_build.yaml @@ -0,0 +1,43 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + - anshulss/* + +jobs: + build: + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Extract metadata (tags, labels) for Docker build + id: meta + uses: docker/metadata-action@v5 + with: + flavor: latest + from_path: ./surfsense_backend + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: ./surfsense_backend + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} From 3ded17d3255ae19a3888bb46cc03e3c3baa850c3 Mon Sep 17 00:00:00 2001 From: Anshul Sharma Date: Sat, 12 Apr 2025 20:39:15 +0530 Subject: [PATCH 2/5] updated tags --- .github/workflows/docker_build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker_build.yaml b/.github/workflows/docker_build.yaml index 8ed3d5447..3300041c1 100644 --- a/.github/workflows/docker_build.yaml +++ b/.github/workflows/docker_build.yaml @@ -31,8 +31,8 @@ jobs: id: meta uses: docker/metadata-action@v5 with: - flavor: latest - from_path: ./surfsense_backend + tags: | + type=semver,pattern={{major}}.{{minor}} - name: Build and push Docker image uses: docker/build-push-action@v5 From 4e36cb44e7d291bd3dcfe1e76f63ffa73e55b00e Mon Sep 17 00:00:00 2001 From: Anshul Sharma Date: Sat, 12 Apr 2025 20:45:41 +0530 Subject: [PATCH 3/5] Updated versioning --- .github/workflows/docker_build.yaml | 3 ++- VERSION | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 VERSION diff --git a/.github/workflows/docker_build.yaml b/.github/workflows/docker_build.yaml index 3300041c1..5dce26ceb 100644 --- a/.github/workflows/docker_build.yaml +++ b/.github/workflows/docker_build.yaml @@ -31,8 +31,9 @@ jobs: id: meta uses: docker/metadata-action@v5 with: + images: ghcr.io/${{ github.repository_owner }}/surfsense_backend tags: | - type=semver,pattern={{major}}.{{minor}} + type=raw,value=./surfsense_backend/VERSION - name: Build and push Docker image uses: docker/build-push-action@v5 diff --git a/VERSION b/VERSION new file mode 100644 index 000000000..8a9ecc2ea --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.1 \ No newline at end of file From 2b92c317bd2973eceb42f23d8177f0049967aecc Mon Sep 17 00:00:00 2001 From: Anshul Sharma Date: Sun, 13 Apr 2025 00:30:12 +0530 Subject: [PATCH 4/5] hardcoded version --- .github/workflows/docker_build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker_build.yaml b/.github/workflows/docker_build.yaml index 5dce26ceb..9b2ead72d 100644 --- a/.github/workflows/docker_build.yaml +++ b/.github/workflows/docker_build.yaml @@ -33,7 +33,7 @@ jobs: with: images: ghcr.io/${{ github.repository_owner }}/surfsense_backend tags: | - type=raw,value=./surfsense_backend/VERSION + type=raw,value=0.0.1 - name: Build and push Docker image uses: docker/build-push-action@v5 From 2aa876972432b5f98f32b3fbc496cdd4df74ca12 Mon Sep 17 00:00:00 2001 From: Anshul Sharma Date: Wed, 23 Apr 2025 20:47:30 +0530 Subject: [PATCH 5/5] added tagging for version --- .github/workflows/docker_build.yaml | 111 ++++++++++++++++++++++++++-- 1 file changed, 105 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker_build.yaml b/.github/workflows/docker_build.yaml index 9b2ead72d..c2cdf64b6 100644 --- a/.github/workflows/docker_build.yaml +++ b/.github/workflows/docker_build.yaml @@ -1,13 +1,112 @@ name: Build and Push Docker Image on: - push: - branches: - - main - - anshulss/* + workflow_dispatch: + inputs: + bump_type: + description: 'Version bump type (patch, minor, major)' + required: true + default: 'patch' + type: choice + options: + - patch + - minor + - major +permissions: + contents: write jobs: - build: + tag_release: + needs: tag_release + runs-on: ubuntu-latest + env: + IMAGE_TAG: ${{ needs.tag_release.outputs.new_tag }} + outputs: + # Define output to pass the tag to the next job + new_tag: ${{ steps.tag_version.outputs.next_version }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + # Fetch all history and tags to find the latest SemVer tag + fetch-depth: 0 + # Checkout the specific branch if provided, otherwise default + ref: ${{ github.event.inputs.branch }} + + - name: Get latest SemVer tag and calculate next version + id: tag_version + run: | + # Fetch all tags from remote just in case + git fetch --tags + + # Get the latest SemVer tag (handles vX.Y.Z pattern) + # Filters tags, sorts them version-aware, takes the last one + LATEST_TAG=$(git tag --list 'v[0-9]*.[0-9]*.[0-9]*' --sort='v:refname' | tail -n 1) + + if [ -z "$LATEST_TAG" ]; then + echo "No previous SemVer tag found. Starting with v0.1.0" + NEXT_VERSION="v0.1.0" + # Optionally adjust starting version based on bump_type, but v0.1.0 is common start + if [ "${{ github.event.inputs.bump_type }}" == "minor" ]; then + NEXT_VERSION="v0.1.0" # Or maybe v0.1.0 ? Depends on convention + elif [ "${{ github.event.inputs.bump_type }}" == "major" ]; then + NEXT_VERSION="v1.0.0" # Or maybe v1.0.0 ? Depends on convention + fi + else + echo "Latest tag found: $LATEST_TAG" + # Remove 'v' prefix for calculation + VERSION=${LATEST_TAG#v} + + # Split into parts + MAJOR=$(echo $VERSION | cut -d. -f1) + MINOR=$(echo $VERSION | cut -d. -f2) + PATCH=$(echo $VERSION | cut -d. -f3) + + # Bump version based on input + case "${{ github.event.inputs.bump_type }}" in + patch) + PATCH=$((PATCH + 1)) + ;; + minor) + MINOR=$((MINOR + 1)) + PATCH=0 + ;; + major) + MAJOR=$((MAJOR + 1)) + MINOR=0 + PATCH=0 + ;; + *) + echo "Invalid bump type: ${{ github.event.inputs.bump_type }}" + exit 1 + ;; + esac + NEXT_VERSION="v${MAJOR}.${MINOR}.${PATCH}" + fi + + echo "Calculated next version: $NEXT_VERSION" + # Set output for subsequent steps + echo "next_version=$NEXT_VERSION" >> $GITHUB_OUTPUT + + - name: Create and Push Tag + run: | + NEXT_TAG="${{ steps.tag_version.outputs.next_version }}" + COMMIT_SHA=$(git rev-parse HEAD) + echo "Tagging commit $COMMIT_SHA with $NEXT_TAG" + + # Create an annotated tag (recommended) + git tag -a "$NEXT_TAG" -m "Release $NEXT_TAG" + + # Push the tag to the remote repository + git push origin "$NEXT_TAG" + + - name: Verify Tag Push + run: | + echo "Checking if tag ${{ steps.tag_version.outputs.next_version }} exists remotely..." + git ls-remote --tags origin | grep "refs/tags/${{ steps.tag_version.outputs.next_version }}" || (echo "Tag push verification failed!" && exit 1) + echo "Tag successfully pushed." + + build__and_push_docker_image: runs-on: ubuntu-latest permissions: packages: write @@ -40,5 +139,5 @@ jobs: with: context: ./surfsense_backend push: true - tags: ${{ steps.meta.outputs.tags }} + tags: $IMAGE_TAG labels: ${{ steps.meta.outputs.labels }}