From 03d14f387e7479a6fdc4d19fd863912598f20f3b Mon Sep 17 00:00:00 2001 From: shum Date: Mon, 12 Oct 2026 10:42:23 +0000 Subject: [PATCH] ci: release nodejs add-on and open release PR --- .github/workflows/build.yml | 50 ++------- .github/workflows/nodejs-addon.yml | 121 ++++++++++++++++++++++ .github/workflows/packages-release-pr.yml | 85 +++++++++++++++ 3 files changed, 213 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/nodejs-addon.yml create mode 100644 .github/workflows/packages-release-pr.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a31abff398..13216a1b07 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -839,49 +839,13 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} # ========================= -# Node.js add-on +# Packages release PR # ========================= - build-nodejs-addon: - name: "Node.js add-on ${{ matrix.platform }}" - needs: [maybe-release] - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - include: - - os: ubuntu-22.04 - platform: linux-x86_64 - - os: ubuntu-22.04-arm - platform: linux-aarch64 - - os: macos-latest - platform: macos-aarch64 - - os: macos-15-intel - platform: macos-x86_64 - - os: windows-latest - platform: windows-x86_64 - defaults: - run: - shell: bash - working-directory: packages/simplex-chat-nodejs - steps: - - name: Checkout Code - uses: actions/checkout@v6 +# A new library release updates the Node.js and Python packages in a release PR. - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: 22 - - - name: Build add-on - run: | - npm install --ignore-scripts --no-audit --no-fund - npx --yes node-gyp rebuild - cp build/Release/simplex.node build/simplex-chat-nodejs-${{ matrix.platform }}.node - - - name: Upload add-on artifact - uses: actions/upload-artifact@v4 - with: - name: simplex-nodejs-addon-${{ matrix.platform }} - path: packages/simplex-chat-nodejs/build/simplex-chat-nodejs-${{ matrix.platform }}.node - if-no-files-found: error + packages-release-pr: + needs: [maybe-release, build-linux, build-linux-postgres, build-macos, build-windows] + if: ${{ !cancelled() && needs.maybe-release.outputs.libs_tag }} + uses: ./.github/workflows/packages-release-pr.yml + secrets: inherit diff --git a/.github/workflows/nodejs-addon.yml b/.github/workflows/nodejs-addon.yml new file mode 100644 index 0000000000..63b72cdf6e --- /dev/null +++ b/.github/workflows/nodejs-addon.yml @@ -0,0 +1,121 @@ +name: nodejs add-on + +# Builds the Node.js add-on on every platform for pull requests. A push to master or stable builds and +# releases it to simplex-chat-libs as nodejs-addon-, when that release does not exist yet, +# and updates the packages release PR. + +# Secrets: +# ------- +# NODEJS_REPO_TOKEN +# Only select repositories: simplex-chat-libs +# Permissions: +# * Contents (Read and Write) + +on: + workflow_dispatch: + push: + branches: + - master + - stable + paths: + - "packages/simplex-chat-nodejs/cpp/**" + - "packages/simplex-chat-nodejs/binding.gyp" + - "packages/simplex-chat-nodejs/package.json" + - ".github/workflows/nodejs-addon.yml" + pull_request: + paths: + - "packages/simplex-chat-nodejs/cpp/**" + - "packages/simplex-chat-nodejs/binding.gyp" + - ".github/workflows/nodejs-addon.yml" + +jobs: + tag: + runs-on: ubuntu-latest + outputs: + tag: ${{ steps.tag.outputs.tag }} + release: ${{ steps.tag.outputs.release }} + steps: + - name: Checkout Code + uses: actions/checkout@v6 + + - name: Release tag + id: tag + env: + GH_TOKEN: ${{ secrets.NODEJS_REPO_TOKEN }} + run: | + tag=$(python3 scripts/ci/packages_release.py addon-tag) + echo "tag=$tag" >> "$GITHUB_OUTPUT" + if [ "${{ github.event_name }}" != pull_request ] && { [ "${{ github.ref }}" = refs/heads/master ] || [ "${{ github.ref }}" = refs/heads/stable ]; } \ + && ! gh release view "$tag" --repo "${{ github.repository }}-libs" > /dev/null 2>&1; then + echo "release=true" >> "$GITHUB_OUTPUT" + fi + + build: + name: "build ${{ matrix.platform }}" + needs: tag + if: github.event_name == 'pull_request' || needs.tag.outputs.release == 'true' + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-22.04 + platform: linux-x86_64 + - os: ubuntu-22.04-arm + platform: linux-aarch64 + - os: macos-latest + platform: macos-aarch64 + - os: macos-15-intel + platform: macos-x86_64 + - os: windows-latest + platform: windows-x86_64 + defaults: + run: + shell: bash + working-directory: packages/simplex-chat-nodejs + steps: + - name: Checkout Code + uses: actions/checkout@v6 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 22 + + - name: Build add-on + run: | + npm install --ignore-scripts --no-audit --no-fund + npx --yes node-gyp rebuild + cp build/Release/simplex.node build/simplex-chat-nodejs-${{ matrix.platform }}.node + + - name: Upload add-on artifact + uses: actions/upload-artifact@v4 + with: + name: simplex-nodejs-addon-${{ matrix.platform }} + path: packages/simplex-chat-nodejs/build/simplex-chat-nodejs-${{ matrix.platform }}.node + if-no-files-found: error + + release: + runs-on: ubuntu-latest + needs: [tag, build] + if: needs.tag.outputs.release == 'true' + steps: + - name: Download add-on artifacts + uses: actions/download-artifact@v4 + with: + pattern: simplex-nodejs-addon-* + merge-multiple: true + path: addons + + - name: Create add-on release + uses: softprops/action-gh-release@v2 + with: + repository: ${{ github.repository }}-libs + tag_name: ${{ needs.tag.outputs.tag }} + files: addons/*.node + token: ${{ secrets.NODEJS_REPO_TOKEN }} + + packages-release-pr: + needs: release + uses: ./.github/workflows/packages-release-pr.yml + secrets: inherit diff --git a/.github/workflows/packages-release-pr.yml b/.github/workflows/packages-release-pr.yml new file mode 100644 index 0000000000..0f82fdbfb7 --- /dev/null +++ b/.github/workflows/packages-release-pr.yml @@ -0,0 +1,85 @@ +name: packages release PR + +# Opens or updates the release PR of simplex-chat (npm, PyPI) and @simplex-chat/types for this branch: +# pins of new library and add-on releases with their SHA-256, and version bumps of changed packages. +# Merging the PR publishes the packages (packages-publish.yml). + +# Secrets: +# ------- +# NODEJS_REPO_TOKEN +# Reads releases of simplex-chat-libs +# RELEASE_PR_TOKEN +# Only select repositories: simplex-chat +# Permissions: +# * Contents (Read and Write) +# * Pull requests (Read and Write) +# A PR opened with GITHUB_TOKEN does not run the checks of other workflows. + +on: + workflow_dispatch: + inputs: + nodejs_version: + description: "simplex-chat npm version, bumped when needed by default" + required: false + types_version: + description: "@simplex-chat/types version, bumped when needed by default" + required: false + python_version: + description: "simplex-chat PyPI version, bumped when needed by default" + required: false + workflow_call: + push: + branches: + - master + - stable + paths: + - "packages/simplex-chat-nodejs/**" + - "packages/simplex-chat-client/types/typescript/**" + - "packages/simplex-chat-python/**" + # nodejs-addon.yml updates the PR after the add-on release + - "!packages/simplex-chat-nodejs/cpp/**" + - "!packages/simplex-chat-nodejs/binding.gyp" + +concurrency: + group: packages-release-pr-${{ github.ref }} + cancel-in-progress: false + +jobs: + release-pr: + # A merged release PR changes only versions and pins. + if: "${{ !startsWith(github.event.head_commit.message, 'packages: release') }}" + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: Update pins and versions + id: prepare + env: + GH_TOKEN: ${{ secrets.NODEJS_REPO_TOKEN }} + LIBS_REPOSITORY: ${{ github.repository }}-libs + NPM_SCOPE: ${{ vars.NPM_SCOPE }} + PYPI_URL: ${{ vars.PYPI_URL }} + PYPI_PROJECT: ${{ vars.PYPI_PROJECT }} + run: | + python3 scripts/ci/packages_release.py prepare \ + --nodejs-version "${{ inputs.nodejs_version }}" \ + --types-version "${{ inputs.types_version }}" \ + --python-version "${{ inputs.python_version }}" \ + --summary "$RUNNER_TEMP/summary.md" + echo "title=$(head -n 1 "$RUNNER_TEMP/summary.md")" >> "$GITHUB_OUTPUT" + + - name: Create or update release PR + uses: peter-evans/create-pull-request@v7 + with: + token: ${{ secrets.RELEASE_PR_TOKEN }} + branch: packages-release/${{ github.ref_name }} + base: ${{ github.ref_name }} + title: ${{ steps.prepare.outputs.title }} + commit-message: ${{ steps.prepare.outputs.title }} + body-path: ${{ runner.temp }}/summary.md + author: SimpleX Chat + committer: SimpleX Chat + delete-branch: true