140 lines
3.9 KiB
YAML
140 lines
3.9 KiB
YAML
name: Release and Build Image
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- "v*"
|
|
|
|
jobs:
|
|
release:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Check out repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Prepare release metadata
|
|
shell: bash
|
|
run: |
|
|
TAG="${GITHUB_REF_NAME:-${GITHUB_REF##refs/tags/}}"
|
|
VERSION="${TAG#v}"
|
|
IMAGE_REGISTRY="${{ gitea.server_url }}"
|
|
IMAGE_REGISTRY="${IMAGE_REGISTRY#http://}"
|
|
IMAGE_REGISTRY="${IMAGE_REGISTRY#https://}"
|
|
IMAGE_NAME="${IMAGE_REGISTRY}/${{ gitea.repository }}"
|
|
|
|
echo "TAG=$TAG" >> "$GITHUB_ENV"
|
|
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
|
|
echo "IMAGE_NAME=$IMAGE_NAME" >> "$GITHUB_ENV"
|
|
|
|
if [[ "$TAG" == *-* ]]; then
|
|
echo "PRERELEASE=true" >> "$GITHUB_ENV"
|
|
else
|
|
echo "PRERELEASE=false" >> "$GITHUB_ENV"
|
|
fi
|
|
|
|
- name: Extract matching CHANGELOG section
|
|
shell: bash
|
|
run: |
|
|
python3 - <<'PY'
|
|
import os
|
|
import re
|
|
from pathlib import Path
|
|
|
|
version = os.environ["VERSION"]
|
|
changelog_path = Path("CHANGELOG.md")
|
|
|
|
if not changelog_path.exists():
|
|
body = f"# {version}\n\nNo CHANGELOG.md found."
|
|
Path("release_body.md").write_text(body, encoding="utf-8")
|
|
raise SystemExit(0)
|
|
|
|
text = changelog_path.read_text(encoding="utf-8")
|
|
|
|
pattern = re.compile(
|
|
rf"^##\s+\[?{re.escape(version)}\]?[^\n]*\n(.*?)(?=^##\s+\[?[0-9]|\Z)",
|
|
re.MULTILINE | re.DOTALL,
|
|
)
|
|
|
|
match = pattern.search(text)
|
|
if match:
|
|
body = match.group(1).strip()
|
|
else:
|
|
body = f"Release {version}"
|
|
|
|
if not body:
|
|
body = f"Release {version}"
|
|
|
|
Path("release_body.md").write_text(body + "\n", encoding="utf-8")
|
|
PY
|
|
|
|
- name: Log in to Gitea container registry
|
|
shell: bash
|
|
env:
|
|
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
|
REGISTRY_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
|
run: |
|
|
echo "$REGISTRY_TOKEN" | docker login "${IMAGE_NAME%%/*}" -u "$REGISTRY_USERNAME" --password-stdin
|
|
|
|
- name: Build Docker image
|
|
shell: bash
|
|
run: |
|
|
docker build \
|
|
-t "$IMAGE_NAME:$TAG" \
|
|
-t "$IMAGE_NAME:latest" \
|
|
.
|
|
|
|
- name: Push version tag
|
|
shell: bash
|
|
run: |
|
|
docker push "$IMAGE_NAME:$TAG"
|
|
|
|
- name: Push latest tag
|
|
if: ${{ !contains(env.TAG, '-') }}
|
|
shell: bash
|
|
run: |
|
|
docker push "$IMAGE_NAME:latest"
|
|
|
|
- name: Push prerelease channel tag
|
|
if: ${{ contains(env.TAG, '-') }}
|
|
shell: bash
|
|
run: |
|
|
CHANNEL="${TAG#*-}"
|
|
CHANNEL="${CHANNEL%%.*}"
|
|
docker tag "$IMAGE_NAME:$TAG" "$IMAGE_NAME:$CHANNEL"
|
|
docker push "$IMAGE_NAME:$CHANNEL"
|
|
|
|
- name: Extract matching CHANGELOG section
|
|
shell: bash
|
|
run: |
|
|
python3 - <<'PY'
|
|
import os
|
|
import re
|
|
from pathlib import Path
|
|
|
|
version = os.environ["VERSION"]
|
|
changelog_path = Path("lst_v3/CHANGELOG.md")
|
|
|
|
if not changelog_path.exists():
|
|
Path("release_body.md").write_text(f"Release {version}\n", encoding="utf-8")
|
|
raise SystemExit(0)
|
|
|
|
text = changelog_path.read_text(encoding="utf-8")
|
|
|
|
pattern = re.compile(
|
|
rf"^##\s+\[?{re.escape(version)}\]?[^\n]*\n(.*?)(?=^##\s+\[?[0-9]|\Z)",
|
|
re.MULTILINE | re.DOTALL,
|
|
)
|
|
|
|
match = pattern.search(text)
|
|
if match:
|
|
body = match.group(1).strip()
|
|
else:
|
|
body = f"Release {version}"
|
|
|
|
if not body:
|
|
body = f"Release {version}"
|
|
|
|
Path("release_body.md").write_text(body + "\n", encoding="utf-8")
|
|
print(body)
|
|
PY |