Skip to content

Commit 5873804

Browse files
author
Christine Zhou
committed
Add GitHub Actions for automated Maven Central publishing
- Add workflow for automatic publishing on releases - Include comprehensive documentation - Set up all required GitHub secrets - Support both release triggers and manual dispatch
1 parent 5367942 commit 5873804

File tree

5 files changed

+553
-26
lines changed

5 files changed

+553
-26
lines changed

.github/workflows/maven-publish.yml

Lines changed: 102 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,109 @@
1-
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
2-
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path
3-
4-
name: Maven Publish
1+
name: Publish to Maven Central
52

63
on:
7-
push:
8-
branches: [ "maven-publish-**" ]
4+
release:
5+
types: [published]
96
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'Version to publish (e.g., 0.4.1)'
10+
required: true
11+
type: string
1012

1113
jobs:
12-
Maven-Publish-Ubuntu:
14+
publish:
1315
runs-on: ubuntu-latest
16+
1417
steps:
15-
- uses: actions/checkout@v3
16-
- name: Set up Java for publishing to Maven Central Repository
17-
uses: actions/setup-java@v3
18-
with:
19-
distribution: 'temurin'
20-
java-version: '11'
21-
server-id: ossrh
22-
server-username: MAVEN_USERNAME
23-
server-password: MAVEN_PASSWORD
24-
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} # Value of the GPG private key to import
25-
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
26-
- name: Publish to the Maven Central Repository
27-
working-directory: Src/PRuntimes/PSymRuntime
28-
run: mvn --batch-mode deploy -P release -Dmaven.test.skip
29-
env:
30-
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
31-
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
32-
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
33-
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Set up JDK 17
22+
uses: actions/setup-java@v4
23+
with:
24+
java-version: '17'
25+
distribution: 'temurin'
26+
27+
- name: Cache Maven dependencies
28+
uses: actions/cache@v3
29+
with:
30+
path: ~/.m2
31+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
32+
restore-keys: ${{ runner.os }}-m2
33+
34+
- name: Import GPG key
35+
uses: crazy-max/ghaction-import-gpg@v6
36+
with:
37+
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
38+
passphrase: ${{ secrets.GPG_PASSPHRASE }}
39+
40+
- name: Extract version from release
41+
id: get_version
42+
run: |
43+
if [ "${{ github.event_name }}" = "release" ]; then
44+
VERSION=${{ github.event.release.tag_name }}
45+
# Remove 'v' prefix if present
46+
VERSION=${VERSION#v}
47+
else
48+
VERSION=${{ github.event.inputs.version }}
49+
fi
50+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
51+
echo "Publishing version: $VERSION"
52+
53+
- name: Update PEx version
54+
run: |
55+
cd Src/PEx
56+
# Update the revision property in pom.xml
57+
sed -i "s/<revision>.*<\/revision>/<revision>${{ steps.get_version.outputs.VERSION }}<\/revision>/" pom.xml
58+
echo "Updated PEx version to ${{ steps.get_version.outputs.VERSION }}"
59+
60+
- name: Create Maven settings.xml
61+
run: |
62+
mkdir -p ~/.m2
63+
cat > ~/.m2/settings.xml << 'EOF'
64+
<?xml version="1.0" encoding="UTF-8"?>
65+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
66+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
67+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
68+
http://maven.apache.org/xsd/settings-1.0.0.xsd">
69+
<servers>
70+
<server>
71+
<id>central</id>
72+
<username>${{ secrets.MAVEN_USERNAME }}</username>
73+
<password>${{ secrets.MAVEN_PASSWORD }}</password>
74+
</server>
75+
<server>
76+
<id>gpg.passphrase</id>
77+
<passphrase>${{ secrets.GPG_PASSPHRASE }}</passphrase>
78+
</server>
79+
</servers>
80+
</settings>
81+
EOF
82+
83+
- name: Publish to Maven Central
84+
run: |
85+
cd Src/PEx
86+
mvn clean deploy -P release -DskipTests
87+
env:
88+
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
89+
90+
- name: Create deployment summary
91+
run: |
92+
echo "## 🚀 Maven Central Deployment" >> $GITHUB_STEP_SUMMARY
93+
echo "Successfully published **PEx ${{ steps.get_version.outputs.VERSION }}** to Maven Central!" >> $GITHUB_STEP_SUMMARY
94+
echo "" >> $GITHUB_STEP_SUMMARY
95+
echo "### 📦 Artifact Details" >> $GITHUB_STEP_SUMMARY
96+
echo "- **Group ID:** io.github.p-org" >> $GITHUB_STEP_SUMMARY
97+
echo "- **Artifact ID:** pex" >> $GITHUB_STEP_SUMMARY
98+
echo "- **Version:** ${{ steps.get_version.outputs.VERSION }}" >> $GITHUB_STEP_SUMMARY
99+
echo "" >> $GITHUB_STEP_SUMMARY
100+
echo "### 📋 Maven Dependency" >> $GITHUB_STEP_SUMMARY
101+
echo '```xml' >> $GITHUB_STEP_SUMMARY
102+
echo '<dependency>' >> $GITHUB_STEP_SUMMARY
103+
echo ' <groupId>io.github.p-org</groupId>' >> $GITHUB_STEP_SUMMARY
104+
echo ' <artifactId>pex</artifactId>' >> $GITHUB_STEP_SUMMARY
105+
echo " <version>${{ steps.get_version.outputs.VERSION }}</version>" >> $GITHUB_STEP_SUMMARY
106+
echo '</dependency>' >> $GITHUB_STEP_SUMMARY
107+
echo '```' >> $GITHUB_STEP_SUMMARY
108+
echo "" >> $GITHUB_STEP_SUMMARY
109+
echo "🔗 [View on Maven Central](https://central.sonatype.com/artifact/io.github.p-org/pex/${{ steps.get_version.outputs.VERSION }})" >> $GITHUB_STEP_SUMMARY

MAVEN_PUBLISHING.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Maven Central Publishing Setup
2+
3+
This repository is configured to automatically publish PEx releases to Maven Central using GitHub Actions.
4+
5+
## 🚀 How It Works
6+
7+
The GitHub Action (`.github/workflows/maven-publish.yml`) automatically triggers when:
8+
1. **A new release is published** on GitHub
9+
2. **Manual workflow dispatch** with a specified version
10+
11+
## 🔐 Required GitHub Secrets
12+
13+
To enable automatic publishing, you need to set up the following secrets in your GitHub repository:
14+
15+
### Setting Up Secrets
16+
17+
Go to your GitHub repository → Settings → Secrets and variables → Actions → New repository secret
18+
19+
Add these secrets:
20+
21+
| Secret Name | Description | Value |
22+
|-------------|-------------|-------|
23+
| `GPG_PRIVATE_KEY` | Your GPG private key | Export with: `gpg --armor --export-secret-keys 898DA8146E2A2D78` |
24+
| `GPG_PASSPHRASE` | GPG key passphrase | `maven123` |
25+
| `MAVEN_USERNAME` | Maven Central username | `ZzKyphY4` |
26+
| `MAVEN_PASSWORD` | Maven Central token | `4pbrSR938B6nxBb3HYTHVE00tHypxDGE6A1K8DeCbAXn` |
27+
28+
### Getting Your GPG Private Key
29+
30+
```bash
31+
# Export your GPG private key
32+
gpg --armor --export-secret-keys 898DA8146E2A2D78
33+
34+
# Copy the entire output including the BEGIN/END lines
35+
```
36+
37+
## 📦 Publishing a New Version
38+
39+
### Method 1: GitHub Release (Recommended)
40+
41+
1. Go to your GitHub repository
42+
2. Click "Releases" → "Create a new release"
43+
3. Create a new tag (e.g., `v0.4.1`, `v0.5.0`)
44+
4. Fill in release title and description
45+
5. Click "Publish release"
46+
6. The GitHub Action will automatically trigger and publish to Maven Central
47+
48+
### Method 2: Manual Workflow Dispatch
49+
50+
1. Go to Actions tab → "Publish to Maven Central"
51+
2. Click "Run workflow"
52+
3. Enter the version number (e.g., `0.4.1`)
53+
4. Click "Run workflow"
54+
55+
## 📋 Version Management
56+
57+
The workflow automatically:
58+
- Extracts version from GitHub release tag (removes `v` prefix if present)
59+
- Updates the `<revision>` property in `Src/PEx/pom.xml`
60+
- Builds and signs the artifacts
61+
- Publishes to Maven Central
62+
63+
## 🔍 Monitoring Deployments
64+
65+
After the workflow runs:
66+
1. Check the Actions tab for build status
67+
2. View the deployment summary in the workflow run
68+
3. Verify the artifact appears on [Maven Central](https://central.sonatype.com/artifact/io.github.p-org/pex)
69+
70+
## 📖 Using the Published Artifact
71+
72+
Once published, users can include PEx in their Maven projects:
73+
74+
```xml
75+
<dependency>
76+
<groupId>io.github.p-org</groupId>
77+
<artifactId>pex</artifactId>
78+
<version>0.4.0</version>
79+
</dependency>
80+
```
81+
82+
## 🛠 Troubleshooting
83+
84+
### Common Issues
85+
86+
1. **GPG Signing Fails**
87+
- Verify `GPG_PRIVATE_KEY` and `GPG_PASSPHRASE` secrets are correct
88+
- Ensure the GPG key is uploaded to key servers
89+
90+
2. **Maven Central Authentication Fails**
91+
- Check `MAVEN_USERNAME` and `MAVEN_PASSWORD` secrets
92+
- Verify the token is still valid
93+
94+
3. **Version Already Exists**
95+
- Maven Central doesn't allow overwriting versions
96+
- Use a new version number
97+
98+
### Manual Local Publishing
99+
100+
If you need to publish manually:
101+
102+
```bash
103+
cd Src/PEx
104+
mvn clean deploy -P release -DskipTests -s ../../settings.xml
105+
```
106+
107+
## 🔄 Workflow Features
108+
109+
- ✅ Automatic version extraction from GitHub releases
110+
- ✅ GPG signing with secure key management
111+
- ✅ Maven dependency caching for faster builds
112+
- ✅ Detailed deployment summaries
113+
- ✅ Manual trigger option for hotfixes
114+
- ✅ Skip tests for faster publishing
115+
- ✅ Professional CI/CD pipeline
116+
117+
The workflow ensures reliable, secure, and automated publishing of PEx releases to Maven Central!

README-Docker.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Docker Setup for P Compiler with PEx Support
2+
3+
This Docker setup provides a containerized environment for running the P compiler with PEx (explicit-state model checking) support.
4+
5+
## Building the Docker Image
6+
7+
From the root directory of the P repository, run:
8+
9+
```bash
10+
docker build -t p-compiler-pex .
11+
```
12+
13+
This will:
14+
1. Build the P compiler from source
15+
2. Set up Java 17 runtime environment
16+
3. Download PEx runtime (version 0.4.0) from Maven Central
17+
4. Configure classpath and wrapper scripts
18+
19+
## Running the Container
20+
21+
### Interactive Mode
22+
```bash
23+
docker run -it --rm -v $(pwd):/workspace p-compiler-pex
24+
```
25+
26+
This mounts your current directory to `/workspace` in the container, allowing you to work with your P projects.
27+
28+
### Running P Compiler with PEx
29+
Inside the container, you can run:
30+
31+
```bash
32+
# Compile a P project with PEx backend
33+
p compile -mode pex MyProject.pproj
34+
35+
# The container automatically sets up the Java classpath for PEx
36+
```
37+
38+
## Example Usage
39+
40+
1. **Start the container:**
41+
```bash
42+
docker run -it --rm -v $(pwd):/workspace p-compiler-pex
43+
```
44+
45+
2. **Inside the container, compile your P project:**
46+
```bash
47+
cd /workspace
48+
p compile -mode pex Tutorial/1_ClientServer/ClientServer.pproj
49+
```
50+
51+
3. **Run the generated Java code with PEx:**
52+
```bash
53+
# The PEx runtime is available via the pex-runner.sh script
54+
/app/pex-runner.sh [PEx arguments]
55+
```
56+
57+
## What's Included
58+
59+
- **P Compiler**: Latest version built from source
60+
- **Java 17**: Required for PEx runtime
61+
- **PEx Runtime**: Version 0.4.0 from Maven Central (`io.github.p-org:pex:0.4.0`)
62+
- **Maven**: For dependency management
63+
- **Wrapper Scripts**: Automatically configured classpath for seamless P/PEx integration
64+
65+
## Environment Details
66+
67+
- **P Compiler**: Located at `/app/p-compiler/`
68+
- **PEx Dependencies**: Located at `/app/pex/target/lib/`
69+
- **Working Directory**: `/workspace` (mounted from host)
70+
- **Java**: OpenJDK 17
71+
- **Wrapper Script**: `/app/p` (in PATH)
72+
73+
## Troubleshooting
74+
75+
If you encounter issues:
76+
77+
1. **Check Java version:**
78+
```bash
79+
java -version
80+
```
81+
82+
2. **Verify PEx classpath:**
83+
```bash
84+
echo $CLASSPATH
85+
```
86+
87+
3. **Test PEx directly:**
88+
```bash
89+
/app/pex-runner.sh --help
90+
```
91+
92+
4. **Check P compiler version:**
93+
```bash
94+
p --version

0 commit comments

Comments
 (0)