-
Notifications
You must be signed in to change notification settings - Fork 4
Update release.yml #436
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
Closed
Closed
Update release.yml #436
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
77126b8
Add Automated Release workflow: prepare/perform Maven releases and pu…
thomasturrell bb327b6
Update release workflow configuration (#432)
thomasturrell 72eb24a
Use GITHUB_TOKEN in gh cli (#434)
thomasturrell 99c5d73
Update release.yml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,161 +1,52 @@ | ||
| # 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 | ||
| # This workflow automates the release process when a draft 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) | ||
| # 1. Create a new draft 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:prepare to update versions and create release commit | ||
| # - Use Maven release:perform to build and deploy artifacts to Maven Central | ||
| # - Move the tag to point to the actual release commit | ||
| # - Create the tag to point to release commit | ||
| # - Push commits back to the originating branch | ||
|
|
||
| # - Publish the GitHub release (mark draft as non-draft) | ||
| name: Automated Release | ||
|
|
||
| on: | ||
| release: | ||
| types: [created] # Trigger when release is created | ||
| types: [created] # Only fire when a release is created | ||
|
|
||
| permissions: | ||
| contents: write # Required to push commits and update tags | ||
| contents: write # Required to push commits, update tags and edit releases | ||
|
|
||
| jobs: | ||
| release: | ||
| # Only run for draft releases; ignore non-draft created events | ||
| if: github.event.release.draft | ||
|
|
||
| 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 "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: Generate GitHub App Token | ||
| id: generate_token | ||
| uses: actions/create-github-app-token@v2 | ||
| with: | ||
| app-id: ${{ secrets.APP_ID }} | ||
| private-key: ${{ secrets.APP_PRIVATE_KEY }} | ||
|
|
||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| ref: ${{ steps.target_branch.outputs.target_branch }} | ||
| fetch-depth: 0 | ||
| token: ${{ steps.generate_token.outputs.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 25 | ||
| uses: actions/setup-java@v5 | ||
| with: | ||
| java-version: "25" | ||
| distribution: "temurin" | ||
| cache: maven | ||
| cache-dependency-path: | | ||
| pom.xml | ||
| xapi-model/pom.xml | ||
| xapi-client/pom.xml | ||
| xapi-model-spring-boot-starter/pom.xml | ||
| server-id: central | ||
| server-username: MAVEN_USERNAME | ||
| server-password: MAVEN_PASSWORD | ||
| gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} | ||
| gpg-passphrase: MAVEN_GPG_PASSPHRASE | ||
|
|
||
| - 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 | ||
| # Only prepare production modules, exclude all sample modules | ||
| # Pass -pl/-am to forked Maven invocations via -Darguments | ||
| ./mvnw -B release:prepare \ | ||
| -DreleaseVersion="${VERSION}" \ | ||
| -Dtag="${TAG_NAME}" \ | ||
| -DpushChanges=false \ | ||
| -Darguments="-pl xapi-model,xapi-client,xapi-model-spring-boot-starter -am" | ||
| 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 | ||
| # Only release production modules, exclude all sample modules | ||
| # Pass -pl/-am to forked Maven invocations via -Darguments | ||
| ./mvnw -B release:perform \ | ||
| -DlocalCheckout=true \ | ||
| -DeployAtEnd=true \ | ||
| -Darguments="-pl xapi-model,xapi-client,xapi-model-spring-boot-starter -am" | ||
| 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" | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace should be removed. The file should end cleanly after the meaningful content.