mirror of
https://github.com/MODSetter/SurfSense.git
synced 2025-09-02 18:49:09 +00:00
added tagging for version
This commit is contained in:
parent
2b92c317bd
commit
2aa8769724
1 changed files with 105 additions and 6 deletions
111
.github/workflows/docker_build.yaml
vendored
111
.github/workflows/docker_build.yaml
vendored
|
@ -1,13 +1,112 @@
|
||||||
name: Build and Push Docker Image
|
name: Build and Push Docker Image
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
workflow_dispatch:
|
||||||
branches:
|
inputs:
|
||||||
- main
|
bump_type:
|
||||||
- anshulss/*
|
description: 'Version bump type (patch, minor, major)'
|
||||||
|
required: true
|
||||||
|
default: 'patch'
|
||||||
|
type: choice
|
||||||
|
options:
|
||||||
|
- patch
|
||||||
|
- minor
|
||||||
|
- major
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
jobs:
|
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
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
packages: write
|
packages: write
|
||||||
|
@ -40,5 +139,5 @@ jobs:
|
||||||
with:
|
with:
|
||||||
context: ./surfsense_backend
|
context: ./surfsense_backend
|
||||||
push: true
|
push: true
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: $IMAGE_TAG
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|
Loading…
Add table
Reference in a new issue