From d4fe837562ad0133e5a76ed00b245bc0e521f733 Mon Sep 17 00:00:00 2001 From: Sebastian Becker Date: Fri, 28 Jul 2023 08:44:05 +0200 Subject: [PATCH] fix: introduce release-please process (#34) Signed-off-by: Sebastian Becker --- .github/scripts/generate-changelog.sh | 66 ------------- ...and-test.yaml => java.build-and-test.yaml} | 35 +++++-- .github/workflows/java.publish.yaml | 68 +++++++++++++ .github/workflows/publish-and-release.yaml | 99 ------------------- .github/workflows/release.yaml | 21 ++++ .pre-commit-config.yaml | 12 ++- .release-please-manifest.json | 3 + README.md | 1 + pom.xml | 20 ++-- release-please-config.json | 13 +++ 10 files changed, 156 insertions(+), 182 deletions(-) delete mode 100755 .github/scripts/generate-changelog.sh rename .github/workflows/{build-and-test.yaml => java.build-and-test.yaml} (59%) create mode 100644 .github/workflows/java.publish.yaml delete mode 100644 .github/workflows/publish-and-release.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 .release-please-manifest.json create mode 100644 release-please-config.json diff --git a/.github/scripts/generate-changelog.sh b/.github/scripts/generate-changelog.sh deleted file mode 100755 index bde794b..0000000 --- a/.github/scripts/generate-changelog.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash - -# -# Copyright (c) 2021 - for information on the respective copyright owner -# see the NOTICE file and/or the repository https://github.com/carbynestack/cli. -# -# SPDX-License-Identifier: Apache-2.0 -# - -if [[ -z "${VERSION}" ]]; then - echo "Artifact version must be defined in env variable \"VERSION\"" - exit -1 -fi - -if [[ -z "${GITHUB_WORKSPACE}" ]]; then - echo "Repository base directory must be defined in env variable \"GITHUB_WORKSPACE\"" - exit -2 -fi - -tmpChangelog=/tmp/cs.repository-changelog.${VERSION} -touch $tmpChangelog - -appendGitLog() { - recentTag=$(git describe --tags --abbrev=0) - if (( $? != 0 )); then - git log --all --format="- %s" --no-merges >> $1 - else - git log ${recentTag}..HEAD --format="- %s" --no-merges >> $1 - fi - echo -e "" >> $1 -} - -appendMavenArtifactRefs() { - if [ ! -f "${GITHUB_WORKSPACE}/pom.xml" ]; then - echo "Project is not a Maven project" - return - fi - - maven_artifacts=($(cd ${GITHUB_WORKSPACE} && cat pom.xml| grep -E "(.*)" | sed 's/<.*>\(.*\)<\/.*>/\1/g')) - - if [ ${#maven_artifacts[@]} -eq 0 ]; then - echo "No Maven modules found - apparently single module project" - maven_artifacts=($(cd ${GITHUB_WORKSPACE} && cat pom.xml| grep -m 1 -E "(.*)" | sed 's/<.*>\(.*\)<\/.*>/\1/g')) - fi - if [ ${#maven_artifacts[@]} -eq 0 ]; then - echo "No Maven artifact found" - return - fi - - echo -e "## Maven Artifacts\n" >> $1 - for artifact in ${maven_artifacts[@]}; do - echo -e "### ${artifact}" >> $1 - echo -e "\`\`\`xml" >> $1 - echo -e "" >> $1 - echo -e " io.carbynestack" >> $1 - echo -e " ${artifact}" >> $1 - echo -e " ${VERSION}" >> $1 - echo -e "" >> $1 - echo -e "\`\`\`" >> $1 - done -} - -echo -e "# Change Log\n" > $tmpChangelog - -appendGitLog $tmpChangelog -appendMavenArtifactRefs $tmpChangelog diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/java.build-and-test.yaml similarity index 59% rename from .github/workflows/build-and-test.yaml rename to .github/workflows/java.build-and-test.yaml index 39fb6a1..a3e2d99 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/java.build-and-test.yaml @@ -1,5 +1,5 @@ # -# Copyright (c) 2021 - for information on the respective copyright owner +# Copyright (c) 2021-2023 - for information on the respective copyright owner # see the NOTICE file and/or the repository https://github.com/carbynestack/cli. # # SPDX-License-Identifier: Apache-2.0 @@ -14,18 +14,19 @@ on: branches: - 'master' jobs: - test: - runs-on: ubuntu-20.04 + build: + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - name: Checkout repository + uses: actions/checkout@v3 - name: Set up JDK 11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: java-version: '11' distribution: 'temurin' cache: 'maven' - name: Setting up Github Package Repository as Maven Repository - uses: s4u/maven-settings-action@v2 + uses: s4u/maven-settings-action@v2.8.0 with: githubServer: false servers: | @@ -36,6 +37,28 @@ jobs: }] - name: Build with Maven run: mvn install -Dskip.tests --batch-mode --update-snapshots --no-transfer-progress + test: + runs-on: ubuntu-22.04 + needs: build + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + cache: 'maven' + - name: Setting up Github Package Repository as Maven Repository + uses: s4u/maven-settings-action@v2.8.0 + with: + githubServer: false + servers: | + [{ + "id": "github", + "username": "${{ github.actor }}", + "password": "${{ secrets.GITHUB_TOKEN }}" + }] - name: Run Tests run: mvn verify --activate-profiles coverage --batch-mode --no-transfer-progress - name: Collect Jacoco reports diff --git a/.github/workflows/java.publish.yaml b/.github/workflows/java.publish.yaml new file mode 100644 index 0000000..659e236 --- /dev/null +++ b/.github/workflows/java.publish.yaml @@ -0,0 +1,68 @@ +# +# Copyright (c) 2021-2023 - for information on the respective copyright owner +# see the NOTICE file and/or the repository https://github.com/carbynestack/cli. +# +# SPDX-License-Identifier: Apache-2.0 +# +name: Publish and Release +on: + push: + tags: + - "cli-v[0-9]+.[0-9]+.[0-9]+" +jobs: + publish: + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Retrieve license obligation resources + id: license-obligations + run: | + cd 3RD-PARTY-LICENSES + FILES=$(find . -maxdepth 1 -type d -not -path .) + if [ -n "$FILES" ] + then + echo "${FILES}" | zip -r@ 3rd-party-copyrights + fi + find . -iname origin.src | \ + awk '{ \ + split($0,b,"/"); \ + system("xargs < " $0 " curl --create-dirs -Lo ./sources/" b[2] ".zip " $2)}' && \ + find -regex './sources$' | awk '{system("zip -jr ./3rd-party-sources.zip " $0)}' + mkdir -p ../license-obligations + ARCHIVES=$(find . -regex "^./3rd-party-.*.zip$") + OBLIGATIONS_FOUND="false" + if [ -n "$ARCHIVES" ] + then + mv $(echo "${ARCHIVES}") ../license-obligations/ + OBLIGATIONS_FOUND="true" + fi + echo "OBLIGATIONS_FOUND=${OBLIGATIONS_FOUND}" >> $GITHUB_OUTPUT + - name: Update Release with license obligations resources + uses: ncipollo/release-action@v1 + if: steps.license-obligations.outputs.OBLIGATIONS_FOUND == 'true' + with: + allowUpdates: true + artifacts: license-obligations/* + artifactErrorsFailBuild: true + makeLatest: true + omitBodyDuringUpdate: true + omitNameDuringUpdate: true + - name: Setup java + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + cache: 'maven' + - name: Setting up Github Package Repository as Maven Repository + uses: s4u/maven-settings-action@v2.8.0 + with: + githubServer: false + servers: | + [{ + "id": "github", + "username": "${{ secrets.GHPR_USERNAME }}", + "password": "${{ secrets.GHPR_TOKEN }}" + }] + - name: Publish version to GitHub Packages + run: mvn deploy -Dskip.tests --batch-mode --no-transfer-progress diff --git a/.github/workflows/publish-and-release.yaml b/.github/workflows/publish-and-release.yaml deleted file mode 100644 index bcd9a4f..0000000 --- a/.github/workflows/publish-and-release.yaml +++ /dev/null @@ -1,99 +0,0 @@ -# -# Copyright (c) 2021 - for information on the respective copyright owner -# see the NOTICE file and/or the repository https://github.com/carbynestack/cli. -# -# SPDX-License-Identifier: Apache-2.0 -# -name: Publish and release -on: - workflow_run: - workflows: ["Build and test artifacts"] - branches: - - master - types: - - completed - workflow_dispatch: - -jobs: - prepare: - if: ${{ github.event.workflow_run.conclusion == 'success' }} - runs-on: ubuntu-20.04 - outputs: - VERSION: "${{ steps.maven-project.outputs.version }}-${{ github.run_id }}-${{ github.run_number }}-${{ steps.short-sha.outputs.sha }}" - steps: - - name: Parse short sha - uses: benjlevesque/short-sha@v1.2 - id: short-sha - - uses: actions/checkout@v2 - - name: Get Maven project version - run: echo ::set-output name=version::$(cat pom.xml| grep -m 1 -E "(.*)" | sed 's/.*<.*>\(.*\)<\/.*>/\1/g') - id: maven-project - draft-release: - runs-on: ubuntu-20.04 - needs: [prepare] - env: - VERSION: "${{ needs.prepare.outputs.VERSION }}" - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - name: Retrieve license obligation resources - run: | - cd 3RD-PARTY-LICENSES - find . -maxdepth 1 -type d -not -path . | zip -r@ ${GITHUB_REPOSITORY#*/}-3rd-party-copyrights - find . -iname origin.src | \ - awk '{ \ - split($0,b,"/"); \ - system("xargs < " $0 " curl --create-dirs -Lo ./sources/" b[2] ".zip " $2)}' && \ - find -regex './sources$' | awk '{system("zip -jr ./${GITHUB_REPOSITORY#*/}-3rd-party-sources.zip " $0)}' - mkdir -p ../license-obligations && mv `find . -regex "^./${GITHUB_REPOSITORY#*/}-3rd-party-.*.zip$"` ../license-obligations/ - cd - - - name: Generate change log - run: | - chmod +x .github/scripts/generate-changelog.sh - ./.github/scripts/generate-changelog.sh - - name: Create release tag - run: | - git tag ${{ env.VERSION }} - git push --tags - - name: Create draft - uses: ncipollo/release-action@v1 - with: - tag: ${{ env.VERSION }} - draft: true - bodyFile: /tmp/cs.repository-changelog.${{ env.VERSION }} - artifacts: "license-obligations/*" - publish: - runs-on: ubuntu-20.04 - needs: [prepare,draft-release] - env: - VERSION: "${{ needs.prepare.outputs.VERSION }}" - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-java@v2 - with: - java-version: '11' - distribution: 'temurin' - cache: 'maven' - - name: Setting up Github Package Repository as Maven Repository - uses: s4u/maven-settings-action@v2 - with: - githubServer: false - servers: | - [{ - "id": "github", - "username": "${{ secrets.GHPR_USERNAME }}", - "password": "${{ secrets.GHPR_TOKEN }}" - }] - - name: Update Maven project version - run: mvn versions:set -DnewVersion=${{ env.VERSION }} -DprocessAllModules -DgenerateBackupPoms=false - - name: Build artifact - run: mvn package -Dskip.tests --batch-mode --no-transfer-progress - - name: Publish release - uses: ncipollo/release-action@v1 - with: - tag: ${{ env.VERSION }} - allowUpdates: true - draft: false - omitBodyDuringUpdate: true - artifacts: "target/cli-${{ env.VERSION }}-jar-with-dependencies.jar" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..6661ae8 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,21 @@ +# +# Copyright (c) 2023 - for information on the respective copyright owner +# see the NOTICE file and/or the repository https://github.com/carbynestack/cli. +# +# SPDX-License-Identifier: Apache-2.0 +# +name: Release +on: + push: + branches: + - master +jobs: + release-please: + runs-on: ubuntu-22.04 + steps: + - name: Release Please + uses: google-github-actions/release-please-action@v3 + with: + command: manifest + signoff: "cs-minion " + token: ${{ secrets.CS_MINION_PAT }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5a5d328..6d429a3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,10 +1,18 @@ # -# Copyright (c) 2021 - for information on the respective copyright owner +# Copyright (c) 2021-2023 - for information on the respective copyright owner # see the NOTICE file and/or the repository https://github.com/carbynestack/cli. # # SPDX-License-Identifier: Apache-2.0 # repos: +- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook + rev: v9.5.0 + hooks: + - id: commitlint + stages: + - commit-msg + additional_dependencies: + - '@commitlint/config-conventional' - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 hooks: @@ -31,4 +39,4 @@ repos: rev: v0.33.0 hooks: - id: markdownlint - exclude: ^README.md$ + exclude: ^README.md$|.*/3RD-PARTY-LICENSES/.* diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..0ee8c01 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "0.3.0" +} diff --git a/README.md b/README.md index 9d3afab..cbb5edf 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![codecov](https://codecov.io/gh/carbynestack/cli/branch/master/graph/badge.svg?token=ja4W6WLOHO)](https://codecov.io/gh/carbynestack/cli) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/67fd8c2ab94f4756a0d5cfc326ac0567)](https://www.codacy.com?utm_source=github.com&utm_medium=referral&utm_content=carbynestack/cli&utm_campaign=Badge_Grade) +[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org) [![Known Vulnerabilities](https://snyk.io/test/github/carbynestack/cli/badge.svg)](https://snyk.io/test/github/carbynestack/cli) [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md) diff --git a/pom.xml b/pom.xml index b8d2f84..04acd4d 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ 4.0.0 cli io.carbynestack - 0.3-SNAPSHOT + 0.3.0 Carbyne Stack Command Line Interface Carbyne Stack Command Line Interface for interacting with backend services. @@ -60,9 +60,11 @@ 2.0.0 - 0.1-SNAPSHOT-4205214333-22-2fa009a - 0.1-SNAPSHOT-4191841095-22-1721229 - 0.1-SNAPSHOT-2804677120-20-efc7f8d + 0.1-SNAPSHOT-4205214333-22-2fa009a + 0.1-SNAPSHOT-4191841095-22-1721229 + 0.1-SNAPSHOT-4191841095-22-1721229 + 0.1-SNAPSHOT-4191841095-22-1721229 + 0.1-SNAPSHOT-2804677120-20-efc7f8d 2.11.0 @@ -88,27 +90,27 @@ io.carbynestack amphora-java-client - ${amphora.version} + ${amphora-java-client.version} io.carbynestack castor-common - ${castor.version} + ${castor-common.version} io.carbynestack castor-java-client - ${castor.version} + ${castor-java-client.version} io.carbynestack castor-upload-java-client - ${castor.version} + ${castor-upload-java-client.version} io.carbynestack ephemeral-java-client - ${ephemeral.version} + ${ephemeral-java-client.version} diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..7eec356 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,13 @@ +{ + "bump-minor-pre-major": true, + "separate-pull-requests": true, + "pull-request-title-pattern": "chore: release ${component} ${version}", + "pull-request-header": ":package: Staging a new release", + "skip-snapshot": true, + "packages": { + ".": { + "package-name": "cli", + "release-type": "maven" + } + } +}