Skip to content

Commit

Permalink
Add release workflow (#414)
Browse files Browse the repository at this point in the history
* Add release workflow

* Fix version

* Create github release

* Skip branch condition for testing

* Add shellcheck

* Fix token for gh release

* Deploy to maven central

* Finish release workflow

* Update dependencies

* Describe new release process

* Update release notes

* Mark variables as read-only

* Implement review findings

* Implement review findings

* Update release date

---------

Co-authored-by: kaklakariada <[email protected]>
  • Loading branch information
kaklakariada and kaklakariada authored Jun 3, 2024
1 parent c6af4ab commit 8c2c443
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 56 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ jobs:
path: target/self-trace-report.html
if-no-files-found: error

- name: Check shell scripts
if: ${{ env.DEFAULT_OS == matrix.os && env.DEFAULT_JAVA == matrix.java }}
run: .github/workflows/run_shellcheck.sh

build:
needs: matrix-build
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/github_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail

base_dir="$( cd "$(dirname "$0")/../.." >/dev/null 2>&1 ; pwd -P )"
readonly base_dir
readonly pom_file="$base_dir/parent/pom.xml"

# Read project version from pom file
project_version=$(grep "<revision>" "$pom_file" | sed --regexp-extended 's/\s*<revision>(.*)<\/revision>\s*/\1/g')
readonly project_version
echo "Read project version '$project_version' from $pom_file"

# Calculate checksum
readonly artifact_path="$base_dir/product/target/openfasttrace-${project_version}.jar"
echo "Calculate sha256sum for file '$artifact_path'"
file_dir="$(dirname "$artifact_path")"
readonly file_dir
file_name=$(basename "$artifact_path")
readonly file_name
cd "$file_dir"
readonly checksum_file_name="${file_name}.sha256"
sha256sum "$file_name" > "$checksum_file_name"
readonly checksum_file_path="$file_dir/$checksum_file_name"
cd "$base_dir"


# Create GitHub release
readonly changes_file="$base_dir/doc/changes/changes_${project_version}.md"
notes=$(cat "$changes_file")
readonly notes

readonly title="Release $project_version"
readonly tag="$project_version"
echo "Creating release:"
echo "Git tag : $tag"
echo "Title : $title"
echo "Changes file : $changes_file"
echo "Artifact file: $artifact_path"
echo "Checksum file: $checksum_file_path"

release_url=$(gh release create --latest --title "$title" --notes "$notes" --target main "$tag" "$artifact_path" "$checksum_file_path")
readonly release_url
echo "Release URL: $release_url"
55 changes: 51 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,63 @@
name: Release on Maven Central and GitHub
name: Release

on:
workflow_dispatch:
inputs:
deploy-maven-central:
description: "Deploy to Maven Central"
skip-deploy-maven-central:
description: "Skip deployment to Maven Central"
required: true
type: boolean
default: false

jobs:
release:
runs-on: ubuntu-latest
defaults:
run:
shell: "bash"
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
permissions:
contents: write # Required for creating GitHub release
steps:
- run: echo "Dummy workflow for testing"
- name: Checkout
uses: actions/checkout@v4

- name: Fail if not running on main branch
if: ${{ github.ref != 'refs/heads/main' }}
uses: actions/github-script@v7
with:
script: |
core.setFailed('Not running on main branch, github.ref is ${{ github.ref }}. Please start this workflow only on main')
- name: Set up Maven Central Repository
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: 17
cache: "maven"
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE

- name: Build
run: mvn --batch-mode -T 1C clean install

- name: List secret GPG keys
run: gpg --list-secret-keys

- name: Publish to Maven Central Repository
if: ${{ !inputs.skip-deploy-maven-central }}
run: mvn --batch-mode deploy -Possrh -DstagingDescription="Deployed via GitHub workflow release.yml"
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}

- name: Create GitHub Release
run: ./.github/workflows/github_release.sh
env:
GH_TOKEN: ${{ github.token }}
14 changes: 14 additions & 0 deletions .github/workflows/run_shellcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail

base_dir="$( cd "$(dirname "$0")/../.." >/dev/null 2>&1 ; pwd -P )"

shellcheck --enable=all --severity=warning --check-sourced --color=auto \
"$base_dir/.github/workflows/run_shellcheck.sh" \
"$base_dir/.github/workflows/github_release.sh" \
"$base_dir/oft" \
"$base_dir/oft-self-trace.sh"

6 changes: 4 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"recommendations": [
"vscjava.vscode-java-pack"
"vscjava.vscode-java-pack",
"sonarsource.sonarlint-vscode",
"timonwong.shellcheck"
],
}
}
3 changes: 2 additions & 1 deletion doc/changes/changes_4.0.0.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# OpenFastTrace 4.0.0, released 2024-04-??
# OpenFastTrace 4.0.0, released 2024-04-03

Code name: RST Importer

Expand Down Expand Up @@ -48,3 +48,4 @@ has now been removed from the Markdown format. Please migrate to OFT's native fo
## Features

* #378: Added an RST importer
* #412: Added automatic release for Maven Central and GitHub
53 changes: 7 additions & 46 deletions doc/developer_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,35 +206,6 @@ The build will use the last Git commit timestamp as timestamp for files in `.jar

**NOTE**: This currently only works for release version numbers, not SNAPSHOT versions.

### One-time Setup

Add the following to your `~/.m2/settings.xml`:

```xml
<settings>
<servers>
<server>
<id>ossrh</id>
<username>your-jira-id</username>
<password>your-jira-pwd</password>
</server>
</servers>
<profiles>
<profile>
<id>ossrh</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>gpg</gpg.executable>
<gpg.keyname>key_id</gpg.keyname>
<gpg.passphrase>the_pass_phrase</gpg.passphrase>
</properties>
</profile>
</profiles>
</settings>
```

### Prepare the Release

1. Checkout the `main` branch.
Expand All @@ -244,23 +215,13 @@ Add the following to your `~/.m2/settings.xml`:
* `README.md`
* `doc/developer_guide.md`
4. Add changes in new version to `doc/changes/changes.md` and `doc/changes/changes_$VERSION.md` and update the release date.
5. Verify that build runs successfully:

```bash
mvn clean verify
```
6. Commit and push changes.
7. Create a new Pull Request, have it reviewed and merged.
5. Commit and push changes.
6. Create a new pull request, have it reviewed and merged to `main`.

### Perform the Release

1. Checkout `main` and get the latest changes.
1. Run this command

```bash
mvn clean deploy -Possrh
```
1. Create a [release](https://github.com/itsallcode/openfasttrace/releases) of the `main` branch on GitHub.
1. Copy the changelog entries for the new version to the GitHub release.
1. Upload `product/target/openfasttrace-<version>.jar` and attach it to the new GitHub release.
1. After some time the release will be available at [Maven Central](https://repo1.maven.org/maven2/org/itsallcode/openfasttrace/openfasttrace/).
1. Start the release workflow
* Run command `gh workflow run release.yml --repo itsallcode/openfasttrace --ref main`
* or go to [GitHub Actions](https://github.com/itsallcode/openfasttrace/actions/workflows/release.yml) and start the `release.yml` workflow on branch `main`.
2. Update title and description of the newly created [GitHub release](https://github.com/itsallcode/openfasttrace/releases).
3. After some time the release will be available at [Maven Central](https://repo1.maven.org/maven2/org/itsallcode/openfasttrace/openfasttrace/).
1 change: 1 addition & 0 deletions oft
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ if [ ! -f "$jar_file" ]; then
exit 1
fi

# shellcheck disable=SC2068 # Double quote to prevent globbing
java -jar "$jar_file" $@
6 changes: 3 additions & 3 deletions parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<properties>
<revision>4.0.0</revision>
<java.version>17</java.version>
<junit.version>5.11.0-M1</junit.version>
<junit.version>5.11.0-M2</junit.version>
<maven.surefire.version>3.2.5</maven.surefire.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand Down Expand Up @@ -216,7 +216,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.11.0</version>
<version>5.12.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -656,7 +656,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<version>1.7.0</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand Down

0 comments on commit 8c2c443

Please sign in to comment.