Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven release from Github Actions

I wanted to know if we could use Github Actions for committing release commits after closing a milestone.

So what I've done previously is to commit mvn release:prepare && mvn release:perform on my local computer, then push it. However, with Github Actions, I was hoping that I could automate release commits from the workflow itself.

So far all the tutorials for using Maven with Github Actions are limited to running clean install or test checks or deployments, but never release.

Does anyone have any experience in setting up Maven release with Github Actions? Thank you

like image 221
user8152821 Avatar asked Jul 21 '26 13:07

user8152821


1 Answers

With the addition of the workflow_dispatch event, you can now create workflows on GitHub Actions that are manually triggered. Also, you can specify inputs, which GitHub will present as form elements in the UI. This is particularly useful when cutting releases with Maven.

  1. Create a new workflow containing two input fields: releaseVersion and developmentVersion.
on:
  workflow_dispatch:
    inputs:
      releaseVersion:
        description: "Default version to use when preparing a release."
        required: true
        default: "X.Y.Z"
      developmentVersion:
        description: "Default version to use for new local working copy."
        required: true
        default: "X.Y.Z-SNAPSHOT"
  1. Set up a job to make Maven releases using the given releaseVersion and developmentVersion.
jobs:
  release:
    runs-on: ubuntu-latest

    steps:
      # Checkout source code, set up Java, etc. Then...

      - name: Configure Git User
        run: |
          git config user.email "[email protected]"
          git config user.name "GitHub Actions"

      - name: Maven Release
        run: mvn release:prepare release:perform -B -s .maven_settings.xml -DreleaseVersion=${{ github.event.inputs.releaseVersion }} -DdevelopmentVersion=${{ github.event.inputs.developmentVersion }}
        env:
          CI_DEPLOY_USERNAME: ${{ secrets.CI_DEPLOY_USERNAME }}
          CI_DEPLOY_PASSWORD: ${{ secrets.CI_DEPLOY_PASSWORD }}

You must have a .maven_settings.xml file saved at the root of your project, containing the username and password to authenticate before downloading or uploading artifacts to repositories configured in the repositories and distributionManagement sections.

<settings>
  ...
  <servers>
    <server>
      <id>server.id</id>
      <username>${env.CI_DEPLOY_USERNAME}</username>
      <password>${env.CI_DEPLOY_PASSWORD}</password>
    </server>
  </servers>
</settings>

You can configure both secrets CI_DEPLOY_USERNAME and CI_DEPLOY_PASSWORD on the project's settings page.

Here's a full example of a Maven release workflow configuration for reference.

like image 63
Henrique Prange Avatar answered Jul 23 '26 23:07

Henrique Prange



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!