From 0dccfacdac99ee9eb969dcd2df47caf4fd272eda Mon Sep 17 00:00:00 2001 From: chensoul Date: Thu, 7 Dec 2023 16:32:37 +0800 Subject: [PATCH] chore: 1.0.1 --- .github/configs/configuration_repo.json | 71 +++++++++++++++ .github/workflows/github-release.yml | 69 +++++++++++++++ .github/workflows/maven-release.yml | 81 +++++++++++++++++ .github/workflows/maven-verify.yml | 32 +++++++ README.md | 110 +++++++++++++++++++++++- expire | 0 pom.xml | 108 ++++++++++++----------- 7 files changed, 418 insertions(+), 53 deletions(-) create mode 100644 .github/configs/configuration_repo.json create mode 100644 .github/workflows/github-release.yml create mode 100644 .github/workflows/maven-release.yml create mode 100644 .github/workflows/maven-verify.yml delete mode 100644 expire diff --git a/.github/configs/configuration_repo.json b/.github/configs/configuration_repo.json new file mode 100644 index 0000000..eb7e232 --- /dev/null +++ b/.github/configs/configuration_repo.json @@ -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 +} diff --git a/.github/workflows/github-release.yml b/.github/workflows/github-release.yml new file mode 100644 index 0000000..7efa222 --- /dev/null +++ b/.github/workflows/github-release.yml @@ -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}} diff --git a/.github/workflows/maven-release.yml b/.github/workflows/maven-release.yml new file mode 100644 index 0000000..4914624 --- /dev/null +++ b/.github/workflows/maven-release.yml @@ -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 "actions@github.com" + git config user.name "GitHub Actions" + echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + - name: Import GPG Key + uses: crazy-max/ghaction-import-gpg@v5.0.0 + 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 }}"}' diff --git a/.github/workflows/maven-verify.yml b/.github/workflows/maven-verify.yml new file mode 100644 index 0000000..41beeab --- /dev/null +++ b/.github/workflows/maven-verify.yml @@ -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' diff --git a/README.md b/README.md index 8af8c7f..f2630cb 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file +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\ +      * **1.0.0-SNAPSHOT**\ +   2. Go to Github action -> Run workflow\ +      * **Release:** 1.0.0\ +      * **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 > private.gpg +``` + +* YOUR_KEY='long number' + +## Local commands + +Check your maven settings file `~/.m2/settings.xml`: + +```bash + + gpg.passphrase + + + + ossrh + + + +``` + +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= -Dusername= -Dpassword= + +# 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 diff --git a/expire b/expire deleted file mode 100644 index e69de29..0000000 diff --git a/pom.xml b/pom.xml index af6cad6..ec0b5f0 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chensoul chensoul-parent - 1.0.0 + 1.0.1-SNAPSHOT pom ChenSoul™: Parent POM @@ -14,6 +14,18 @@ 2023 https://chensoul.github.io/${project.artifactId}/ + + scm:git:git@github.com:chensoul/${project.artifactId}.git + scm:git:git@github.com:chensoul/${project.artifactId}.git + https://github.com/chensoul/${project.artifactId}/ + HEAD + + + + Github + https://github.com/chensoul/${project.artifactId}/issues + + ChenSoul™ https://blog.chensoul.com/ @@ -42,18 +54,6 @@ - - scm:git:git@github.com:chensoul/${project.artifactId}.git - scm:git:git@github.com:chensoul/${project.artifactId}.git - https://github.com/chensoul/${project.artifactId}/ - HEAD - - - - Github - https://github.com/chensoul/${project.artifactId}/issues - - true @@ -101,12 +101,7 @@ maven-deploy-plugin 3.1.1 - - - org.apache.maven.plugins - maven-gpg-plugin - 3.1.0 - + org.apache.maven.plugins maven-install-plugin @@ -121,6 +116,17 @@ org.apache.maven.plugins maven-release-plugin 3.0.1 + + v@{project.version} + + + + default + + perform + + + org.apache.maven.plugins @@ -154,48 +160,54 @@ -J-Dhttp.agent=maven-javadoc-plugin - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.13 - true - - ossrh - - - https://s01.oss.sonatype.org/ - true - + + + attach-javadocs + + jar + + + + + + ossrh + https://s01.oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + + + release - - - ossrh - https://s01.oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ - - + org.sonatype.plugins nexus-staging-maven-plugin + 1.6.13 + true + + ossrh + + + https://s01.oss.sonatype.org/ + true + + org.apache.maven.plugins maven-gpg-plugin + 3.1.0 sign-artifacts @@ -209,14 +221,6 @@ org.apache.maven.plugins maven-javadoc-plugin - - - attach-javadocs - - jar - - - org.apache.maven.plugins