Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions .github/workflows/manage-release-tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Manage Release Tags

on:
create:
schedule:
- cron: '0 8 * * 2' # Every Tuesday at 8 AM UTC
workflow_dispatch:

permissions:
contents: write

jobs:
create-tags:
name: Create Release Tags
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Handle initial release tag
if: github.event_name == 'create' && github.event.ref_type == 'branch'
run: |
BRANCH_NAME="${{ github.event.ref }}"

# Check if this is a release branch
if [[ ! "$BRANCH_NAME" =~ ^release-[0-9]+\.[0-9]+$ ]]; then
echo "Not a release branch, skipping"
exit 0
fi

# Extract version from branch name
VERSION=${BRANCH_NAME#release-}
TAG="v${VERSION}.0"

# Check if tag already exists
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists, skipping"
exit 0
fi

echo "Creating initial release tag $TAG for branch $BRANCH_NAME"
git tag "$TAG"
git push origin "$TAG"

- name: Handle patch release tags
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
run: |
# Find all release branches
RELEASE_BRANCHES=$(git branch -r | grep -E 'origin/release-[0-9]+\.[0-9]+$' | sed 's|origin/||' | sed 's/^[[:space:]]*//')

if [ -z "$RELEASE_BRANCHES" ]; then
echo "No release branches found"
exit 0
fi

echo "Found release branches:"
echo "$RELEASE_BRANCHES"

for BRANCH in $RELEASE_BRANCHES; do
echo "Processing branch: $BRANCH"

# Extract major.minor version from branch name
if [[ ! "$BRANCH" =~ ^release-([0-9]+\.[0-9]+)$ ]]; then
echo "Invalid branch name format: $BRANCH, skipping"
continue
fi

VERSION_PREFIX="${BASH_REMATCH[1]}"

# Find latest tag for this release branch
LATEST_TAG=$(git tag -l "v${VERSION_PREFIX}.*" | sort -V | tail -n1)

if [ -z "$LATEST_TAG" ]; then
# No tags exist for this branch, create v.X.Y.0
NEW_TAG="v${VERSION_PREFIX}.0"
echo "No existing tags for $BRANCH, creating initial tag $NEW_TAG"
else
# Check if there are commits since the last tag
git checkout "origin/$BRANCH" --quiet
COMMITS_SINCE_TAG=$(git rev-list "$LATEST_TAG..origin/$BRANCH" --count)

if [ "$COMMITS_SINCE_TAG" -eq 0 ]; then
echo "No new commits on $BRANCH since $LATEST_TAG, skipping"
continue
fi

echo "Found $COMMITS_SINCE_TAG commits since $LATEST_TAG"

# Extract and increment patch version
PATCH_VERSION=$(echo "$LATEST_TAG" | sed "s/v${VERSION_PREFIX}\.//" )
NEW_PATCH=$((PATCH_VERSION + 1))
NEW_TAG="v${VERSION_PREFIX}.${NEW_PATCH}"

echo "Creating new patch tag $NEW_TAG for $BRANCH"
fi

# Check if tag already exists
if git rev-parse "$NEW_TAG" >/dev/null 2>&1; then
echo "Tag $NEW_TAG already exists, skipping"
continue
fi

# Create and push the tag
git checkout "origin/$BRANCH" --quiet
git tag "$NEW_TAG"
git push origin "$NEW_TAG"

echo "Successfully created and pushed tag $NEW_TAG"
done
2 changes: 1 addition & 1 deletion .github/workflows/multiarch-build-and-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ jobs:
platforms: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:main
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version_tag }}
103 changes: 103 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Release Build and Publish

on:
push:
tags:
- 'v*.*.*'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-push-release:
name: Build and Push Release Image
runs-on: ubuntu-latest
permissions:
contents: write
packages: write

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Free up disk space
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache
df -h

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Parse version from tag
id: version
run: |
TAG=${GITHUB_REF#refs/tags/v}
echo "full=$TAG" >> $GITHUB_OUTPUT

MAJOR=$(echo $TAG | cut -d. -f1)
MINOR=$(echo $TAG | cut -d. -f2)
PATCH=$(echo $TAG | cut -d. -f3)

echo "major=$MAJOR" >> $GITHUB_OUTPUT
echo "minor=$MINOR" >> $GITHUB_OUTPUT
echo "patch=$PATCH" >> $GITHUB_OUTPUT
echo "major_minor=$MAJOR.$MINOR" >> $GITHUB_OUTPUT

# Check if this is the latest version
LATEST_TAG=$(git tag -l 'v*.*.*' | sort -V | tail -n1)
if [ "v$TAG" = "$LATEST_TAG" ]; then
echo "is_latest=true" >> $GITHUB_OUTPUT
else
echo "is_latest=false" >> $GITHUB_OUTPUT
fi

- name: Build and push image (latest version)
if: steps.version.outputs.is_latest == 'true'
uses: docker/build-push-action@v6
with:
context: .
target: prod
platforms: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.full }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.major_minor }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.major }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest

- name: Build and push image (none latest version)
if: steps.version.outputs.is_latest == 'false'
uses: docker/build-push-action@v6
with:
context: .
target: prod
platforms: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.full }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.major_minor }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.major }}

- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create ${{ github.ref_name }} \
--title "Release ${{ github.ref_name }}" \
--generate-notes