-
Notifications
You must be signed in to change notification settings - Fork 4
Automate release workflow via GitHub releases using Maven release plugin #346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c61a01b
Initial plan
Copilot 79c11b2
Add automated release workflow and documentation
Copilot 14f7fb5
Add test verification step before release deployment
Copilot 11dbea2
Enhance release documentation with workflow diagram and troubleshootiβ¦
Copilot 01573ba
Update main branch with next SNAPSHOT version after release
Copilot f096dff
Use Maven release plugin (release:prepare and release:perform) with bβ¦
Copilot d51004b
Apply suggestions from code review
thomasturrell 6e16a2c
Update .github/workflows/release.yml
thomasturrell 69f0dc9
Document GITHUB_TOKEN behavior: release commits won't trigger CI workβ¦
Copilot b99b33c
Remove unnecessary documentation sections from RELEASING.md
Copilot 23fe0f2
Simplify workflow: use Maven's automatic version calculation and remoβ¦
Copilot 2fa5ec3
Remove redundant Maven configuration and SVN-specific parameter
Copilot 1f6d320
Merge branch 'main' into copilot/simplify-release-workflow
thomasturrell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| # This workflow automates the release process when a release is created on GitHub | ||
| # It uses Maven release plugin to manage versions and deploys to Maven Central | ||
| # | ||
| # Usage: | ||
| # 1. Create a new release in GitHub UI with tag format: vX.Y.Z (e.g., v1.2.0) | ||
| # - Select the target branch (typically main) | ||
| # 2. This workflow will automatically: | ||
| # - Use Maven release:prepare to update versions and create release commits | ||
| # - Use Maven release:perform to build and deploy artifacts to Maven Central | ||
| # - Move the tag to point to the actual release commit | ||
| # - Push commits back to the originating branch | ||
|
|
||
| name: Automated Release | ||
|
|
||
| on: | ||
| release: | ||
| types: [created] # Trigger when release is created | ||
|
|
||
| permissions: | ||
| contents: write # Required to push commits and update tags | ||
|
|
||
| jobs: | ||
| release: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Validate release tag format | ||
| id: validate_tag | ||
| run: | | ||
| TAG_NAME="${{ github.event.release.tag_name }}" | ||
| echo "Release tag: $TAG_NAME" | ||
|
|
||
| # Validate tag format (should be vX.Y.Z) | ||
| if [[ ! "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
| echo "::error::Invalid tag format. Expected format: vX.Y.Z (e.g., v1.2.0)" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Remove 'v' prefix to get the version number | ||
| VERSION="${TAG_NAME#v}" | ||
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | ||
| echo "Extracted version: $VERSION" | ||
|
|
||
| - name: Determine target branch | ||
| id: target_branch | ||
| run: | | ||
| # Use target_commitish to determine the originating branch | ||
| TARGET="${{ github.event.release.target_commitish }}" | ||
|
|
||
| # If target_commitish is empty or a SHA, default to main | ||
| if [[ -z "$TARGET" ]] || [[ "$TARGET" =~ ^[0-9a-f]{40}$ ]]; then | ||
| TARGET="main" | ||
| fi | ||
|
|
||
| echo "target_branch=${TARGET}" >> $GITHUB_OUTPUT | ||
| echo "Target branch: $TARGET" | ||
|
|
||
| - name: Checkout repository | ||
| uses: actions/checkout@v3 | ||
| with: | ||
| ref: ${{ steps.target_branch.outputs.target_branch }} | ||
| fetch-depth: 0 | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Delete user-created tag | ||
| run: | | ||
| TAG_NAME="${{ github.event.release.tag_name }}" | ||
|
|
||
| # Delete the tag created by the user (will be recreated by release:prepare) | ||
| git tag -d "$TAG_NAME" || true | ||
| git push origin ":refs/tags/$TAG_NAME" || true | ||
|
|
||
| echo "Deleted user-created tag $TAG_NAME" | ||
|
|
||
| - name: Set up JDK 17 | ||
| uses: actions/setup-java@v5 | ||
| with: | ||
| java-version: "17" | ||
| distribution: "temurin" | ||
| cache: maven | ||
|
|
||
| - name: Configure Git | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| - name: Run Maven release:prepare | ||
| run: | | ||
| VERSION="${{ steps.validate_tag.outputs.version }}" | ||
| TAG_NAME="${{ github.event.release.tag_name }}" | ||
|
|
||
| echo "Preparing release version: $VERSION" | ||
| echo "Tag name: $TAG_NAME" | ||
|
|
||
| # Run release:prepare with explicit release version | ||
| # Maven will automatically calculate the next development version | ||
| ./mvnw -B release:prepare \ | ||
| -DreleaseVersion="${VERSION}" \ | ||
| -Dtag="${TAG_NAME}" \ | ||
| -DpushChanges=false | ||
| env: | ||
| MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} | ||
| MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} | ||
| MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} | ||
|
|
||
| - name: Run Maven release:perform | ||
| run: | | ||
| echo "Performing release and deploying to Maven Central" | ||
|
|
||
| # Run release:perform to build and deploy | ||
| ./mvnw -B release:perform \ | ||
| -DlocalCheckout=true \ | ||
| -DeployAtEnd=true | ||
| env: | ||
| MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} | ||
| MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} | ||
| MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} | ||
|
|
||
| - name: Push changes to originating branch | ||
| run: | | ||
| TARGET_BRANCH="${{ steps.target_branch.outputs.target_branch }}" | ||
| TAG_NAME="${{ github.event.release.tag_name }}" | ||
|
|
||
| echo "Pushing changes to branch: $TARGET_BRANCH" | ||
|
|
||
| # Push the commits created by release:prepare | ||
| if ! git push --force-with-lease origin "HEAD:${TARGET_BRANCH}"; then | ||
| echo "::error::Failed to push release commits to ${TARGET_BRANCH} due to branch divergence." | ||
| echo "The remote branch may have new commits. Please resolve the conflict manually:" | ||
| echo " 1. Fetch the latest changes: git fetch origin" | ||
| echo " 2. Rebase or merge as needed, then push again with --force-with-lease." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Push the tag created by release:prepare | ||
| git push origin "$TAG_NAME" | ||
|
|
||
| echo "Pushed release commits and tag to $TARGET_BRANCH" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| # Release Process | ||
|
|
||
| This document describes the automated release process for xAPI Java. | ||
|
|
||
| ## Overview | ||
|
|
||
| The release process is **fully automated** via GitHub Actions. Creating a release is as simple as: | ||
| 1. Click "Create Release" in GitHub UI | ||
| 2. Enter tag (e.g., `v1.2.0`) | ||
| 3. Publish | ||
| 4. Wait for workflow to complete β | ||
|
|
||
| All version management, building, testing, and deployment happens automatically. | ||
|
|
||
| ## Automated Release Process | ||
|
|
||
|
|
||
|
|
||
| ### Step 1: Create a GitHub Release | ||
|
|
||
| 1. Navigate to the [Releases page](https://github.com/BerryCloud/xapi-java/releases) | ||
| 2. Click **"Draft a new release"** | ||
| 3. **Choose a tag**: Enter the tag version in the format: `vX.Y.Z` (e.g., `v1.2.0`) | ||
| - The tag **must** start with `v` followed by semantic version numbers | ||
| - Example: `v1.1.16`, `v2.0.0`, `v1.2.3` | ||
| 4. **Target**: Select the branch to release from (typically `main`) | ||
| - The workflow will automatically detect and use this branch | ||
| 5. Enter a release title (e.g., "Release 1.2.0") | ||
| 6. Add release notes describing the changes | ||
| 7. Click **"Publish release"** | ||
|
|
||
| ### Step 2: Automated Workflow Execution | ||
|
|
||
| Once you publish the release, the "Automated Release" workflow will: | ||
|
|
||
| 1. β Validate the tag format (must be `vX.Y.Z`) | ||
| 2. β Detect the target branch (auto-detected from release) | ||
| 3. β Delete the user-created tag (will be recreated properly) | ||
| 4. β **Run Maven release:prepare** to: | ||
| - Update all `pom.xml` files to the release version | ||
| - Commit the version change | ||
| - Create the release tag pointing to the release commit | ||
| - Update `pom.xml` files to the next SNAPSHOT version | ||
| - Commit the next development iteration | ||
| 5. β **Run Maven release:perform** to: | ||
| - Check out the release tag | ||
| - Build and test the release version | ||
| - Deploy artifacts to Maven Central with GPG signatures | ||
| 6. β Push commits and tag back to the originating branch | ||
|
|
||
| **Workflow Diagram:** | ||
| ``` | ||
| User Action: Create Release (tag: v1.2.0, target: main) | ||
| β | ||
| GitHub: Creates tag v1.2.0 β commit A (from main) | ||
| β | ||
| Workflow: Detects target branch (main) | ||
| β | ||
| Workflow: Deletes user-created tag v1.2.0 | ||
| β | ||
| Workflow: Runs release:prepare | ||
| β | ||
| - Commit B: pom.xml β 1.2.0 (release version) | ||
| - Creates tag v1.2.0 β commit B | ||
| - Commit C: pom.xml β 1.2.1-SNAPSHOT (next dev version) | ||
| β | ||
| Workflow: Runs release:perform | ||
| β | ||
| - Checks out tag v1.2.0 (commit B) | ||
| - Builds and tests | ||
| - Deploys to Maven Central | ||
| β | ||
| Workflow: Pushes commits B & C to main | ||
| β | ||
| Workflow: Pushes tag v1.2.0 β commit B | ||
| β | ||
| Result: | ||
| - Tag v1.2.0 β commit B (release version) | ||
| - Main branch β commit C (next SNAPSHOT: 1.2.1-SNAPSHOT) | ||
| - Artifacts deployed to Maven Central | ||
| ``` | ||
|
|
||
| ### Step 3: Verify Release | ||
|
|
||
| 1. Check the [Actions tab](https://github.com/BerryCloud/xapi-java/actions) to ensure the workflow completed successfully | ||
| 2. Verify the target branch (e.g., `main`) has two new commits: | ||
| - Release commit: `[maven-release-plugin] prepare release vX.Y.Z` | ||
| - Development commit: `[maven-release-plugin] prepare for next development iteration` | ||
| 3. Verify artifacts are available on [Maven Central](https://central.sonatype.com/artifact/dev.learning.xapi/xapi-model) | ||
|
|
||
| ## Release Branch Strategy | ||
|
|
||
| - **Main branch (`main`)** (or other target branch): Contains development code with `-SNAPSHOT` versions | ||
| - After each release, receives two commits from Maven release plugin: | ||
| 1. Release commit: Version update to release version (X.Y.Z) | ||
| 2. Development commit: Version update to next development version (X.Y.Z+1-SNAPSHOT) | ||
| - The HEAD always points to the next development version | ||
| - **Release tags (`vX.Y.Z`)**: Created by Maven release plugin | ||
| - Points to the release version commit (first commit) | ||
| - Used for reproducible builds and deployments | ||
| - **No separate release branches**: The release workflow pushes directly to the originating branch | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Release Workflow Failed | ||
|
|
||
| If the automated release workflow fails: | ||
|
|
||
| 1. **Check the workflow logs** in the [Actions tab](https://github.com/BerryCloud/xapi-java/actions) | ||
| 2. **Identify the failed step** and review the error message | ||
| 3. **Common issues and solutions:** | ||
|
|
||
| | Issue | Solution | | ||
| |-------|----------| | ||
| | Invalid tag format | Use format `vX.Y.Z` (e.g., `v1.2.0`, not `1.2.0` or `v1.2`) | | ||
| | Missing secrets | Ensure GPG keys and Maven credentials are configured in repository secrets | | ||
| | Build failures | Fix build issues on main branch first, then retry release | | ||
| | Test failures | Fix failing tests on main branch first, then retry release | | ||
|
|
||
| 4. **After fixing issues:** | ||
| - Delete the failed release and tag in GitHub UI | ||
| - **Important**: Reset your target branch if commits were already pushed: | ||
| ```bash | ||
| # If release:prepare pushed commits before failure | ||
| git fetch origin | ||
| git checkout main # or your target branch | ||
| git reset --hard origin/main~2 # Remove the 2 release commits | ||
| git push -f origin main | ||
| ``` | ||
| - Create a new release with the same tag | ||
|
|
||
| ### Workflow Stuck or Taking Too Long | ||
|
|
||
| The workflow typically takes 5-10 minutes. If it's taking longer: | ||
|
|
||
| 1. Check if tests are running (this is the longest step) | ||
| 2. Check for any hanging processes in the workflow logs | ||
| 3. You can cancel the workflow run and restart it | ||
|
|
||
| ### Artifacts Not Appearing on Maven Central | ||
|
|
||
| If artifacts don't appear on Maven Central after a successful workflow: | ||
|
|
||
| 1. Check the Central Portal for deployment status: https://central.sonatype.com/ | ||
| 2. Deployment can take up to 2 hours to sync to Maven Central | ||
| 3. Check for any deployment errors in the workflow logs | ||
| 4. Verify GPG signing was successful (check for GPG-related errors) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.