diff --git a/.github/workflows/go_release.yml b/.github/workflows/go_release.yml new file mode 100644 index 000000000..e55bb2077 --- /dev/null +++ b/.github/workflows/go_release.yml @@ -0,0 +1,163 @@ +name: Go Release +on: + pull_request: # TODO REMOVE + workflow_dispatch: + inputs: + version: # TODO remove? + description: "Version for the go package" + required: true + type: string + level: + description: | + The level of version bump to make. + + Possible values: + - major: Increase the major version (x.0.0) + - minor: Increase the minor version (x.y.0) + - patch: Increase the patch version (x.y.z) + - release: Remove the pre-version (x.y.z) + - rc: Increase the rc pre-version (x.y.z-rc.M) + - beta: Increase the beta pre-version (x.y.z-beta.M) + - alpha: Increase the alpha pre-version (x.y.z-alpha.M) + type: choice + required: true + options: # TODO take from semver cmd + - major + - minor + - patch + - release + - rc + - beta + - alpha + +jobs: + prepare-source-archive: + name: Prepare source archive + runs-on: ubuntu-latest + steps: + - name: Checkout iota-rust-sdk + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5.0.0 + + - name: Archive Go bindings + uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 + with: + name: source + path: bindings/go/iota_sdk + + prepare-build-archives: + strategy: + matrix: + include: + - os: macos-latest + target: x86_64-apple-darwin + lib: libiota_sdk_ffi.dylib + folder: darwin-amd64 + - os: macos-latest + target: aarch64-apple-darwin + lib: libiota_sdk_ffi.dylib + folder: darwin-aarch64 + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + lib: libiota_sdk_ffi.so + folder: linux-amd64 + - os: ubuntu-latest + target: aarch64-unknown-linux-gnu + lib: libiota_sdk_ffi.so + folder: linux-aarch64 + - os: windows-latest + target: x86_64-pc-windows-msvc + lib: iota_sdk_ffi.dll + folder: windows-amd64 + - os: windows-latest + target: aarch64-pc-windows-msvc + lib: iota_sdk_ffi.dll + folder: windows-aarch64 + runs-on: ${{ matrix.os }} + steps: + - name: Checkout iota-rust-sdk + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5.0.0 + + - name: Install rust target ${{ matrix.target }} + run: rustup target add ${{ matrix.target }} + + - name: Install gcc-aarch64-linux-gnu + if: matrix.target == 'aarch64-unknown-linux-gnu' + run: | + sudo apt-get update -y + sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + + - name: Install gcc-x86-64-linux-gnu + if: matrix.target == 'x86_64-unknown-linux-gnu' + run: | + sudo apt-get update -y + sudo apt-get install -y gcc-x86-64-linux-gnu g++-x86-64-linux-gnu + + - name: Build ${{ matrix.target }} bindings + if: matrix.os == 'macos-latest' + run: RUSTFLAGS="-C link-args=-Wl,-install_name,@rpath/${{ matrix.lib }}" cargo build -p iota-sdk-ffi --lib --release --target ${{ matrix.target }} + + - name: Build ${{ matrix.target }} bindings + if: matrix.os == 'ubuntu-latest' + env: + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: /usr/bin/aarch64-linux-gnu-gcc + CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER: /usr/bin/x86_64-linux-gnu-gcc + run: RUSTFLAGS="-C link-args=-Wl,-rpath,$ORIGIN" cargo build -p iota-sdk-ffi --lib --release --target ${{ matrix.target }} + + - name: Build ${{ matrix.target }} bindings + if: matrix.os == 'windows-latest' + run: cargo build -p iota-sdk-ffi --lib --release --target ${{ matrix.target }} + + - name: Prepare upload + run: | + mkdir -p tmp/lib/${{ matrix.folder }} + cp target/${{ matrix.target }}/release/${{ matrix.lib }} tmp/lib/${{ matrix.folder }}/${{ matrix.lib }} + + - name: Archive ${{ matrix.target }} bindings + uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 + with: + name: ${{ matrix.target }} + path: tmp + + release-archives: + name: Release archives + runs-on: ubuntu-latest + needs: + - prepare-source-archive + - prepare-build-archives + steps: + - name: Checkout iota-sdk-go + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5.0.0 + with: + repository: iotaledger/iota-sdk-go + ssh-key: ${{ secrets.SSH_PRIVATE_KEY_FOR_GO_SDK }} + fetch-depth: 0 + + - name: Get latest tag from iota-sdk-go + id: get-latest-tag + run: | + LATEST_TAG=$(git tag --sort=-v:refname | head -n 1) + if [ -z "$LATEST_TAG" ]; then + LATEST_TAG="v0.0.0" + fi + echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT + echo "Latest tag: $LATEST_TAG" + + - uses: actions-ecosystem/action-bump-semver@34e334551143a5301f38c830e44a22273c6ff5c5 # v1.0.0 + id: bump-semver + with: + current_version: ${{ steps.get-latest-tag.outputs.tag }} + level: ${{ inputs.level || 'patch' }} # TODO undo + + - uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 + with: + merge-multiple: true + + - name: Tag the Go package + run: | + git config --global user.email github-actions@github.com + git config --global user.name github-actions + git add . + git commit -m "Update Go bindings to version ${{ steps.bump-semver.outputs.new_version }}" + git push + git tag ${{ steps.bump-semver.outputs.new_version }} -m "${{ steps.bump-semver.outputs.new_version }}" + git push --tags