Skip to content

Commit

Permalink
chore: 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
chensoul committed Dec 7, 2023
1 parent 6fd530c commit 0dccfac
Show file tree
Hide file tree
Showing 7 changed files with 418 additions and 53 deletions.
71 changes: 71 additions & 0 deletions .github/configs/configuration_repo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"categories": [
{
"title": "## 🚀 Features",
"labels": [
"feature",
"minor",
"major"
],
"exclude_labels": [
"fix",
"patch"
]
},
{
"title": "## 🐛 Fixes",
"labels": [
"fix",
"patch"
],
"exclude_labels": [
"feature",
"minor",
"major"
]
},
{
"title": "## 🐛 Wiki",
"labels": [
"wiki"
]
},
{
"title": "## 🐛 Test",
"labels": [
"test"
],
"exclude_labels": [
"feature",
"fix",
"minor",
"patch",
"major"
]
},
{
"title": "## 🧪 Github",
"labels": [
"github"
]
},
{
"title": "## 💬 Other",
"labels": [
"other"
]
},
{
"title": "## 📦 Dependencies",
"labels": [
"dependencies"
]
}
],
"sort": "ASC",
"template": "${{CHANGELOG}}",
"pr_template": "- ${{TITLE}}\n - PR: #${{NUMBER}}",
"empty_template": "- no changes",
"max_pull_requests": 1000,
"max_back_track_time_days": 1000
}
69 changes: 69 additions & 0 deletions .github/workflows/github-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# https://github.com/marketplace/actions/release-changelog-builder
name: 'Github Release'

on:
repository_dispatch:
types: [release-notes]

concurrency:
group: ${{ github.event.pull_request.number }}-ci
cancel-in-progress: true

jobs:
release-notes:
if: github.event.client_payload.auto_release == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get Latest Release Tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "latest_release_tag=$(curl -sL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{github.event.repository.owner.login}}/${{github.event.repository.name}}/releases/latest | jq -r '.tag_name')" >> $GITHUB_ENV
echo "currentTag=$(git describe --tags `git rev-list --tags --max-count=1`)" >> $GITHUB_ENV
- name: Build Changelog
id: github_release
uses: mikepenz/release-changelog-builder-action@v2
with:
configuration: ".github/configs/configuration_repo.json"
fromTag: ${{env.latest_release_tag}}
toTag: ${{env.currentTag}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
uses: softprops/action-gh-release@v1
with:
body: ${{steps.github_release.outputs.changelog}}
tag_name: ${{env.currentTag}}
- name: Artifact Information
id: artifact_information
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
run: |
echo "archive_download_url=$(curl -sSL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{github.event.repository.owner.login}}/${{github.event.repository.name}}/actions/artifacts | jq -r '.artifacts[0].archive_download_url')" >> $GITHUB_ENV
- name: Download Artifact
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
curl -sSL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
${{ env.archive_download_url }} -o ${{ github.event.client_payload.artifact }}.zip
- name: Upload Assets to Release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ github.event.client_payload.artifact }}.zip
tag: ${{env.currentTag}}
81 changes: 81 additions & 0 deletions .github/workflows/maven-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: 'Maven Release'

on:
workflow_dispatch:
inputs:
releaseVersion:
description: "Define the release version"
required: true
default: ""
developmentVersion:
description: "Define the snapshot version"
required: true
default: ""

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Maven Central Repository
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'temurin'
java-package: 'jdk'
cache: 'maven'
server-id: ossrh
- name: Configure Git User
run: |
git config user.email "[email protected]"
git config user.name "GitHub Actions"
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Import GPG Key
uses: crazy-max/[email protected]
with:
gpg_private_key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
- name: Verify Whether a Release is Ready
shell: bash
run: |
if [ "${{ github.event.inputs.releaseVersion }}" != "" ] && [ "${{ github.event.inputs.developmentVersion }}" != "" ]; then
echo "auto_release=true" >> $GITHUB_ENV
else
echo "auto_release=false" >> $GITHUB_ENV
fi
- name: Artifact Version
shell: bash
run: |
echo "artifact_version=$(mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.version -q -DforceStdout)" >> "$GITHUB_ENV"
- name: Release With Maven
run: |
mvn -B -U \
release:prepare \
release:perform \
-DreleaseVersion=${{ github.event.inputs.releaseVersion }} \
-DdevelopmentVersion=${{ github.event.inputs.developmentVersion }} \
deploy \
-s settings.xml \
-Prelease \
-Dgpg.passphrase=${{ secrets.MAVEN_GPG_PASSPHRASE }}
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
AUTO_RELEASE_AFTER_CLOSE: ${{ env.auto_release }}
- name: Artifact Name
shell: bash
run: |
echo "artifact_name=$(mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.artifactId -q -DforceStdout)" >> "$GITHUB_ENV"
echo "${{ env.artifact_name }} ${{ env.artifact_version }}"
ls -al ./target/
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.artifact_name }}-${{ env.artifact_version }}
path: ./target/${{ env.artifact_name }}-${{ env.artifact_version }}.jar
- name: Workflow Release Notes
uses: peter-evans/repository-dispatch@v2
if: ${{ github.event.inputs.releaseVersion }} != "" && ${{ github.event.inputs.developmentVersion }} != ""
with:
event-type: release-notes
client-payload: '{"auto_release": "${{ env.auto_release }}", "artifact": "${{ env.artifact_name }}-${{ env.artifact_version }}"}'
32 changes: 32 additions & 0 deletions .github/workflows/maven-verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: 'Maven Verify'

on:
- 'pull_request'
- 'push'

jobs:
job-mvn-verify:
name: 'Job: Maven Verify'
permissions:
contents: 'read'
runs-on: 'ubuntu-latest'
steps:
- id: 'checkout'
name: 'Step: Checkout'
uses: 'actions/checkout@v4'
with:
fetch-depth: 1
persist-credentials: false
- id: 'setup-java'
name: 'Step: Set Up Java and Maven'
uses: 'actions/setup-java@v3'
with:
cache: 'maven'
distribution: 'temurin'
java-version: '11'
- id: 'mvn-verify'
name: 'Step: Maven Verify'
# -U force updates just to make sure we are using latest dependencies
# -B Batch mode (do not ask for user input), just in case
# -P activate profile
run: 'mvn -U -B -e -ntp verify'
110 changes: 109 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,112 @@

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.chensoul/chensoul-parent/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.chensoul/chensoul-parent)

This project houses the parent Project Object Model (POM) for most ChenSoul™ projects.
This project houses the parent Project Object Model (POM) for most ChenSoul™ projects.

## Links

Login to your [sonatype](https://s01.oss.sonatype.org/) account to release the version

| Type | URL | Description |
|:---------|:------------------------------------------------------------------------------------------------------|:------------------|
| Snapshot | [sonatype](https://s01.oss.sonatype.org/content/repositories/snapshots/com/chensoul/chensoul-parent/) | Snapshot versions |
| Release | [sonatype](https://repo.maven.apache.org/maven2/com/chensoul/chensoul-parent/) | Release versions |
| Release | [central-sonatype](https://central.sonatype.com/artifact/com.chensoul/chensoul-parent/1.0.0/versions) | Release versions |

## Secrets

* **MAVEN_GPG_PRIVATE_KEY** - Take it from the private.gpg
* **OSSRH_USERNAME** - Created [here](https://issues.sonatype.org/)
* **OSSRH_TOKEN** - Created [here](https://issues.sonatype.org/)
* **MAVEN_GPG_PASSPHRASE** - Create [here](https://central.sonatype.org/publish/requirements/gpg/#generating-a-key-pair)
* This passphrase and your private key are all that is needed to sign artifacts with your signature.
* **GITHUB_TOKEN** - Github token

## Demo

How do you release a version?

Manually:\
   1. Check the version in the pom.xml\
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* **<version>1.0.0-SNAPSHOT</version>**\
&nbsp;&nbsp;&nbsp;2. Go to Github action -> Run workflow\
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* **Release:** 1.0.0\
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* **Snapshot:** 1.0.1-SNAPSHOT

Automatically:\
Push to Github will create a release and a snapshot but it won't publish the release.\
Snapshot will be available through [here](https://central.sonatype.com/artifact/com.chensoul/chensoul-parent/1.0.0)

## GPG

After generating gpg key following by [here](https://central.sonatype.org/publish/requirements/gpg/#generating-a-key-pair)

```bash
gpg --gen-key
```

You can list the local key that you created:

```bash
gpg --list-secret-keys --keyid-format=long
```

Then you can export the private key to your local machine in order to upload it later to Github secret:

```bash
gpg --armor --export-secret-keys <YOUR_KEY> > private.gpg
```

* YOUR_KEY='long number'

## Local commands

Check your maven settings file `~/.m2/settings.xml`:

```bash
<server>
<id>gpg.passphrase</id>
<passphrase><PASSPHRASE_GPG></passphrase>
</server>
<server>
<id>ossrh</id>
<username><OSSRH_USERNAME></username>
<password><OSSRH_TOKEN></password>
</server>
```

Release and deploy to maven repository:

```bash
mvn -B release:clean release:prepare release:perform
```

Update pom version:

```bash
mvn -B build-helper:parse-version versions:set -DnewVersion=1.0.0-SNAPSHOT versions:commit
```

Create new branch with next version, it won't update the working copy version:

```bash
mvn -B release:branch -DbranchName=my-branch -DupdateBranchVersions=true -DupdateWorkingCopyVersions=false
```

GPG to sign and deploy to sonatype repository using release profile:

```bash
mvn -B clean deploy -Prelease -Dgpg.passphrase=<PASSPHRASE_GPG> -Dusername=<OSSRH_USERNAME> -Dpassword=<OSSRH_TOKEN>

# reading gpg.passphrase, username and password from settings.xml
mvn -B clean deploy -Prelease
```

## Authors

- [@chensoul](https://www.github.com/chensoul)

## Thanks

- https://github.com/microbean/microbean-parent
- https://github.com/naturalett/maven-hello-world
Empty file removed expire
Empty file.
Loading

0 comments on commit 0dccfac

Please sign in to comment.