Publish to Maven Central #38
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish to Maven Central | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version to publish (e.g., 0.4.1). Leave empty to use current P version from pom.xml' | |
| required: false | |
| type: string | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Cache Maven dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.m2 | |
| key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: ${{ runner.os }}-m2 | |
| - name: Import GPG key | |
| uses: crazy-max/ghaction-import-gpg@v6 | |
| with: | |
| gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} | |
| passphrase: ${{ secrets.GPG_PASSPHRASE }} | |
| - name: Extract version from release | |
| id: get_version | |
| run: | | |
| if [ "${{ github.event_name }}" = "release" ]; then | |
| VERSION=${{ github.event.release.tag_name }} | |
| # Remove 'v' prefix if present | |
| VERSION=${VERSION#v} | |
| else | |
| VERSION=${{ github.event.inputs.version }} | |
| fi | |
| echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Publishing version: $VERSION" | |
| - name: Update PEx version | |
| run: | | |
| cd Src/PEx | |
| # Update the revision property in pom.xml | |
| sed -i "s/<revision>.*<\/revision>/<revision>${{ steps.get_version.outputs.VERSION }}<\/revision>/" pom.xml | |
| echo "Updated PEx version to ${{ steps.get_version.outputs.VERSION }}" | |
| - name: Create Maven settings.xml | |
| run: | | |
| mkdir -p ~/.m2 | |
| cat > ~/.m2/settings.xml << 'EOF' | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" | |
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 | |
| http://maven.apache.org/xsd/settings-1.0.0.xsd"> | |
| <servers> | |
| <server> | |
| <id>central</id> | |
| <username>${{ secrets.MAVEN_USERNAME }}</username> | |
| <password>${{ secrets.MAVEN_PASSWORD }}</password> | |
| </server> | |
| <server> | |
| <id>gpg.passphrase</id> | |
| <passphrase>${{ secrets.GPG_PASSPHRASE }}</passphrase> | |
| </server> | |
| </servers> | |
| </settings> | |
| EOF | |
| - name: Publish to Maven Central | |
| run: | | |
| cd Src/PEx | |
| mvn clean deploy -P release -DskipTests | |
| env: | |
| MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} | |
| - name: Create deployment summary | |
| run: | | |
| echo "## 🚀 Maven Central Deployment" >> $GITHUB_STEP_SUMMARY | |
| echo "Successfully published **PEx ${{ steps.get_version.outputs.VERSION }}** to Maven Central!" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### 📦 Artifact Details" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Group ID:** io.github.p-org" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Artifact ID:** pex" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Version:** ${{ steps.get_version.outputs.VERSION }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### 📋 Maven Dependency" >> $GITHUB_STEP_SUMMARY | |
| echo '```xml' >> $GITHUB_STEP_SUMMARY | |
| echo '<dependency>' >> $GITHUB_STEP_SUMMARY | |
| echo ' <groupId>io.github.p-org</groupId>' >> $GITHUB_STEP_SUMMARY | |
| echo ' <artifactId>pex</artifactId>' >> $GITHUB_STEP_SUMMARY | |
| echo " <version>${{ steps.get_version.outputs.VERSION }}</version>" >> $GITHUB_STEP_SUMMARY | |
| echo '</dependency>' >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "🔗 [View on Maven Central](https://central.sonatype.com/artifact/io.github.p-org/pex/${{ steps.get_version.outputs.VERSION }})" >> $GITHUB_STEP_SUMMARY |