Files
TwitchDropsMiner/.github/workflows/publish.yml
2025-10-25 22:29:21 +11:00

165 lines
5.2 KiB
YAML

name: Publish Release
on:
push:
branches:
- 'release/**'
permissions:
contents: write
packages: write
jobs:
extract-version:
name: Extract Version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.extract.outputs.version }}
is_prerelease: ${{ steps.extract.outputs.is_prerelease }}
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Extract version from branch and version.py
id: extract
run: |
# Extract version from branch name (release/1.2.3 -> 1.2.3)
BRANCH_VERSION="${GITHUB_REF#refs/heads/release/}"
echo "Branch version: $BRANCH_VERSION"
# Read version from version.py
FILE_VERSION=$(grep -oP '__version__ = "\K[^"]+' src/version.py)
echo "File version: $FILE_VERSION"
# Verify they match
if [ "$BRANCH_VERSION" != "$FILE_VERSION" ]; then
echo "Error: Branch version ($BRANCH_VERSION) does not match version.py ($FILE_VERSION)"
exit 1
fi
VERSION="$BRANCH_VERSION"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
# Check if pre-release (contains hyphen)
if echo "$VERSION" | grep -q '-'; then
echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
echo "Detected pre-release version: $VERSION"
else
echo "is_prerelease=false" >> "$GITHUB_OUTPUT"
echo "Detected stable release version: $VERSION"
fi
docker-build:
name: Build & Push Docker Images
runs-on: ubuntu-latest
needs: extract-version
environment: prod
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Generate Docker tags
id: docker-tags
run: |
VERSION="${{ needs.extract-version.outputs.version }}"
IMAGE="rangermix/twitch-drops-miner"
IS_PRERELEASE="${{ needs.extract-version.outputs.is_prerelease }}"
# Always include the full version tag
TAGS="$IMAGE:$VERSION"
# For stable releases, add major.minor, major, and latest tags
if [ "$IS_PRERELEASE" = "false" ]; then
# Extract major.minor.patch
MAJOR=$(echo "$VERSION" | cut -d. -f1)
MINOR=$(echo "$VERSION" | cut -d. -f2)
TAGS="$TAGS,$IMAGE:$MAJOR.$MINOR"
TAGS="$TAGS,$IMAGE:$MAJOR"
TAGS="$TAGS,$IMAGE:latest"
fi
echo "tags=$TAGS" >> "$GITHUB_OUTPUT"
echo "Generated tags: $TAGS"
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.docker-tags.outputs.tags }}
labels: |
org.opencontainers.image.title=Twitch Drops Miner
org.opencontainers.image.description=Automatically mine Twitch drops
org.opencontainers.image.version=${{ needs.extract-version.outputs.version }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.created=${{ github.event.repository.updated_at }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
BUILD_DATE=${{ github.event.repository.updated_at }}
VCS_REF=${{ github.sha }}
VERSION=${{ needs.extract-version.outputs.version }}
github-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [extract-version, docker-build]
environment: prod
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Create and push git tag
run: |
VERSION="${{ needs.extract-version.outputs.version }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Create tag
git tag "v$VERSION"
git push origin "v$VERSION"
echo "✅ Created and pushed tag v$VERSION"
- name: Auto-generate release notes if missing
run: .github/scripts/generate_release_notes.sh "${{ needs.extract-version.outputs.version }}" "${{ secrets.GEMINI_API_KEY }}"
- uses: DavidAnson/markdownlint-cli2-action@v20
with:
fix: true
globs: '**/*.md'
continue-on-error: true
- name: Generate release notes
id: release-notes
run: .github/scripts/extract_release_notes.sh "${{ needs.extract-version.outputs.version }}"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.extract-version.outputs.version }}
name: Release ${{ needs.extract-version.outputs.version }}
body_path: release_notes.md
prerelease: ${{ needs.extract-version.outputs.is_prerelease }}
draft: false