-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
efe8312
commit d0d9d76
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
name: Release and Publish Docker Image | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
description: "Version to release (optional, defaults to patch increment)" | ||
required: false | ||
default: "" | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# Checkout the repository | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
# Fetch all tags | ||
- name: Fetch tags | ||
run: git fetch --tags | ||
|
||
# Determine the next version | ||
- name: Determine release version | ||
id: determine_version | ||
run: | | ||
# Get the input version | ||
INPUT_VERSION="${{ github.event.inputs.version }}" | ||
# Find the latest tag | ||
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0") | ||
# If an input version is provided, use it | ||
if [[ -n "$INPUT_VERSION" ]]; then | ||
NEW_VERSION="$INPUT_VERSION" | ||
else | ||
# Increment the patch version by default | ||
IFS='.' read -r MAJOR MINOR PATCH <<< "$LATEST_TAG" | ||
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))" | ||
fi | ||
# If no releases exist, default to 0.1.0 | ||
if [[ "$LATEST_TAG" == "0.0.0" ]]; then | ||
NEW_VERSION="0.1.0" | ||
fi | ||
echo "New version: $NEW_VERSION" | ||
echo "::set-output name=version::$NEW_VERSION" | ||
# Create a GitHub release | ||
- name: Create GitHub Release | ||
uses: softprops/action-gh-release@v2 | ||
with: | ||
tag_name: ${{ steps.determine_version.outputs.version }} | ||
name: Release ${{ steps.determine_version.outputs.version }} | ||
body: | | ||
Automatically generated release ${{ steps.determine_version.outputs.version }}. | ||
draft: false | ||
prerelease: false | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Log in to GitHub Docker Registry | ||
- name: Log in to GitHub Docker Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Build and push Docker image | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
push: true | ||
tags: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ steps.determine_version.outputs.version }} |