125 lines
4.0 KiB
YAML
125 lines
4.0 KiB
YAML
name: CI/CD Pipeline
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- 'v*'
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
|
|
env:
|
|
REGISTRY: git.hnrx.net
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
jobs:
|
|
lint:
|
|
name: Lint & Check
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Install uv
|
|
uses: astral-sh/setup-uv@v2
|
|
with:
|
|
version: "latest"
|
|
enable-cache: true
|
|
|
|
- name: Install dependencies
|
|
run: uv sync --frozen --dev
|
|
|
|
- name: Run Ruff (Lint & Syntax Check)
|
|
run: uv run ruff check src
|
|
|
|
build-and-push:
|
|
name: Build & Push Docker Image
|
|
needs: lint
|
|
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
|
|
runs-on: gitea-runner-on-dsm
|
|
permissions:
|
|
packages: write
|
|
contents: read
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Log in to the Container registry
|
|
uses: docker/login-action@v4
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
- name: Extract metadata (tags, labels) for Docker
|
|
id: meta
|
|
uses: docker/metadata-action@v6
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
tags: |
|
|
type=raw,value=latest,enable={{is_default_branch}}
|
|
type=ref,event=tag
|
|
|
|
- name: Determine PEP 440 Version for Python Package
|
|
id: pkg_version
|
|
run: |
|
|
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
|
|
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "version=0.0.dev${{ github.run_number }}" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v4
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v7
|
|
with:
|
|
context: .
|
|
push: true
|
|
platforms: linux/amd64,linux/arm64
|
|
build-args: VERSION=${{ steps.pkg_version.outputs.version }}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache
|
|
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max
|
|
|
|
- name: Update Gitea Release Notes
|
|
if: startsWith(github.ref, 'refs/tags/v')
|
|
run: |
|
|
TAG_NAME=${GITHUB_REF#refs/tags/}
|
|
|
|
# Fetch the current release
|
|
RELEASE_JSON=$(curl -s -H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
|
${{ github.api_url }}/repos/${{ github.repository }}/releases/tags/${TAG_NAME})
|
|
|
|
# Extract Release ID (if it exists)
|
|
RELEASE_ID=$(echo "$RELEASE_JSON" | jq -r '.id // empty')
|
|
|
|
if [ -n "$RELEASE_ID" ] && [ "$RELEASE_ID" != "null" ]; then
|
|
OLD_BODY=$(echo "$RELEASE_JSON" | jq -r '.body // ""')
|
|
|
|
# Check if Docker Image section already exists
|
|
if [[ "$OLD_BODY" != *"## 🐳 Docker Image"* ]]; then
|
|
NEW_BODY="${OLD_BODY}\n\n## 🐳 Docker Image\n\`\`\`bash\ndocker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG_NAME}\n\`\`\`"
|
|
|
|
jq -n --arg body "$NEW_BODY" '{body: $body}' | \
|
|
curl -s -X PATCH \
|
|
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
|
-H "Content-Type: application/json" \
|
|
-d @- \
|
|
${{ github.api_url }}/repos/${{ github.repository }}/releases/${RELEASE_ID}
|
|
|
|
echo "Successfully updated Release Notes for $TAG_NAME"
|
|
else
|
|
echo "Release Notes already contain the Docker pull command."
|
|
fi
|
|
else
|
|
echo "No associated release found for tag $TAG_NAME. Skipping."
|
|
fi
|