Update release.yml #270
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: Release | |
| on: | |
| push: | |
| branches: | |
| - publish-java | |
| jobs: | |
| build-java-jni: | |
| strategy: | |
| fail-fast: true | |
| matrix: | |
| settings: | |
| - host: ubuntu-22.04 | |
| lib_prefix: "lib" | |
| lib_suffix: ".so" | |
| target: x86_64-unknown-linux-gnu | |
| cross: true | |
| - host: ubuntu-22.04 | |
| lib_prefix: "lib" | |
| lib_suffix: ".so" | |
| target: aarch64-unknown-linux-gnu | |
| cross: true | |
| - host: windows-latest | |
| lib_suffix: ".dll" | |
| target: x86_64-pc-windows-msvc | |
| - host: macos-13 | |
| lib_prefix: "lib" | |
| lib_suffix: ".dylib" | |
| target: x86_64-apple-darwin | |
| - host: macos-13 | |
| lib_prefix: "lib" | |
| lib_suffix: ".dylib" | |
| target: aarch64-apple-darwin | |
| runs-on: ${{ matrix.settings.host }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| submodules: true | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| toolchain: stable | |
| components: rustfmt, clippy | |
| targets: ${{ matrix.settings.target }} | |
| - name: Build | |
| if: ${{ !matrix.settings.cross }} | |
| run: | | |
| cargo build -p longport-java --release --target ${{ matrix.settings.target }} | |
| mv target/${{ matrix.settings.target }}/release/${{ matrix.settings.lib_prefix }}longport_java${{ matrix.settings.lib_suffix }} longport_java-${{ matrix.settings.target }}${{ matrix.settings.lib_suffix }} | |
| - name: Install latest cross binary | |
| if: ${{ matrix.settings.cross }} | |
| uses: st3iny/install-cross-binary@v3 | |
| - name: Build with Cross | |
| if: ${{ matrix.settings.cross }} | |
| run: | | |
| cross build -p longport-java --release --target ${{ matrix.settings.target }} | |
| mv target/${{ matrix.settings.target }}/release/${{ matrix.settings.lib_prefix }}longport_java${{ matrix.settings.lib_suffix }} longport_java-${{ matrix.settings.target }}${{ matrix.settings.lib_suffix }} | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: jnis-${{ matrix.settings.target }} | |
| path: longport_java-${{ matrix.settings.target }}${{ matrix.settings.lib_suffix }} | |
| build: | |
| needs: | |
| - build-java-jni | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - run: echo "All builds are done" | |
| publish-java-sdk: | |
| runs-on: ubuntu-22.04 | |
| needs: build | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| submodules: true | |
| - name: Install JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: "8" | |
| distribution: "temurin" | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v5 | |
| with: | |
| path: ./java/jnis | |
| pattern: jnis-* | |
| merge-multiple: true | |
| - name: Configure Maven settings.xml | |
| run: | | |
| mkdir -p ~/.m2 | |
| cat > ~/.m2/settings.xml << EOF | |
| <settings> | |
| <profiles> | |
| <profile> | |
| <id>gpg</id> | |
| <activation> | |
| <activeByDefault>true</activeByDefault> | |
| </activation> | |
| <properties> | |
| <gpg.executable>gpg</gpg.executable> | |
| <gpg.passphrase>${{ secrets.GPG_PASSPHRASE }}</gpg.passphrase> | |
| </properties> | |
| </profile> | |
| </profiles> | |
| <servers> | |
| <server> | |
| <id>central</id> | |
| <username>${{ secrets.CENTRAL_USERNAME }}</username> | |
| <password>${{ secrets.CENTRAL_PASSWORD }}</password> | |
| </server> | |
| </servers> | |
| </settings> | |
| EOF | |
| - name: Copy jnis | |
| working-directory: java | |
| run: | | |
| mkdir -p javasrc/target/natives/linux_64 | |
| mkdir -p javasrc/target/natives/linux_arm64 | |
| mkdir -p javasrc/target/natives/windows_64 | |
| mkdir -p javasrc/target/natives/osx_64 | |
| mkdir -p javasrc/target/natives/osx_arm64 | |
| mv jnis/longport_java-x86_64-unknown-linux-gnu.so javasrc/target/natives/linux_64/liblongport_java.so | |
| mv jnis/longport_java-aarch64-unknown-linux-gnu.so javasrc/target/natives/linux_arm64/liblongport_java.so | |
| mv jnis/longport_java-x86_64-pc-windows-msvc.dll javasrc/target/natives/windows_64/longport_java.dll | |
| mv jnis/longport_java-x86_64-apple-darwin.dylib javasrc/target/natives/osx_64/liblongport_java.dylib | |
| mv jnis/longport_java-aarch64-apple-darwin.dylib javasrc/target/natives/osx_arm64/liblongport_java.dylib | |
| - name: Get version | |
| run: echo PACKAGE_VERSION=$(sed -nE 's/^\s*version = "(.*?)"/\1/p' Cargo.toml) >> $GITHUB_ENV | |
| - name: Update version | |
| working-directory: java/javasrc | |
| run: mvn versions:set -DnewVersion=${PACKAGE_VERSION} | |
| - name: Import GPG private key | |
| env: | |
| GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} | |
| GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} | |
| run: | | |
| echo "$GPG_PRIVATE_KEY" > private.key | |
| gpg --import --batch private.key | |
| rm private.key | |
| # - name: Deploy Maven package | |
| # working-directory: java/javasrc | |
| # run: mvn deploy --activate-profiles release |