Skip to content

Commit

Permalink
♻️ ci extract maven build to action
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhir committed Sep 2, 2024
1 parent 29bdb4b commit fcc8f7a
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 60 deletions.
103 changes: 103 additions & 0 deletions .github/actions/build-maven/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: ""
description: ""

inputs:
module:
description: 'Module to build'
required: true
release:
description: 'Release?'
default: "false"
release-version:
description: 'Release version'
required: false
default: "X.Y.Z"
next-version:
description: "Next version to use after release"
required: false
default: "X.Y.Z-SNAPSHOT"
java-version:
description: "Jave version used for building"
required: false
default: "21"
gpg-private-key:
description: "Gpg private key used for signing packages for maven central release"
required: false
gpg-passphrase:
description: "Gpg passphrase for private key"
required: false
sonatype-username:
description: "Sonatype username for maven central release"
required: false
sonatype-password:
description: "Sonatype password for maven central release"
required: false

runs:
using: "composite"
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Set up JDK
uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4.2.2
with:
java-version: ${{ inputs.java-version }}
distribution: "temurin"
cache: "maven"
cache-dependency-path: "./${{ inputs.module }}/pom.xml"
server-id: "central"
server-username: CENTRAL_USERNAME
server-password: CENTRAL_PASSWORD
gpg-private-key: ${{ inputs.gpg-private-key }}
gpg-passphrase: SIGN_KEY_PASS
- name: Maven build
if: ${{ inputs.release != true }}
shell: bash
run: mvn -f ./${{ inputs.module }}/pom.xml --batch-mode clean install
- name: Maven release
if: ${{ inputs.release == true }}
shell: bash
run: |
git config --global user.email "github-actions@github.com"
git config --global user.name "GitHub Actions"
mvn release:prepare -f ./${{ inputs.module }}/pom.xml -B -DreleaseVersion=${{ inputs.release-version }} -DdevelopmentVersion=${{ inputs.next-version }} -DpushChanges=false -DremoteTagging=false
mvn release:perform -f ./${{ inputs.module }}/pom.xml -DlocalCheckout=true
env:
SIGN_KEY_PASS: ${{ inputs.gpg-passphrase }}
CENTRAL_USERNAME: ${{ inpus.sonatype-username }}
CENTRAL_PASSWORD: ${{ insputs.sonatype-password }}
- name: "Upload target artifacts"
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6
with:
name: target
path: "**/target"
retention-days: 5
- name: Push changes to new branch
if: ${{ inputs.release == true }}
shell: bash
run: |
git checkout -b ${{ github.ref_name }}-version-bump
git push --force origin ${{ github.ref_name }}-version-bump
- name: Create pull request
if: ${{ inputs.release == true }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const { repo, owner } = context.repo;
const pullResult = await github.rest.pulls.create({
title: 'chore: bump release version ${{ github.ref_name }}',
owner,
repo,
head: '${{ github.ref_name }}-version-bump',
base: '${{ github.ref_name }}',
body: [
'This PR is auto-generated'
].join('\n')
});
await github.rest.issues.addAssignees({
owner,
repo,
issue_number: pullResult.data.number,
assignees: ['${{ github.actor }}'],
});
console.log(`Pull Request created: ${pullResult.data.html_url}`);
69 changes: 9 additions & 60 deletions .github/workflows/maven.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,68 +33,17 @@ jobs:
build-maven:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Set up JDK
uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4.2.2
- uses: ./.github/actions/build-maven
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: "temurin"
cache: "maven"
cache-dependency-path: "./${{ inputs.module }}/pom.xml"
server-id: "central"
server-username: CENTRAL_USERNAME
server-password: CENTRAL_PASSWORD
module: ${{ inputs.module }}
release: ${{ inputs.snapshot-release == false }}
release-version: ${{ inputs.release-version }}
next-version: ${{ inputs.next-version }}
java-version: "21"
gpg-private-key: ${{ secrets.gpg_private_key }}
gpg-passphrase: SIGN_KEY_PASS
- name: Maven build
if: ${{ inputs.snapshot-release != false }}
run: mvn -f ./${{ inputs.module }}/pom.xml --batch-mode clean install
- name: Maven release
if: ${{ inputs.snapshot-release == false }}
run: |
git config --global user.email "github-actions@github.com"
git config --global user.name "GitHub Actions"
mvn release:prepare -f ./${{ inputs.module }}/pom.xml -B -DreleaseVersion=${{ inputs.release-version }} -DdevelopmentVersion=${{ inputs.next-version }} -DpushChanges=false -DremoteTagging=false
mvn release:perform -f ./${{ inputs.module }}/pom.xml -DlocalCheckout=true
env:
SIGN_KEY_PASS: ${{ secrets.gpg_passphrase }}
CENTRAL_USERNAME: ${{ secrets.sonatype_username }}
CENTRAL_PASSWORD: ${{ secrets.sonatype_password }}
- name: "Upload target artifacts"
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6
with:
name: target
path: "**/target"
retention-days: 5
- name: Push changes to new branch
if: ${{ inputs.snapshot-release == false }}
run: |
git checkout -b ${{ github.ref_name }}-version-bump
git push --force origin ${{ github.ref_name }}-version-bump
- name: Create pull request
if: ${{ inputs.snapshot-release == false }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const { repo, owner } = context.repo;
const pullResult = await github.rest.pulls.create({
title: 'chore: bump release version ${{ github.ref_name }}',
owner,
repo,
head: '${{ github.ref_name }}-version-bump',
base: '${{ github.ref_name }}',
body: [
'This PR is auto-generated'
].join('\n')
});
await github.rest.issues.addAssignees({
owner,
repo,
issue_number: pullResult.data.number,
assignees: ['${{ github.actor }}'],
});
console.log(`Pull Request created: ${pullResult.data.html_url}`);
gpg-passphrase: ${{ secrets.gpg_passphrase }}
sonatype-username: ${{ secrets.sonatype_username }}
sonatype-password: ${{ secrets.sonatype_password }}

build-images:
if: inputs.build-images == true
Expand Down

0 comments on commit fcc8f7a

Please sign in to comment.