Skip to content

Commit

Permalink
build(release): add release script
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Romero Montes <rromerom@redhat.com>
  • Loading branch information
ruromero committed Nov 15, 2023
1 parent 2bf775a commit 0b479ca
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
27 changes: 0 additions & 27 deletions .github/workflows/publish.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The packages are published to the GitHub maven repository. Make sure to add it t
<dependency>
<groupId>com.redhat.ecosystemappeng</groupId>
<artifactId>exhort-api</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>1.0.9-SNAPSHOT</version>
</dependency>
```

Expand All @@ -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.9-SNAPSHOT
```
75 changes: 75 additions & 0 deletions perform_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/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 clean deploy -Ppublish -Prelease
}

git_push() {
for remote in `git remote`; do
if [ "upstream" = ${remote} ]; then
print_message "push to ${remote} ${1}"
git push ${remote} ${1}
fi
done
}

git_commit() {
print_message "Commit: $1"
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 -s v${version} -m "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 package -Ppublish
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:-''}
107 changes: 57 additions & 50 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
<maven-invoker-plugin.version>3.2.2</maven-invoker-plugin.version>
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
<maven-javadoc-plugin.version>3.4.1</maven-javadoc-plugin.version>
<maven-release-plugin.version>3.0.0</maven-release-plugin.version>
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
<maven-surefire-plugin.version>3.0.0</maven-surefire-plugin.version>
Expand Down Expand Up @@ -179,17 +178,6 @@
<doclint>all,-missing</doclint>
</configuration>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>${maven-release-plugin.version}</version>
<configuration>
<scmCommentPrefix>build(release): </scmCommentPrefix>
<signTag>true</signTag>
<goals>install</goals>
<tagNameFormat>v@{project.version}</tagNameFormat>
<completionGoals>clean package</completionGoals>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
Expand Down Expand Up @@ -576,10 +564,67 @@ limitations under the License.]]>
</build>

<profiles>
<profile>
<id>publish</id>
<build>
<plugins>
<!-- flatten-maven-plugin:flatten is bound to the process-resources phase and will create
a .flattened-pom.xml -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- source:jar is bound to the generate-sources phase and will create a sources jar -->
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- javadoc:jar is bound to the generate-sources phase and will create a javadoc jar -->
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
Expand Down Expand Up @@ -630,46 +675,8 @@ limitations under the License.]]>
<installDirectory>target</installDirectory>
</configuration>
</plugin>
<!-- flatten-maven-plugin:flatten is bound to the process-resources phase and will create
a .flattened-pom.xml -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- source:jar is bound to the generate-sources phase and will create a sources jar -->
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- javadoc:jar is bound to the generate-sources phase and will create a javadoc jar -->
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

</profiles>
</project>
2 changes: 1 addition & 1 deletion src/filtered/js-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"lint": "eslint model/**/* --ext js --fix",
"precompile": "rm -rf dist && npm run lint",
"compile": "tsc -p tsconfig.json",
"publish:snapshot": "npm version prerelease --preid ${timestamp} && npm publish --tag ${timestamp}"
"publish:snapshot": "npm version prerelease --preid ${timestamp} && npm publish --tag snapshot"
},
"keywords": [
"analysis",
Expand Down

0 comments on commit 0b479ca

Please sign in to comment.