* Updated workflow
* Added GPG public signing key
This commit is contained in:
+132
-109
@@ -16,6 +16,11 @@ on:
|
|||||||
description: "New version to release (e.g., 0.2.0)"
|
description: "New version to release (e.g., 0.2.0)"
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
|
pr_check_timeout:
|
||||||
|
description: "Timeout in seconds for PR status checks (default: 1800)"
|
||||||
|
required: false
|
||||||
|
type: number
|
||||||
|
default: 1800
|
||||||
jobs:
|
jobs:
|
||||||
description: "Comma-separated jobs to run (e.g., build-windows,build-debian,build-arch,build-rhel)"
|
description: "Comma-separated jobs to run (e.g., build-windows,build-debian,build-arch,build-rhel)"
|
||||||
required: true
|
required: true
|
||||||
@@ -35,15 +40,23 @@ env:
|
|||||||
jobs:
|
jobs:
|
||||||
bump-version:
|
bump-version:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
pull-requests: write
|
||||||
outputs:
|
outputs:
|
||||||
pr_number: ${{ steps.create-pr.outputs.pr_number }}
|
pr_number: ${{ steps.create-pr.outputs.pr_number }}
|
||||||
steps:
|
steps:
|
||||||
- name: Validate version format
|
- name: Validate version format
|
||||||
run: |
|
run: |
|
||||||
VERSION="${{ github.event.inputs.new_version }}"
|
VERSION="${{ github.event.inputs.new_version }}"
|
||||||
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?$ ]]; then
|
# Full semver regex supporting:
|
||||||
|
# - Basic: 1.2.3
|
||||||
|
# - Prerelease: 1.2.3-beta, 1.2.3-rc.1, 1.2.3-alpha.1.2
|
||||||
|
# - Build metadata: 1.2.3+build, 1.2.3+20130313144700
|
||||||
|
# - Combined: 1.2.3-beta.1+build.123
|
||||||
|
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*)?(\+[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*)?$ ]]; then
|
||||||
echo "::error::Invalid version format: $VERSION"
|
echo "::error::Invalid version format: $VERSION"
|
||||||
echo "::error::Expected format: MAJOR.MINOR.PATCH (e.g., 1.2.3 or 1.2.3-beta)"
|
echo "::error::Expected semantic version format (e.g., 1.2.3, 1.2.3-beta.1, 1.2.3+build.123)"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "Version format is valid: $VERSION"
|
echo "Version format is valid: $VERSION"
|
||||||
@@ -52,7 +65,6 @@ jobs:
|
|||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
ref: develop
|
ref: develop
|
||||||
fetch-depth: 0
|
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Configure git
|
- name: Configure git
|
||||||
@@ -68,12 +80,42 @@ jobs:
|
|||||||
- name: Install Poetry
|
- name: Install Poetry
|
||||||
uses: snok/install-poetry@v1
|
uses: snok/install-poetry@v1
|
||||||
|
|
||||||
|
- name: Check for existing PR or branch
|
||||||
|
id: check-existing
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
set -e
|
||||||
|
VERSION="${{ github.event.inputs.new_version }}"
|
||||||
|
BRANCH_NAME="release/v${VERSION}"
|
||||||
|
|
||||||
|
# Check if branch already exists
|
||||||
|
if git ls-remote --heads origin "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; then
|
||||||
|
echo "::warning::Branch $BRANCH_NAME already exists"
|
||||||
|
|
||||||
|
# Check if there's an open PR for this branch
|
||||||
|
EXISTING_PR=$(gh pr list --base develop --head "$BRANCH_NAME" --state open --json number --jq '.[0].number' || echo "")
|
||||||
|
|
||||||
|
if [ -n "$EXISTING_PR" ]; then
|
||||||
|
echo "::error::PR #$EXISTING_PR already exists for version $VERSION"
|
||||||
|
echo "::error::Please close or merge the existing PR before creating a new release"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "::error::Branch $BRANCH_NAME exists but no open PR found"
|
||||||
|
echo "::error::Please delete the branch or use a different version number"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "✓ No existing branch or PR found for version $VERSION"
|
||||||
|
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Create release branch and bump version
|
- name: Create release branch and bump version
|
||||||
id: bump
|
id: bump
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
VERSION="${{ github.event.inputs.new_version }}"
|
VERSION="${{ github.event.inputs.new_version }}"
|
||||||
BRANCH_NAME="release/v${VERSION}"
|
BRANCH_NAME="${{ steps.check-existing.outputs.branch_name }}"
|
||||||
|
|
||||||
# Create and checkout release branch
|
# Create and checkout release branch
|
||||||
git checkout -b "$BRANCH_NAME"
|
git checkout -b "$BRANCH_NAME"
|
||||||
@@ -85,8 +127,11 @@ jobs:
|
|||||||
git add pyproject.toml
|
git add pyproject.toml
|
||||||
git commit -m "Bump version to ${VERSION}"
|
git commit -m "Bump version to ${VERSION}"
|
||||||
|
|
||||||
# Push the branch
|
# Push the branch with error handling
|
||||||
git push origin "$BRANCH_NAME"
|
if ! git push origin "$BRANCH_NAME"; then
|
||||||
|
echo "::error::Failed to push branch $BRANCH_NAME"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
|
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
@@ -109,7 +154,10 @@ jobs:
|
|||||||
**Auto-generated by release workflow**
|
**Auto-generated by release workflow**
|
||||||
|
|
||||||
Once status checks pass, this PR will be automatically merged." \
|
Once status checks pass, this PR will be automatically merged." \
|
||||||
--repo ${{ github.repository }})
|
--repo ${{ github.repository }} || {
|
||||||
|
echo "::error::Failed to create PR"
|
||||||
|
exit 1
|
||||||
|
})
|
||||||
|
|
||||||
# Extract PR number from URL
|
# Extract PR number from URL
|
||||||
PR_NUMBER=$(echo "$PR_URL" | grep -oP '\d+$')
|
PR_NUMBER=$(echo "$PR_URL" | grep -oP '\d+$')
|
||||||
@@ -117,12 +165,18 @@ jobs:
|
|||||||
echo "Created PR #$PR_NUMBER: $PR_URL"
|
echo "Created PR #$PR_NUMBER: $PR_URL"
|
||||||
|
|
||||||
# Enable auto-merge (squash)
|
# Enable auto-merge (squash)
|
||||||
gh pr merge "$PR_NUMBER" --auto --squash --repo ${{ github.repository }}
|
if ! gh pr merge "$PR_NUMBER" --auto --squash --repo ${{ github.repository }}; then
|
||||||
|
echo "::error::Failed to enable auto-merge for PR #$PR_NUMBER"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
echo "Auto-merge enabled for PR #$PR_NUMBER"
|
echo "Auto-merge enabled for PR #$PR_NUMBER"
|
||||||
|
|
||||||
wait-for-version-pr:
|
wait-for-version-pr:
|
||||||
needs: [bump-version]
|
needs: [bump-version]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
pull-requests: read
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -135,9 +189,10 @@ jobs:
|
|||||||
PR_NUMBER="${{ needs.bump-version.outputs.pr_number }}"
|
PR_NUMBER="${{ needs.bump-version.outputs.pr_number }}"
|
||||||
echo "Monitoring PR #$PR_NUMBER for status checks..."
|
echo "Monitoring PR #$PR_NUMBER for status checks..."
|
||||||
|
|
||||||
MAX_WAIT=1800 # 30 minutes max wait
|
MAX_WAIT=${{ github.event.inputs.pr_check_timeout || 1800 }}
|
||||||
SLEEP_INTERVAL=30
|
SLEEP_INTERVAL=30
|
||||||
ELAPSED=0
|
ELAPSED=0
|
||||||
|
echo "Max wait time: ${MAX_WAIT}s"
|
||||||
|
|
||||||
while [ $ELAPSED -lt $MAX_WAIT ]; do
|
while [ $ELAPSED -lt $MAX_WAIT ]; do
|
||||||
# Get PR status
|
# Get PR status
|
||||||
@@ -182,6 +237,8 @@ jobs:
|
|||||||
merge-develop-to-main:
|
merge-develop-to-main:
|
||||||
needs: [wait-for-version-pr]
|
needs: [wait-for-version-pr]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
outputs:
|
outputs:
|
||||||
merge_commit_sha: ${{ steps.merge.outputs.merge_commit_sha }}
|
merge_commit_sha: ${{ steps.merge.outputs.merge_commit_sha }}
|
||||||
previous_main_sha: ${{ steps.merge.outputs.previous_main_sha }}
|
previous_main_sha: ${{ steps.merge.outputs.previous_main_sha }}
|
||||||
@@ -227,14 +284,19 @@ jobs:
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Fast-forward merge develop into main
|
# Merge develop into main (create merge commit for revert capability)
|
||||||
git checkout main
|
git checkout main
|
||||||
git merge origin/develop --ff-only
|
git merge origin/develop --no-ff -m "Merge develop into main for release"
|
||||||
|
|
||||||
echo "Successfully fast-forwarded main to develop"
|
echo "Successfully merged develop into main"
|
||||||
git log origin/main..HEAD --oneline
|
git log origin/main..HEAD --oneline
|
||||||
|
|
||||||
git push origin main
|
# Push with error handling
|
||||||
|
if ! git push origin main; then
|
||||||
|
echo "::error::Failed to push merge commit to main"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Successfully pushed merge commit to main"
|
||||||
|
|
||||||
# Store the new merge commit SHA
|
# Store the new merge commit SHA
|
||||||
MERGE_COMMIT_SHA=$(git rev-parse HEAD)
|
MERGE_COMMIT_SHA=$(git rev-parse HEAD)
|
||||||
@@ -244,44 +306,65 @@ jobs:
|
|||||||
verify-main-status-checks:
|
verify-main-status-checks:
|
||||||
needs: [merge-develop-to-main]
|
needs: [merge-develop-to-main]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
actions: read
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout main branch
|
- name: Checkout main branch
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
ref: main
|
ref: main
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Set up Python
|
- name: Verify commit status via GitHub API
|
||||||
uses: actions/setup-python@v5
|
id: check-status
|
||||||
with:
|
env:
|
||||||
python-version: '3.12'
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Install Poetry
|
|
||||||
uses: snok/install-poetry@v1
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
run: |
|
||||||
poetry install
|
set -e
|
||||||
|
MERGE_COMMIT="${{ needs.merge-develop-to-main.outputs.merge_commit_sha }}"
|
||||||
|
echo "Checking status of commit: $MERGE_COMMIT"
|
||||||
|
|
||||||
- name: Run unit tests - Linux
|
# Wait a moment for status checks to be registered
|
||||||
id: test-linux
|
sleep 5
|
||||||
run: |
|
|
||||||
poetry run pytest tests/ -v
|
|
||||||
|
|
||||||
- name: Run unit tests - Windows (via Act or skip)
|
# Get commit status using GitHub API
|
||||||
id: test-windows
|
MAX_WAIT=300 # 5 minutes max wait for status checks to appear
|
||||||
continue-on-error: true
|
SLEEP_INTERVAL=10
|
||||||
run: |
|
ELAPSED=0
|
||||||
echo "Windows tests would run here in a matrix job"
|
|
||||||
echo "Skipping for now as this is a Linux runner"
|
|
||||||
|
|
||||||
- name: Build verification
|
while [ $ELAPSED -lt $MAX_WAIT ]; do
|
||||||
id: build-check
|
# Get combined status for the commit
|
||||||
run: |
|
STATUS_RESPONSE=$(gh api "repos/${{ github.repository }}/commits/${MERGE_COMMIT}/status" --jq '{state: .state, statuses: .statuses | length, total_count: .total_count}' || echo '{"state":"pending","statuses":0,"total_count":0}')
|
||||||
echo "Build checks passed"
|
|
||||||
|
|
||||||
- name: Handle test failures with rollback
|
STATE=$(echo "$STATUS_RESPONSE" | jq -r '.state')
|
||||||
if: failure()
|
TOTAL_COUNT=$(echo "$STATUS_RESPONSE" | jq -r '.total_count')
|
||||||
|
|
||||||
|
echo "Commit status: state=$STATE, checks=$TOTAL_COUNT (${ELAPSED}s elapsed)"
|
||||||
|
|
||||||
|
if [ "$STATE" = "success" ]; then
|
||||||
|
echo "✓ All status checks passed on main branch"
|
||||||
|
exit 0
|
||||||
|
elif [ "$STATE" = "failure" ] || [ "$STATE" = "error" ]; then
|
||||||
|
echo "::error::Status checks failed on commit $MERGE_COMMIT"
|
||||||
|
gh api "repos/${{ github.repository }}/commits/${MERGE_COMMIT}/status" --jq '.statuses[] | select(.state == "failure" or .state == "error") | "- " + .context + ": " + .state'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep $SLEEP_INTERVAL
|
||||||
|
ELAPSED=$((ELAPSED + SLEEP_INTERVAL))
|
||||||
|
done
|
||||||
|
|
||||||
|
# If we get here, treat as success if no checks were registered
|
||||||
|
if [ "$TOTAL_COUNT" -eq 0 ]; then
|
||||||
|
echo "⚠ No status checks found for commit, proceeding..."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "::warning::Status checks still pending after ${MAX_WAIT}s, proceeding with caution..."
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
- name: Handle status check failures with rollback
|
||||||
|
if: failure() && steps.check-status.outcome == 'failure'
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
@@ -303,78 +386,18 @@ jobs:
|
|||||||
git checkout main
|
git checkout main
|
||||||
git revert "$MERGE_COMMIT" --no-edit -m 1
|
git revert "$MERGE_COMMIT" --no-edit -m 1
|
||||||
|
|
||||||
# Push the revert commit
|
# Push the revert commit with error handling
|
||||||
git push origin main
|
if ! git push origin main; then
|
||||||
|
echo "::error::Failed to push revert commit"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
echo "::error::Reverted merge commit $MERGE_COMMIT on main branch"
|
echo "::error::Reverted merge commit $MERGE_COMMIT on main branch"
|
||||||
echo "::error::Workflow failed due to status check failures"
|
echo "::error::Workflow failed due to status check failures"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
run-unit-tests-linux:
|
|
||||||
needs: [verify-main-status-checks]
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
ref: main
|
|
||||||
|
|
||||||
- name: Display build information
|
|
||||||
run: |
|
|
||||||
echo "Event: ${{ github.event_name }}"
|
|
||||||
echo "Jobs to run: ${{ github.event.inputs.jobs || 'build-windows,build-debian,build-arch,build-rhel' }}"
|
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: '3.12'
|
|
||||||
|
|
||||||
- name: Install Poetry
|
|
||||||
uses: snok/install-poetry@v1
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
poetry install
|
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
run: |
|
|
||||||
poetry run pytest tests/ -v
|
|
||||||
|
|
||||||
run-unit-tests-windows:
|
|
||||||
needs: [verify-main-status-checks]
|
|
||||||
runs-on: windows-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
ref: main
|
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: '3.12'
|
|
||||||
|
|
||||||
- name: Install Poetry
|
|
||||||
uses: snok/install-poetry@v1
|
|
||||||
with:
|
|
||||||
version: latest
|
|
||||||
virtualenvs-create: true
|
|
||||||
virtualenvs-in-project: true
|
|
||||||
|
|
||||||
- name: Ensure Poetry is on PATH (Windows)
|
|
||||||
shell: pwsh
|
|
||||||
run: |
|
|
||||||
# Add Poetry user bin to PATH for subsequent steps in this job
|
|
||||||
$poetryPath = Join-Path $env:USERPROFILE ".local\bin"
|
|
||||||
Write-Output $poetryPath >> $Env:GITHUB_PATH
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
poetry install
|
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
run: |
|
|
||||||
poetry run pytest tests/ -v
|
|
||||||
build-windows:
|
build-windows:
|
||||||
needs: [verify-main-status-checks, run-unit-tests-linux, run-unit-tests-windows]
|
needs: [verify-main-status-checks]
|
||||||
if: ${{ contains(github.event.inputs.jobs, 'build-windows') }}
|
if: ${{ contains(github.event.inputs.jobs, 'build-windows') }}
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
steps:
|
steps:
|
||||||
@@ -420,7 +443,7 @@ jobs:
|
|||||||
dist/android-file-handler.exe
|
dist/android-file-handler.exe
|
||||||
|
|
||||||
build-debian:
|
build-debian:
|
||||||
needs: [verify-main-status-checks, run-unit-tests-linux, run-unit-tests-windows]
|
needs: [verify-main-status-checks]
|
||||||
if: ${{ contains(github.event.inputs.jobs, 'build-debian') }}
|
if: ${{ contains(github.event.inputs.jobs, 'build-debian') }}
|
||||||
env:
|
env:
|
||||||
DISTRO_TYPE: debian
|
DISTRO_TYPE: debian
|
||||||
@@ -507,7 +530,7 @@ jobs:
|
|||||||
pkg_dist_debian/**
|
pkg_dist_debian/**
|
||||||
|
|
||||||
build-arch:
|
build-arch:
|
||||||
needs: [verify-main-status-checks, run-unit-tests-linux, run-unit-tests-windows]
|
needs: [verify-main-status-checks]
|
||||||
if: ${{ contains(github.event.inputs.jobs, 'build-arch') }}
|
if: ${{ contains(github.event.inputs.jobs, 'build-arch') }}
|
||||||
env:
|
env:
|
||||||
DISTRO_TYPE: arch
|
DISTRO_TYPE: arch
|
||||||
@@ -587,7 +610,7 @@ jobs:
|
|||||||
|
|
||||||
|
|
||||||
build-rhel:
|
build-rhel:
|
||||||
needs: [verify-main-status-checks, run-unit-tests-linux, run-unit-tests-windows]
|
needs: [verify-main-status-checks]
|
||||||
if: ${{ contains(github.event.inputs.jobs, 'build-rhel') }}
|
if: ${{ contains(github.event.inputs.jobs, 'build-rhel') }}
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||||
|
|
||||||
|
mDMEaPAWyxYJKwYBBAHaRw8BAQdAZvH8TI491M3W7PCRrs3Iks4qsIMGFZ71UW4E
|
||||||
|
Di808m20OmFuZHJvaWQtZmlsZS1oYW5kbGVyIFJlbGVhc2UgQm90IDxqYXNvbi5y
|
||||||
|
b3NzODQxQGdtYWlsLmNvbT6IkwQTFgoAOxYhBAlZWbUAICc77jajXKVv3PRrBEqG
|
||||||
|
BQJo8BbLAhsDBQsJCAcCAiICBhUKCQgLAgQWAgMBAh4HAheAAAoJEKVv3PRrBEqG
|
||||||
|
FGIA/3wXwy2esmP0M5kVwyjoXvkxz9icqETxvWj613nVgTP0AQCErfBCae5gce2h
|
||||||
|
Ruw4g2a1dyvO+020t429qXv1T8XhCA==
|
||||||
|
=GOiu
|
||||||
|
-----END PGP PUBLIC KEY BLOCK-----
|
||||||
Reference in New Issue
Block a user