Skip to content

Commit

Permalink
build: workflow optimization (#1255)
Browse files Browse the repository at this point in the history
* build: replace push to main with PR

* build: make maven cache reusable between runs

* build: improve release branch PR creation

* build: run mvn test on feature branches instead of mvn verify
  • Loading branch information
chillleader authored Oct 9, 2023
1 parent 32dccf0 commit c9fdcf4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 30 deletions.
57 changes: 33 additions & 24 deletions .github/workflows/CREATE_RELEASE_BRANCH.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@ on:
workflow_dispatch:
inputs:
version:
description: 'Semantic version number of release: ^[0-9]+.[0-9]+.[0-9]+(-[a-zA-Z0-9.-]+){0,1}$'
description: 'Full semantic version number of the next minor release, e.g. 8.4.0'
required: true
setVersionOnMain:
description: 'Set the new snapshot version on main branch?'
type: boolean
required: true
default: true

jobs:
create-release-branch:
Expand All @@ -24,46 +19,60 @@ jobs:
ref: ${{ github.event.inputs.branch }}
fetch-depth: 0

- name: Restore cache
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Prepare Java and Maven settings
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'

- name: Configure git user
run: |
# https://github.com/actions/checkout/issues/13#issuecomment-724415212
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Set snapshot version on main branch
if: ${{ github.event.inputs.setVersionOnMain == 'true' }}
run: |
git checkout main
mvn -B versions:set -DnewVersion=${RELEASE_VERSION}-SNAPSHOT -DgenerateBackupPoms=false -f parent
git add parent/pom.xml
git commit -am "ci: set next snapshot version"
git push
env:
RELEASE_VERSION: ${{ github.event.inputs.version }}

- name: Create branch and set release version
id: create-branch
run: |
MINOR_VERSION=${RELEASE_VERSION%.*}
git checkout -b release/${MINOR_VERSION}
git push --set-upstream origin release/${MINOR_VERSION}
echo "branchName=release/${RELEASE_VERSION%.*}" >> $GITHUB_OUTPUT
env:
RELEASE_VERSION: ${{ github.event.inputs.version }}

- name: Set snapshot version on release branch (if not set on main)
if: ${{ github.event.inputs.setVersionOnMain == 'false' }}
- name: Set snapshot version on release branch
run: |
MINOR_VERSION=${RELEASE_VERSION%.*}
git checkout release/${MINOR_VERSION}
mvn -B versions:set -DnewVersion=${RELEASE_VERSION}-SNAPSHOT -DgenerateBackupPoms=false -f parent
git add parent/pom.xml
git commit -am "ci: set next snapshot version"
git push
env:
RELEASE_VERSION: ${{ github.event.inputs.version }}

- name: Create pull request to main branch
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ steps.create-branch.outputs.branchName }}
commit-message: "ci: set next snapshot version"
committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
base: main
title: "ci: set next snapshot version"
body: |
This PR sets the next snapshot version on the main branch.
Checklist:
- [ ] the PR should be accepted via the "Rebase and merge" option
- [ ] the branch must **not** be deleted after merging
- [ ] the PR contains exactly one commit with the version change
If this PR has conflicts, re-run the `Create release branch` workflow. No need to close the PR or delete the branch.
env:
RELEASE_VERSION: ${{ github.event.inputs.version }}
11 changes: 9 additions & 2 deletions .github/workflows/DEPLOY_SNAPSHOTS.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,19 @@ jobs:
secret/data/products/connectors/ci/common ARTIFACTORY_USR;
secret/data/products/connectors/ci/common ARTIFACTORY_PSW;
- name: Restore cache
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Setup Java Build
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
server-id: camunda-nexus
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
Expand All @@ -53,7 +60,7 @@ jobs:
mirrors: '[{"url": "https://repository.nexus.camunda.cloud/content/groups/internal/", "id": "camunda-nexus", "mirrorOf": "camunda-nexus", "name": "camunda Nexus"}]'

- name: Build Artifacts
run: mvn -B compile generate-sources source:jar javadoc:jar deploy
run: mvn -B compile generate-sources source:jar javadoc:jar deploy -DskipTests
env:
MAVEN_USERNAME: ${{ steps.secrets.outputs.ARTIFACTORY_USR }}
MAVEN_PASSWORD: ${{ steps.secrets.outputs.ARTIFACTORY_PSW }}
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/RELEASE.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,19 @@ jobs:
gpg_private_key: ${{ steps.secrets.outputs.MAVEN_CENTRAL_GPG_SIGNING_KEY_SEC }}
passphrase: ${{ steps.secrets.outputs.MAVEN_CENTRAL_GPG_SIGNING_KEY_PASSPHRASE }}

- name: Restore cache
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Prepare Java and Maven settings
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'

# Use CI Nexus as co-located pull-through cache for Maven artifacts via ~/.m2/settings.xml
- name: 'Create settings.xml'
Expand Down Expand Up @@ -104,7 +111,7 @@ jobs:
RELEASE_VERSION: ${{ github.event.release.tag_name }}

- name: Deploy artifacts to Artifactory and Maven Central
run: mvn -B compile generate-sources source:jar javadoc:jar deploy -PcheckFormat -Psonatype-oss-release -DskipTests
run: mvn -B compile generate-sources source:jar javadoc:jar deploy -PcheckFormat -Psonatype-oss-release
env:
NEXUS_USR: ${{ steps.secrets.outputs.ARTIFACTORY_USR }}
NEXUS_PSW: ${{ steps.secrets.outputs.ARTIFACTORY_PSW }}
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/TEST_FEATURE_BRANCH.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ jobs:
secret/data/products/connectors/ci/common ARTIFACTORY_USR;
secret/data/products/connectors/ci/common ARTIFACTORY_PSW;
- name: Restore cache
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'

# Use CI Nexus as co-located pull-through cache for Maven artifacts via ~/.m2/settings.xml
- name: 'Create settings.xml'
Expand All @@ -49,7 +56,7 @@ jobs:
node-version: '16'

- name: Build Connectors
run: mvn --batch-mode clean verify -PcheckFormat
run: mvn --batch-mode clean test -PcheckFormat

- name: Lint Dockerfile - connector-runtime
uses: hadolint/[email protected]
Expand Down

0 comments on commit c9fdcf4

Please sign in to comment.