Case Study: You have 2 maven projects, A and B. You want that every successful release of project A will trigger release in project B automatically.
One of solution is using GitHub Action's repository_dispatch
event to release "next" maven project automatically. This
demo using these 2 projects to show it works:
This is optional step, and the purpose is to make sure your maven and cloudsmith configuration Ok.
Use cloudsmith to for actual maven release. To deploy to cloudsmith:
- Set up your cloudsmith account and maven repository over there.
- Set your maven's
settings.xml
(seesample-settings.xml
as an example). We'll use this dedicatedsettings.xml
so this demo never broke your actual<HOME>/.m2/settings.xml
that may contain your job's configuration. - In each project, call following command :
mvn clean install && mvn -B --gs settings.xml release:clean release:prepare release:perform
. Add these arguments to
set release/development version:-DreleaseVersion=1.0.1-RC1 -DdevelopmentVersion=1.0.1-SNAPSHOT
.
Optional step, to make sure your individual action event configured properly.
Before release, make sure that:
- Read and write permissions are enabled in GitHub Action. (
Settings -> Actions -> General -> Workflow permissions
) CLOUDSMITH_USER
andCLOUDSMITH_API_KEY
GitHub secrets variables are set up properly, by go toSettings -> Secrets & Variables -> Actions -> "New Repository Secret" button
. Link for cloudsmith api key is here.
To start release:
- Go to
Actions
tab. - In
Actions
section on the left pane, selectrelease
(or any other available workflows). - Select "Run Workflow" dropdown on the right, and click the "Run Workflow" button.
- The release workflow should start running.
This workflow contains all steps as Use GitHub Action above, except that
kb-commons or kb-base will trigger repository_dispatch event in
kb-oss-parent
(this repository), using repository_dispatch
.
The repository_dispatch
event in this repository defined by release-dispatch.yml file. Note that repository_dispatch
needs Personal Access Token
To create Personal Access Token:
- Go to your developer settings, and then
-> Personal Access Token -> Fine-grained Tokens
. - Click "generate new token" button, and configure it so that have an access like in the picture below.
- Set
metadata:read
,actions:read&write
andcontents:read&write
(note thatcontents
permission in screenshot labeled ascode
). - Put this PAT to each involved repositories secret. Set:
Settings -> Secrets & Variables -> Actions -> "New Repository Secret" button
- This variables will be available in workflow (For example, see line:
GH_WORKFLOW_PAT: ${{ secrets.GH_WORKFLOW_PAT }}
inkb-commons/.github/workflows/release.yml
).
If everything set successfully, executing release
with send_repository_dispatch=yes
action will in kb-commons
or
kb-base
will update kb-commons.version
or kb-base.version
in kb-oss-parent/pom.xml
file.