Skip to content

Create Release

Create Release #3

name: Create Release
on:
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g., 1.2.3)'
required: true
type: string
prerelease:
description: 'Mark as pre-release'
required: false
default: false
type: boolean
update-major-tag:
description: 'Update major version tag (e.g., 1)'
required: false
default: true
type: boolean
jobs:
validate:
name: Validate Release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.validate.outputs.version }}
version-tag: ${{ steps.validate.outputs.version-tag }}
major-version: ${{ steps.validate.outputs.major-version }}
minor-version: ${{ steps.validate.outputs.minor-version }}
steps:
- name: Validate version format
id: validate
run: |
VERSION="${{ github.event.inputs.version }}"
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Invalid version format. Use 'X.Y.Z'."
exit 1
fi
# Extract version components
MAJOR=$(echo "$VERSION" | cut -d. -f1)
MINOR=$(echo "$VERSION" | cut -d. -f2)
MAJOR_TAG="$MAJOR"
MINOR_TAG="$MAJOR.$MINOR"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "version-tag=$VERSION" >> $GITHUB_OUTPUT
echo "major-version=$MAJOR_TAG" >> $GITHUB_OUTPUT
echo "minor-version=$MINOR_TAG" >> $GITHUB_OUTPUT
- name: Check if tag already exists
run: |
if git ls-remote --tags origin | grep -q "refs/tags/${{ steps.validate.outputs.version-tag }}$"; then
echo "::error::Tag ${{ steps.validate.outputs.version-tag }} already exists"
exit 1
fi
run-tests:
name: Run Tests
runs-on: ubuntu-latest
needs: validate
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run Pipelines
id: run-tests
run: |
sh ./tests/run-all.sh
release:
name: Create Release
runs-on: ubuntu-latest
needs: [validate, run-tests]
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure git
run: |
git config --local user.name "ae-actions-runner"
git config --local user.email "ae-actions-runner@metaeffekt.com"
- name: Commit version updates
run: |
VERSION="${{ needs.validate.outputs.version }}"
VERSION_TAG="${{ needs.validate.outputs.version-tag }}"
git add -A
if ! git diff --staged --quiet; then
git commit -m "Release $VERSION: Update action references from @main to @$VERSION_TAG"
echo "Changes committed"
else
echo "No changes to commit"
fi
- name: Create and push release tag
run: |
VERSION="${{ needs.validate.outputs.version }}"
VERSION_TAG="${{ needs.validate.outputs.version-tag }}"
git tag -a "$VERSION_TAG" -m "Release $VERSION"
git push origin "$VERSION_TAG"
echo "Created and pushed tag: $VERSION_TAG"
- name: Update major and minor version tags
if: github.event.inputs.update-major-tag == 'true'
run: |
VERSION="${{ needs.validate.outputs.version }}"
MAJOR_VERSION="${{ needs.validate.outputs.major-version }}"
MINOR_VERSION="${{ needs.validate.outputs.minor-version }}"
git tag -f "$MAJOR_VERSION"
git push origin "$MAJOR_VERSION" --force
git tag -f "$MINOR_VERSION"
git push origin "$MINOR_VERSION" --force
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.validate.outputs.version-tag }}
release_name: ${{ needs.validate.outputs.version }}
draft: false
prerelease: ${{ github.event.inputs.prerelease }}