name: Release Please
on:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: write
pull-requests: write
actions: write # Required to trigger workflow dispatches
jobs:
release-please:
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
version: ${{ steps.release.outputs.version }}
pr: ${{ steps.release.outputs.pr }}
steps:
- name: Run release-please
id: release
uses: googleapis/release-please-action@v4
with:
# Release type for Python packages
release-type: python
# Configuration file location
config-file: release-please-config.json
manifest-file: .release-please-manifest.json
# Skip automatic GitHub release creation (handled by separate release.yml workflow)
skip-github-release: true
# Token for creating PRs and releases
token: ${{ secrets.GITHUB_TOKEN }}
# Optional: Add a job to notify about release PR creation
notify-release-pr:
runs-on: ubuntu-latest
needs: release-please
if: needs.release-please.outputs.pr && !needs.release-please.outputs.release_created
steps:
- name: Comment on PR
uses: actions/github-script@v8
with:
script: |
// Extract PR number from the PR output (format: "https://github.com/owner/repo/pull/123")
const prUrl = '${{ needs.release-please.outputs.pr }}';
if (!prUrl) {
console.log('No PR URL found');
return;
}
const prNumber = prUrl.split('/').pop();
console.log(`Found PR number: ${prNumber}`);
try {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: parseInt(prNumber),
body: `π€ **Automated Release PR Created**
This PR was automatically created by release-please based on conventional commits.
**What this PR does:**
- Updates version numbers in all relevant files
- Updates CHANGELOG.md with new release notes
- Prepares for automated release when merged
**To release:**
1. Review the changes in this PR
2. Merge this PR to automatically create a new release
**To modify:**
- Edit the files directly in this PR if needed
- The release will use the final state when merged
For more information, see the [versioning documentation](README.md#versioning).`
});
console.log('Comment added successfully');
} catch (error) {
console.log('Failed to add comment:', error.message);
}
# Validate version synchronization after release creation
validate-release:
runs-on: ubuntu-latest
needs: release-please
if: needs.release-please.outputs.release_created
steps:
- uses: actions/checkout@v6
with:
ref: ${{ needs.release-please.outputs.tag_name }}
- name: Validate version synchronization
run: |
echo "π Validating version synchronization for ${{ needs.release-please.outputs.tag_name }}"
# Extract version from tag
TAG_VERSION="${{ needs.release-please.outputs.version }}"
echo "Expected version: $TAG_VERSION"
# Check pyproject.toml
PYPROJECT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "pyproject.toml version: $PYPROJECT_VERSION"
# Check __init__.py
INIT_VERSION=$(grep '__version__ = ' openzim_mcp/__init__.py | sed 's/__version__ = "\(.*\)"/\1/')
echo "__init__.py version: $INIT_VERSION"
# Check manifest
MANIFEST_VERSION=$(jq -r '."."' .release-please-manifest.json)
echo "manifest version: $MANIFEST_VERSION"
# Validate all versions match
if [ "$TAG_VERSION" = "$PYPROJECT_VERSION" ] && [ "$TAG_VERSION" = "$INIT_VERSION" ] && [ "$TAG_VERSION" = "$MANIFEST_VERSION" ]; then
echo "β
All versions are synchronized!"
else
echo "β Version mismatch detected!"
echo "Tag: $TAG_VERSION"
echo "pyproject.toml: $PYPROJECT_VERSION"
echo "__init__.py: $INIT_VERSION"
echo "manifest: $MANIFEST_VERSION"
exit 1
fi
- name: Notify release created
run: |
echo "π Release ${{ needs.release-please.outputs.tag_name }} created and validated!"
echo "Version: ${{ needs.release-please.outputs.version }}"
echo "The release workflow will now be triggered automatically."
# Trigger the release workflow when a release is created
trigger-release:
runs-on: ubuntu-latest
needs: [release-please, validate-release]
if: needs.release-please.outputs.release_created && needs.validate-release.result == 'success'
steps:
- name: Trigger release workflow
uses: actions/github-script@v8
with:
script: |
const tagName = '${{ needs.release-please.outputs.tag_name }}';
console.log(`Triggering release workflow for tag: ${tagName}`);
try {
const result = await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'release.yml',
ref: 'main',
inputs: {
tag: tagName,
create_tag: 'false'
}
});
console.log('β
Release workflow triggered successfully');
console.log(`Workflow dispatch result: ${result.status}`);
} catch (error) {
console.error('β Failed to trigger release workflow:', error.message);
throw error;
}