From b540e2d104eb884d34aff1c5c46cd6071a6e76a2 Mon Sep 17 00:00:00 2001 From: Ruben Romero Montes Date: Wed, 15 Nov 2023 16:35:49 +0100 Subject: [PATCH] feat: add release script Signed-off-by: Ruben Romero Montes --- .github/workflows/ci.yaml | 2 +- .github/workflows/cicd.yaml | 2 +- .github/workflows/publish.yaml | 2 +- README.md | 4 +- perform_release.sh | 76 +++++++++++++++++++++ pom.xml | 116 ++++++++++++++++++--------------- 6 files changed, 146 insertions(+), 56 deletions(-) create mode 100755 perform_release.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e1941ab..b4d7456 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -25,7 +25,7 @@ jobs: java-version: '17' distribution: 'temurin' - name: Build with Maven - run: mvn -B test --file pom.xml + run: mvn -B verify --file pom.xml openapi-lint-checks: runs-on: ubuntu-latest name: OpenAPI Linter diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml index 4af2de5..244f1ef 100644 --- a/.github/workflows/cicd.yaml +++ b/.github/workflows/cicd.yaml @@ -54,6 +54,6 @@ jobs: - name: Set NPM auth token run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc - name: Build and Publish to GitHub Maven Packages - run: mvn -B deploy --file pom.xml + run: mvn -B deploy -Ppublish --file pom.xml env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index ec2f0c8..6a0bf28 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -22,6 +22,6 @@ jobs: - name: Set NPM auth token run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc - name: Build and Publish to GitHub Maven Packages - run: mvn -B deploy -Prelease --file pom.xml + run: mvn -B deploy -Prelease -Ppublish --file pom.xml env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/README.md b/README.md index d32da92..762939d 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ The packages are published to the GitHub maven repository. Make sure to add it t com.redhat.ecosystemappeng exhort-api - 1.0.1-SNAPSHOT + 1.0.5-SNAPSHOT ``` @@ -36,5 +36,5 @@ echo "@RHEcosystemAppEng:registry=https://npm.pkg.github.com" >> .npmrc Then, add it to your project as follows: ```bash -npm install @RHEcosystemAppEng/exhort-javascript-api@1.0.1-SNAPSHOT +npm install @RHEcosystemAppEng/exhort-javascript-api@1.0.5-SNAPSHOT ``` \ No newline at end of file diff --git a/perform_release.sh b/perform_release.sh new file mode 100755 index 0000000..6edcca1 --- /dev/null +++ b/perform_release.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +set -euo pipefail + +RED='\033[0;31m' # Red Color +GREEN='\033[0;32m' # Green Color +NC='\033[0m' # No Color + +print_message() { + echo -e "${GREEN}${1}${NC}" +} + +remove_snapshot() { + print_message "Removing snapshot from pom" + mvn -B versions:set -DremoveSnapshot -DgenerateBackupPoms=false + mvn -B clean package +} + +git_push() { + remotes = `git remote` + expected_remotes=("upstream" "origin") + for remote in "${remotes[@]}"; do + if [[ ${expected_remotes[@]} =~ $remote ]]; then + git push ${remote} ${1} + fi + done +} + +git_commit() { + print_message "Committing messages" + git add . + git commit -sm "build(release): $1" + git_push main +} + +git_tag() { + version=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout` + print_message "Creating tag v${version}" + git tag v${version} + git_push v${version} +} + +next_version() { + version=${1:-} + if [[ ! -z $version ]]; then + echo "Using custom version ${version}" + mvn -B release:update-versions -DnewVersion=${version} + else + echo "Using default version" + mvn -B release:update-versions + fi +} + +perform_release() { + remove_snapshot + git_commit "removed snapshot from version" + git_tag + + next_version ${1:-} + mvn -B clean verify + git_commit "updated next development version" +} + +branch=`git branch --no-color --show-current` +if [ "main" != $branch ]; then + echo -e "${RED}Error: The release must be performed in the main branch. Current: ${branch}" + exit 1 +fi + +if [ ! -z "$(git status --porcelain)"]; then + echo -e "${RED}Error: Make sure all changes are committed" + exit 1 +fi + +print_message "Performing release" +perform_release ${1:-''} diff --git a/pom.xml b/pom.xml index f44884f..f862be9 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.redhat.ecosystemappeng exhort-api-spec - 1.0.1-SNAPSHOT + 1.0.4-SNAPSHOT Exhort Java API Red Hat Trusted Profile Analizer :: Exhort :: Java API https://github.com/RHEcosystemAppEng/exhort-api-spec @@ -34,7 +34,6 @@ 3.2.2 3.3.0 3.4.1 - 3.0.0 3.3.1 3.2.1 3.0.0 @@ -179,17 +178,6 @@ all,-missing - - maven-release-plugin - ${maven-release-plugin.version} - - build(release): - true - install - v@{project.version} - clean package - - maven-resources-plugin ${maven-resources-plugin.version} @@ -576,6 +564,70 @@ limitations under the License.]]> + + signed-jars + + + + org.apache.maven.plugins + maven-gpg-plugin + + + sign-artifacts + verify + + sign + + + + + + + + + publish + + + + + org.codehaus.mojo + flatten-maven-plugin + + + flatten + process-resources + + flatten + + + + + + + maven-source-plugin + + + + jar + + + + + + + maven-javadoc-plugin + + + + jar + + + + + + + release @@ -630,46 +682,8 @@ limitations under the License.]]> target - - - org.codehaus.mojo - flatten-maven-plugin - - - flatten - process-resources - - flatten - - - - - - - maven-source-plugin - - - - jar - - - - - - - maven-javadoc-plugin - - - - jar - - - - -