Skip to content

Commit

Permalink
feat: 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 b540e2d
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 56 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 }}
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
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.5-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.5-SNAPSHOT
```
76 changes: 76 additions & 0 deletions perform_release.sh
Original file line number Diff line number Diff line change
@@ -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:-''}
116 changes: 65 additions & 51 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.redhat.ecosystemappeng</groupId>
<artifactId>exhort-api-spec</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>1.0.4-SNAPSHOT</version>
<name>Exhort Java API</name>
<description>Red Hat Trusted Profile Analizer :: Exhort :: Java API</description>
<url>https://github.com/RHEcosystemAppEng/exhort-api-spec</url>
Expand Down 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,6 +564,70 @@ limitations under the License.]]>
</build>

<profiles>
<profile>
<id>signed-jars</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>
</plugins>
</build>
</profile>
<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>
Expand Down Expand Up @@ -630,46 +682,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>

0 comments on commit b540e2d

Please sign in to comment.