Skip to content

Commit 0597f1a

Browse files
authored
Merge pull request #365 from tcheeric/codex/convert-publish-workflow-to-reusable
refactor: reuse publish workflow
2 parents 0cbfb61 + 827b18a commit 0597f1a

3 files changed

Lines changed: 43 additions & 11 deletions

File tree

.github/workflows/publish-github-packages.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
name: Publish to GitHub Packages
22

33
on:
4+
workflow_call:
5+
secrets:
6+
GITHUB_TOKEN:
7+
required: true
8+
GPG_PRIVATE_KEY:
9+
required: false
10+
GPG_PASSPHRASE:
11+
required: false
412
push:
513
branches: [main]
614
paths:
@@ -14,6 +22,9 @@ jobs:
1422
permissions:
1523
contents: read
1624
packages: write
25+
env:
26+
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
27+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
1728
steps:
1829
- name: Checkout repository
1930
uses: actions/checkout@v4
@@ -26,6 +37,17 @@ jobs:
2637
server-id: github
2738
server-username: ${{ github.actor }}
2839
server-password: ${{ secrets.GITHUB_TOKEN }}
40+
- name: Import GPG key
41+
if: env.GPG_PRIVATE_KEY != ''
42+
run: |
43+
echo "$GPG_PRIVATE_KEY" | gpg --batch --import
44+
gpg --list-secret-keys --keyid-format LONG
2945
- name: Publish modules
30-
run: ./mvnw -B -q deploy -DskipTests -Dgpg.skip=true \
31-
-DaltDeploymentRepository=github::default::https://maven.pkg.github.com/${{ github.repository }}
46+
run: |
47+
if [ -n "$GPG_PRIVATE_KEY" ]; then
48+
./mvnw -q -P release deploy -Dgpg.passphrase="$GPG_PASSPHRASE" \
49+
-DaltDeploymentRepository=github::default::https://maven.pkg.github.com/${{ github.repository }}
50+
else
51+
./mvnw -B -q deploy -DskipTests -Dgpg.skip=true \
52+
-DaltDeploymentRepository=github::default::https://maven.pkg.github.com/${{ github.repository }}
53+
fi

.github/workflows/release.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,11 @@ jobs:
2828
run: |
2929
echo "$GPG_PRIVATE_KEY" | gpg --batch --import
3030
gpg --list-secret-keys --keyid-format LONG
31-
3231
- name: Build and deploy
3332
env:
3433
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
3534
run: ./mvnw -q -P release deploy -Dgpg.passphrase="$GPG_PASSPHRASE"
3635

37-
- name: Deploy to GitHub Packages
38-
env:
39-
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
40-
run: |
41-
./mvnw -q -P release deploy -Dgpg.passphrase="$GPG_PASSPHRASE" \
42-
-DaltDeploymentRepository=github::default::https://maven.pkg.github.com/tcheeric/nostr-java
43-
4436
- name: Collect JAR artifacts
4537
run: |
4638
mkdir -p release-jars
@@ -67,3 +59,11 @@ jobs:
6759
for file in release-jars/*.jar; do
6860
gh release upload "${{ github.ref_name }}" "$file" --clobber
6961
done
62+
63+
publish-packages:
64+
needs: release
65+
uses: ./.github/workflows/publish-github-packages.yml
66+
secrets:
67+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
69+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,17 @@ Authenticating to GitHub Packages is required; provide a personal access token w
4545

4646
## Publishing Modules
4747

48-
This repository includes a [GitHub Actions workflow](.github/workflows/publish-github-packages.yml) that publishes all Maven modules to GitHub Packages. The workflow runs on pushes to `main` that modify `pom.xml` files and can also be triggered manually from the Actions tab.
48+
This repository includes a [GitHub Actions workflow](.github/workflows/publish-github-packages.yml) that publishes all Maven modules to GitHub Packages. The workflow runs on pushes to `main` that modify `pom.xml` files and can also be triggered manually from the Actions tab. It is also exposed as a reusable workflow and can be invoked from other workflows, such as the release pipeline:
49+
50+
```yaml
51+
jobs:
52+
publish-packages:
53+
uses: ./.github/workflows/publish-github-packages.yml
54+
secrets:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
57+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
58+
```
4959
5060
## Examples
5161
Example usages are located in the [`nostr-java-examples`](./nostr-java-examples) module. Additional demonstrations can be found in [nostr-client](https://github.com/tcheeric/nostr-client) and [SuperConductor](https://github.com/avlo/superconductor).

0 commit comments

Comments
 (0)