From b9198ef86adfbc83af12a4975c50fe98173bd9ff Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Mon, 21 Sep 2026 11:50:33 -0400 Subject: [PATCH] build: publish library through a GitHub action --- .github/ISSUE_TEMPLATE/release.md | 5 +- .github/workflows/publish.yml | 223 ++++++++++++++++++++++++++++++ 2 files changed, 225 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/ISSUE_TEMPLATE/release.md b/.github/ISSUE_TEMPLATE/release.md index 642dac6..405c991 100644 --- a/.github/ISSUE_TEMPLATE/release.md +++ b/.github/ISSUE_TEMPLATE/release.md @@ -35,9 +35,8 @@ git tag v2.3.0 --sign --edit git push upstream v2.3.0 ``` -- [ ] Build release artifacts through the workflow dispatch with the new tag (`build.yml`) -- [ ] Add the platform-specific binaries to the `resources/` directory -- [ ] Publish the release to Maven Central. +- [ ] Build and upload the release through the workflow dispatch with the new tag (`publish.yml`). Select the release tag in the _Run workflow > Use workflow from_ dropdown. The workflow checks that the library version matches the tag, builds the native libraries for all targets, runs the tests, and uploads the signed deployment to the Central Portal. +- [ ] Publish the release on Maven Central by logging in to https://central.sonatype.com, reviewing the staged deployment, and clicking _Publish_. Note that a published version can never be replaced or removed. - [ ] Go to https://javadoc.io/versions/org.bitcoindevkit/bdk-jvm and download the latest version of the API docs, which will publish them at https://javadoc.io/doc/org.bitcoindevkit/bdk-jvm/latest/index.html. - [ ] Bump the version on `master` while keeping the `SNAPSHOT` suffix, e.g., from `1.1.0-SNAPSHOT` to `1.2.0-SNAPSHOT`. - [ ] Update this release workflow if necessary. diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..b525790 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,223 @@ +name: Publish Library To Maven Central + +# Run this workflow from the GitHub UI, selecting the release tag (e.g. v3.2.0) in the +# "Run workflow > Use workflow from" dropdown. It builds the native libraries for all +# targets, runs the tests, and uploads the deployment to the Central Portal, where the +# release must then be published manually at https://central.sonatype.com. + +on: [workflow_dispatch] + +permissions: {} + +concurrency: + group: publish + cancel-in-progress: false + +jobs: + verify-tag: + name: "Verify tag and library version" + runs-on: ubuntu-24.04 + permissions: + contents: read + steps: + - name: "Ensure workflow was started from a release tag" + if: github.ref_type != 'tag' || !startsWith(github.ref_name, 'v') + run: | + echo "::error::This workflow must be run from a release tag (e.g. v3.2.0), not '${GITHUB_REF_NAME}'." + exit 1 + + - name: "Check out tag" + uses: actions/checkout@v6 + with: + persist-credentials: false + + - name: "Ensure library version matches tag" + run: | + LIB_VERSION=$(sed -n 's/^version = "\(.*\)"$/\1/p' lib/build.gradle.kts) + TAG_VERSION="${GITHUB_REF_NAME#v}" + echo "Library version: ${LIB_VERSION}" + echo "Tag version: ${TAG_VERSION}" + if [[ "${LIB_VERSION}" == *SNAPSHOT* ]]; then + echo "::error::Library version ${LIB_VERSION} is a SNAPSHOT version." + exit 1 + fi + if [[ "${LIB_VERSION}" != "${TAG_VERSION}" ]]; then + echo "::error::Library version ${LIB_VERSION} does not match tag ${GITHUB_REF_NAME}." + exit 1 + fi + + build-macOS-native-libs: + name: "Create M1 and x86_64 native binaries" + needs: verify-tag + runs-on: macos-14 + permissions: + contents: read + steps: + - name: "Check out tag" + uses: actions/checkout@v6 + with: + submodules: recursive + persist-credentials: false + fetch-depth: 0 + + - name: "Set up JDK" + uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: 17 + + - name: "Build native libraries" + run: | + bash ./scripts/build-macos-aarch64.sh + bash ./scripts/build-macos-x86_64.sh + + - name: "Upload macOS native libraries" + uses: actions/upload-artifact@v7 + with: + name: artifact-macos + path: lib/src/main/resources/ + if-no-files-found: error + + build-windows-native-lib: + name: "Create Windows native binaries" + needs: verify-tag + runs-on: windows-2022 + permissions: + contents: read + steps: + - name: "Check out tag" + uses: actions/checkout@v6 + with: + submodules: recursive + persist-credentials: false + fetch-depth: 0 + + - name: "Set up JDK" + uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: 17 + + - name: "Build native library" + run: bash ./scripts/build-windows-x86_64.sh + + - name: "Upload Windows native libraries" + uses: actions/upload-artifact@v7 + with: + name: artifact-windows + path: lib/src/main/resources/ + if-no-files-found: error + + test: + name: "Build library and run unit tests" + needs: verify-tag + runs-on: ubuntu-24.04 + permissions: + contents: read + + services: + bitcoin-regtest: + image: ghcr.io/thunderbiscuit/podman-regtest-infinity-pro:0.4.0 + ports: + - 18443:18443 + - 18444:18444 + - 3002:3002 + - 60401:60401 + # The container initialization step will wait until everything is ready before allowing other steps to run + options: >- + --health-cmd "test $(bitcoin-cli -regtest -rpcuser=regtest -rpcpassword=password getblockcount) -gt 100" + --health-interval 3s + --health-timeout 5s + --health-retries 20 + + steps: + - name: "Check out tag" + uses: actions/checkout@v6 + with: + submodules: recursive + persist-credentials: false + fetch-depth: 0 + + - name: "Set up JDK" + uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: 21 + + - name: "Build library" + run: bash ./scripts/build-linux-x86_64.sh + + - name: "Run tests and build examples" + run: | + ./gradlew test + ./gradlew :examples:build + + publish: + name: "Publish bdk-jvm to Maven Central" + needs: [build-macOS-native-libs, build-windows-native-lib, test] + runs-on: ubuntu-24.04 + environment: maven-central + permissions: + contents: read + id-token: write + attestations: write + steps: + - name: "Check out tag" + uses: actions/checkout@v6 + with: + submodules: recursive + persist-credentials: false + fetch-depth: 0 + + - name: "Set up JDK" + uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: 17 + + - name: "Setup Gradle" + uses: gradle/actions/setup-gradle@v6 + + - name: "Build Linux native library and Kotlin bindings" + run: bash ./scripts/build-linux-x86_64.sh + + - name: "Download macOS native libraries" + uses: actions/download-artifact@v8 + with: + name: artifact-macos + path: lib/src/main/resources/ + + - name: "Download Windows native libraries" + uses: actions/download-artifact@v8 + with: + name: artifact-windows + path: lib/src/main/resources/ + + - name: "Verify all native libraries are present" + run: | + for lib in \ + linux-x86-64/libbdkffi.so \ + darwin-aarch64/libbdkffi.dylib \ + darwin-x86-64/libbdkffi.dylib \ + win32-x86-64/bdkffi.dll; do + if [[ ! -f "lib/src/main/resources/${lib}" ]]; then + echo "::error::Missing native library: ${lib}" + exit 1 + fi + done + find lib/src/main/resources -type f + + # Uploads the deployment to the Central Portal, where it must be published manually + # at https://central.sonatype.com. It does not release the library on its own. + - name: "Upload deployment 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_signingInMemoryKeyPassword: ${{ secrets.SIGNING_KEY_PASSWORD }} + run: ./gradlew :lib:publishToMavenCentral + + - name: "Generate build provenance attestation" + uses: actions/attest-build-provenance@v3 + with: + subject-path: lib/build/libs/*.jar