Build and Publish #3
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: Build & Publish | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| jobs: | |
| build: | |
| name: Build Platform-Specific JARs | |
| strategy: | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| platform: linux-x86_64 | |
| build-tools: build-essential clang pkg-config | |
| - os: ubuntu-latest | |
| platform: linux-aarch64 | |
| build-tools: build-essential clang pkg-config gcc-aarch64-linux-gnu | |
| cross-compile: true | |
| - os: macos-latest | |
| platform: macos-aarch64 | |
| build-tools: "" | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Install build tools (Linux) | |
| if: startsWith(matrix.os, 'ubuntu') | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y ${{ matrix.build-tools }} | |
| - name: Setup Java | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: temurin | |
| java-version: 21 | |
| cache: gradle | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v4 | |
| - name: Set up cross-compilation (Linux ARM64) | |
| if: matrix.platform == 'linux-aarch64' | |
| run: | | |
| echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV | |
| echo "CXX=aarch64-linux-gnu-g++" >> $GITHUB_ENV | |
| echo "TARGET_OS=linux" >> $GITHUB_ENV | |
| echo "TARGET_ARCH=aarch64" >> $GITHUB_ENV | |
| - name: Set platform environment variables | |
| run: | | |
| case "${{ matrix.platform }}" in | |
| linux-x86_64) | |
| echo "TARGET_OS=linux" >> $GITHUB_ENV | |
| echo "TARGET_ARCH=x86_64" >> $GITHUB_ENV | |
| ;; | |
| macos-aarch64) | |
| echo "TARGET_OS=macos" >> $GITHUB_ENV | |
| echo "TARGET_ARCH=aarch64" >> $GITHUB_ENV | |
| ;; | |
| esac | |
| - name: Build jpostal | |
| run: ./gradlew -Pversion=${{ github.event.release.tag_name }} clean build platformJar -x test -x signArchives | |
| - name: Verify JAR contents | |
| run: | | |
| echo "=== Built JARs ===" | |
| ls -la build/libs/ | |
| echo "=== JAR Contents ===" | |
| for jar in build/libs/jpostal-*.jar; do | |
| if [[ -f "$jar" && "$jar" != *"sources"* && "$jar" != *"javadoc"* ]]; then | |
| echo "Contents of $jar:" | |
| jar -tf "$jar" | grep -E "(native/|\.class$)" | head -10 | |
| echo "Native libraries:" | |
| jar -tf "$jar" | grep native/ || echo "No native libraries found" | |
| echo "---" | |
| fi | |
| done | |
| - name: Upload platform artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: jpostal-${{ matrix.platform }} | |
| path: build/libs/*.jar | |
| publish: | |
| name: Publish to Maven | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v5 | |
| with: | |
| path: artifacts | |
| - name: Setup Java | |
| uses: actions/setup-java@v5 | |
| env: | |
| GPG_PASSPHRASE: ${{ secrets.SIGNING_KEY_PASSPHRASE }} | |
| with: | |
| distribution: temurin | |
| java-version: 21 | |
| cache: gradle | |
| gpg-passphrase: GPG_PASSPHRASE | |
| gpg-private-key: ${{ secrets.SIGNING_KEY }} | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v4 | |
| - name: List downloaded artifacts | |
| run: | | |
| echo "Downloaded artifacts:" | |
| find artifacts -name "*.jar" -type f | |
| - name: Build for publishing | |
| run: | | |
| # Build the universal JAR (signing handled by Maven Central plugin) | |
| ./gradlew clean build -x test | |
| - name: Publish to Maven Central | |
| env: | |
| ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} | |
| ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ vars.SIGNING_KEY_ID }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_KEY_PASSPHRASE }} | |
| run: ./gradlew publishToMavenCentral | |
| - name: Prepare release artifacts | |
| run: | | |
| mkdir -p release-artifacts | |
| # Copy the universal JAR | |
| cp build/libs/*.jar release-artifacts/ | |
| # Copy platform-specific JARs from artifacts | |
| find artifacts -name "*.jar" -type f -exec cp {} release-artifacts/ \; | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: release-artifacts/*.jar | |
| generate_release_notes: true |