Files
semapform_api/.gitea/workflows/release.yml

172 lines
6.1 KiB
YAML

on:
workflow_dispatch:
inputs:
github_release:
description: "Create Gitea Release"
default: true
type: boolean
docker_release:
description: "Push Docker images"
default: true
type: boolean
bump:
description: "Bump type"
required: false
default: "patch"
type: choice
options:
- "major"
- "minor"
- "patch"
pull_request:
types: [closed]
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
# Only run on merged PRs with [release-*] or manual workflow_dispatch
if: |
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'pull_request' && github.event.pull_request.merged == true && contains(github.event.pull_request.title, '[release-'))
steps:
- name: Determine bump type
id: bump_type
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "type=${{ github.event.inputs.bump }}" >> $GITHUB_OUTPUT
else
# Extract bump type from PR title: [release-patch], [release-minor], [release-major]
PR_TITLE="${{ github.event.pull_request.title }}"
if [[ "$PR_TITLE" =~ \[release-major\] ]]; then
echo "type=major" >> $GITHUB_OUTPUT
elif [[ "$PR_TITLE" =~ \[release-minor\] ]]; then
echo "type=minor" >> $GITHUB_OUTPUT
elif [[ "$PR_TITLE" =~ \[release-patch\] ]]; then
echo "type=patch" >> $GITHUB_OUTPUT
else
echo "type=patch" >> $GITHUB_OUTPUT
fi
fi
- name: Checkout code
uses: actions/checkout@v4.2.2
with:
fetch-depth: 0 # Fetch full history
fetch-tags: true # Fetch all tags (refs/tags)
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Set up Python
run: uv python install
with:
python-version-file: "pyproject.toml"
- name: Install the project dependencies
run: |
uv sync --all-groups
uv add pip
uv export --format requirements.txt -o requirements.txt
# uv run python -m pip install --upgrade pip
# uv run python -m pip install -r requirements.txt
- name: Set Git identity
run: |
git config user.name "Gitea CI"
git config user.email "ci@git.theprivateserver.de"
- name: Determine branch to push to
id: push_branch
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
# workflow_dispatch runs on a branch ref like refs/heads/main
BRANCH=${GITHUB_REF#refs/heads/}
else
# for a merged PR use the PR base ref (target branch)
BRANCH=${{ github.event.pull_request.base.ref }}
fi
echo "PUSH_BRANCH=$BRANCH" >> $GITHUB_ENV
- name: Bump version
id: bump
run: |
uv tool install bump-my-version
uv tool run bump-my-version bump ${{ steps.bump_type.outputs.type }}
# echo the version to github env, the version is shown by using uv tool run bump-my-version show current_version
echo "VERSION<<EOF" >> $GITHUB_ENV
echo "$(uv tool run bump-my-version show current_version)" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ secrets.REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.TOKEN }}
- name: Get previous tag
id: prev_tag
run: |
prev=$(git tag --sort=-v:refname | sed -n '2p' || true)
echo "tag=$prev" >> "$GITHUB_OUTPUT"
- name: Compute lowercased image repo
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.docker_release == 'true' || github.event_name == 'pull_request' }}
run: |
echo "IMAGE_REPO=${{ secrets.REGISTRY }}/$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Docker meta
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.docker_release == 'true' || github.event_name == 'pull_request' }}
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_REPO }}
tags: |
type=raw,value=latest
type=raw,value=${{ env.VERSION }}
- name: Build and push Docker image
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.docker_release == 'true' || github.event_name == 'pull_request' }}
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
push: true
no-cache: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ env.PUSH_BRANCH }}
- name: Build Changelog
id: build_changelog
uses: https://github.com/mikepenz/release-changelog-builder-action@v5
with:
platform: "gitea"
baseURL: "http://192.168.178.110:3000"
configuration: ".gitea/changelog_config.json"
env:
GITHUB_TOKEN: ${{ secrets.GITEA_TOKEN }}
- name: Create Gitea Release
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.github_release == 'true' || github.event_name == 'pull_request' }}
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ env.VERSION }}
release_name: Release v${{ env.VERSION }}
body: ${{steps.build_changelog.outputs.changelog}}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}