Release mit semantischer Versionierung #7
This file contains hidden or 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
name: Release mit semantischer Versionierung | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Version (major.minor.patch)' | |
required: true | |
default: '' | |
release_type: | |
description: 'Release-Typ' | |
required: true | |
type: choice | |
options: | |
- patch | |
- minor | |
- major | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write # Für Tag und Release | |
packages: write # Für ghcr.io Push | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Setze Kleinbuchstaben-Image-Namen | |
id: lowercase | |
run: | | |
echo "IMAGE_NAME=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV | |
- name: Bestimme neue Version | |
id: version | |
run: | | |
if [[ -n "${{ github.event.inputs.version }}" ]]; then | |
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT | |
else | |
# Letzten Tag holen | |
git fetch --tags | |
CURRENT_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") | |
CURRENT_VERSION=${CURRENT_VERSION#v} | |
# Version aufteilen | |
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" | |
case "${{ github.event.inputs.release_type }}" in | |
major) | |
MAJOR=$((MAJOR + 1)) | |
MINOR=0 | |
PATCH=0 | |
;; | |
minor) | |
MINOR=$((MINOR + 1)) | |
PATCH=0 | |
;; | |
patch) | |
PATCH=$((PATCH + 1)) | |
;; | |
esac | |
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}" | |
echo "VERSION=${NEW_VERSION}" >> $GITHUB_OUTPUT | |
fi | |
- name: GHCR Login | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build und Push Docker Image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
tags: | | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }} | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest | |
- name: Erstelle und pushe Git-Tag | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git tag -a "v${{ steps.version.outputs.VERSION }}" -m "Release v${{ steps.version.outputs.VERSION }}" | |
git push origin "v${{ steps.version.outputs.VERSION }}" | |
- name: Erstelle GitHub Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: "v${{ steps.version.outputs.VERSION }}" | |
name: "Release v${{ steps.version.outputs.VERSION }}" | |
draft: false | |
prerelease: false | |
generate_release_notes: true |