From c9fdcf4d293d10a8eb551dddb24e56b48c203e00 Mon Sep 17 00:00:00 2001 From: Pavel Kotelevsky <38818382+chillleader@users.noreply.github.com> Date: Mon, 9 Oct 2023 20:09:09 +0200 Subject: [PATCH] build: workflow optimization (#1255) * 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 --- .github/workflows/CREATE_RELEASE_BRANCH.yml | 57 ++++++++++++--------- .github/workflows/DEPLOY_SNAPSHOTS.yaml | 11 +++- .github/workflows/RELEASE.yaml | 11 +++- .github/workflows/TEST_FEATURE_BRANCH.yml | 11 +++- 4 files changed, 60 insertions(+), 30 deletions(-) diff --git a/.github/workflows/CREATE_RELEASE_BRANCH.yml b/.github/workflows/CREATE_RELEASE_BRANCH.yml index 89313416c9..e965e63f57 100644 --- a/.github/workflows/CREATE_RELEASE_BRANCH.yml +++ b/.github/workflows/CREATE_RELEASE_BRANCH.yml @@ -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: @@ -24,12 +19,19 @@ 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: | @@ -37,33 +39,40 @@ jobs: 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 }} diff --git a/.github/workflows/DEPLOY_SNAPSHOTS.yaml b/.github/workflows/DEPLOY_SNAPSHOTS.yaml index a2027cc617..b08c8b6fed 100644 --- a/.github/workflows/DEPLOY_SNAPSHOTS.yaml +++ b/.github/workflows/DEPLOY_SNAPSHOTS.yaml @@ -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 @@ -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 }} diff --git a/.github/workflows/RELEASE.yaml b/.github/workflows/RELEASE.yaml index 8f8fa132f8..42994652ca 100644 --- a/.github/workflows/RELEASE.yaml +++ b/.github/workflows/RELEASE.yaml @@ -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' @@ -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 }} diff --git a/.github/workflows/TEST_FEATURE_BRANCH.yml b/.github/workflows/TEST_FEATURE_BRANCH.yml index 3d87602f6f..22f340ace6 100644 --- a/.github/workflows/TEST_FEATURE_BRANCH.yml +++ b/.github/workflows/TEST_FEATURE_BRANCH.yml @@ -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' @@ -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/hadolint-action@v3.1.0