Skip to content

Commit

Permalink
🚀 github action to deploy OSSRH
Browse files Browse the repository at this point in the history
  • Loading branch information
trydofor committed Dec 31, 2023
1 parent 5d280d6 commit d447769
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 27 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Release-To-OssRh
run-name: Deploy ${{github.event.release.tag_name}} to Sonatype by @${{ github.actor }}

on:
workflow_dispatch:
release:
types: [published]

jobs:
release:
name: Release to Sonatype
runs-on: ubuntu-latest

steps:
- name: Checkout ${{github.event.release.tag_name}}
uses: actions/checkout@v4
## chache asdf/, m2/repository
- name: Cache Sdk & Repo
id: cache-sdk-repo
uses: actions/cache@v3
with:
path: |
~/.asdf/
~/.m2/repository/
key: asdf-m2-repo-${{hashFiles('.tool-versions')}}

## install jdk and maven
- name: Install asdf & tools
uses: asdf-vm/actions/install@v2
with:
skip_install: ${{steps.cache-sdk-repo.outputs.cache-hit == 'true'}}

## write settings.xml
- name: Maven settings.xml
run: |
mkdir -p ~/.m2
cat > ~/.m2/settings.xml << "EOF"
<settings>
<interactiveMode>false</interactiveMode>
<servers>
<server>
<id>ossrh</id>
<username>${MVN_OSS_USER}</username>
<password>${MVN_OSS_PASS}</password>
</server>
</servers>
</settings>
EOF
## get JAVA_HOME
- name: Env JAVA_HOME
id: java-env
run: echo "JAVA_HOME=$(asdf where java)" >> "$GITHUB_OUTPUT"
## get revision if tag_name
- name: Opt revision
id: opt-revision
run: echo "OPT_REVISION=-Drevision=${{github.event.release.tag_name}}" >> "$GITHUB_OUTPUT"
if: github.event.release.tag_name != ''
## info deploy
- name: Info Deploy
run: |
mvn -v ${{ steps.opt-revision.outputs.OPT_REVISION }}
git log --pretty=format:'%H - %an, %ad %d : %s' --graph -10
env:
JAVA_HOME: ${{ steps.java-env.outputs.JAVA_HOME }}
## import gpp private key
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.MVN_GPG_SKEY }}
passphrase: ${{ secrets.MVN_GPG_PASS }}
## maven deploy
- name: Maven Deploy
run: >
mvn
-P ossrh
${{ steps.opt-revision.outputs.OPT_REVISION }}
-Dgpg.passphrase=${MVN_GPG_PASS}
-Dgpg.skip=false
-Dmaven.test.skip=true
clean deploy
env:
JAVA_HOME: ${{ steps.java-env.outputs.JAVA_HOME }}
MVN_OSS_USER: ${{ secrets.MVN_OSS_USER }}
MVN_OSS_PASS: ${{ secrets.MVN_OSS_PASS }}
MVN_GPG_PASS: ${{ secrets.MVN_GPG_PASS }}
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
java temurin-8.0.382+5
maven 3.9.6
76 changes: 49 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<groupId>pro.fessional</groupId>
<artifactId>mirana</artifactId>
<version>2.6.4-SNAPSHOT</version>
<version>${revision}</version>
<packaging>jar</packaging>

<name>mirana moon girl</name>
Expand Down Expand Up @@ -60,6 +60,7 @@
</issueManagement>

<properties>
<revision>2.6.4-SNAPSHOT</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down Expand Up @@ -226,23 +227,6 @@
<commitIdGenerationMode>full</commitIdGenerationMode>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
<configuration>
<keyname>541B1728468267BFA83FE092CE8F6F63A835DB68</keyname>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
Expand Down Expand Up @@ -272,14 +256,52 @@
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<profiles>
<profile>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
<configuration>
<keyname>541B1728468267BFA83FE092CE8F6F63A835DB68</keyname>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<!-- https://central.sonatype.org/publish/publish-maven/ -->
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</profile>
</profiles>
</project>

0 comments on commit d447769

Please sign in to comment.