From 6eb889b849232652fd4159ca899ff2ff1a2cd6da Mon Sep 17 00:00:00 2001 From: barshaul Date: Mon, 4 Dec 2023 14:22:21 +0000 Subject: [PATCH] Added Continuous Deployment workflow to publish to NPM --- .github/workflows/cd.yml | 174 ++++++++++++++++++++++++++++++++++ node/.gitignore | 3 +- node/rust-client/package.json | 15 ++- 3 files changed, 183 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/cd.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000000..f08ef51797 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,174 @@ +name: Continuous Deployment + +on: + push: + tags: + - "v*.*" + +jobs: + publish-npm-binaries: + name: Publish NPM packages + runs-on: ${{ matrix.build.RUNNER }} + strategy: + fail-fast: false + matrix: + build: + - { + OS: ubuntu-latest, + NAMED_OS: linux, + RUNNER: ubuntu-latest, + ARCH: x64, + TARGET: x86_64-unknown-linux-gnu, + } + - { + OS: ubuntu-latest, + NAMED_OS: linux, + RUNNER: [self-hosted, Linux, ARM64], + ARCH: arm64, + TARGET: aarch64-unknown-linux-gnu, + } + - { + OS: macos-latest, + NAMED_OS: darwin, + RUNNER: macos-latest, + ARCH: x64, + TARGET: x86_64-apple-darwin, + } + - { + OS: macos-latest, + NAMED_OS: darwin, + RUNNER: macos-13-xlarge, + arch: arm64, + TARGET: aarch64-apple-darwin, + } + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: "true" + + - name: Set the release version + shell: bash + run: | + echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + target: ${{ matrix.build.TARGET }} + override: true + + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: "16" + registry-url: "https://registry.npmjs.org" + architecture: ${{ matrix.build.ARCH }} + scope: "${{ vars.NPM_SCOPE }}" + always-auth: true + token: ${{ secrets.NPM_AUTH_TOKEN }} + + - name: Build Node wrapper + uses: ./.github/workflows/build-node-wrapper + with: + os: ${{ matrix.build.OS }} + named_os: ${{ matrix.build.NAMED_OS }} + arch: ${{ matrix.build.ARCH }} + target: ${{ matrix.build.TARGET }} + npm_scope: ${{ vars.NPM_SCOPE }} + publish: "true" + + - name: Publish to NPM + shell: bash + working-directory: ./node + run: | + npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} + + - name: Pack the package + shell: bash + working-directory: ./node + run: | + # Remove the "cpu" and "os" fileds so the base package would be able to install it on ubuntu + SED_FOR_MACOS=`if [[ "${{ matrix.build.OS }}" =~ .*"macos".* ]]; then echo "''"; fi` + sed -i $SED_FOR_MACOS '/"cpu":/d' ./package.json && sed -i $SED_FOR_MACOS '/"os":/d' ./package.json + mkdir -p bin + npm pack --pack-destination ./bin + ls ./bin + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} + - name: Upload the package + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.build.TARGET }} + path: ./node/bin + if-no-files-found: error + + publish-npm-base: + name: Publish the base NPM package + needs: publish-npm-binaries + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: "true" + + - name: Install node + uses: actions/setup-node@v3 + with: + node-version: "16" + registry-url: "https://registry.npmjs.org" + scope: "${{ vars.NPM_SCOPE }}" + always-auth: true + + - name: Create package.json file + shell: bash + working-directory: ./node/npm/babushka + run: | + export pkg_name=babushka + echo "${GITHUB_REF:11}" + export package_version=${GITHUB_REF:11} + export scope=`if [ "$NPM_SCOPE" != '' ]; then echo "$NPM_SCOPE/"; fi` + envsubst < package.json.tmpl > "package.json" + cat package.json + # Fix index.ts based on the scope variable + sed -i "s|@scope/|${scope}|g" index.ts + env: + NPM_SCOPE: ${{ vars.NPM_SCOPE }} + + - name: Create a directory for the packed packages + shell: bash + working-directory: ./node/npm/babushka + run: mkdir packages + + - name: Download the packed packages + id: download + uses: actions/download-artifact@v3 + with: + path: ./node/npm/babushka/packages + + - name: Install the packed packages + shell: bash + working-directory: ./node/npm/babushka + run: | + ls -LR packages/ + packages_list=`find ${{steps.download.outputs.download-path}} -type f -follow -print` + for package in $packages_list + do + echo "Installing package $package" + npm i --no-save "$package" + done + + - name: Publish the base package + shell: bash + working-directory: ./node/npm/babushka + run: | + # Copy the main README file + cp ../../README.md . + npm install + npm run build + npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/node/.gitignore b/node/.gitignore index 9f689ba097..896b8bf174 100644 --- a/node/.gitignore +++ b/node/.gitignore @@ -6,7 +6,6 @@ yarn-debug.log* yarn-error.log* lerna-debug.log* .pnpm-debug.log* -npm/ rust-client/index.* @@ -137,4 +136,6 @@ yarn.lock # Protobuf src/ProtobufMessage* + +.npmignore package.json diff --git a/node/rust-client/package.json b/node/rust-client/package.json index 83d543c86f..f544c30e41 100644 --- a/node/rust-client/package.json +++ b/node/rust-client/package.json @@ -1,12 +1,13 @@ { "name": "babushka-rs-internal", - "version": "1.0.0", + "version": "0.1.0", "description": "Redis client", "main": "index.js", - "license": "MIT", + "license": "Apache-2.0", "files": [ "index.d.ts", - "index.js" + "index.js", + "babushka*.*.node" ], "napi": { "name": "babushka-rs-internal", @@ -15,13 +16,11 @@ "additional": [ "x86_64-unknown-linux-musl", "aarch64-unknown-linux-gnu", - "i686-pc-windows-msvc", "armv7-unknown-linux-gnueabihf", "aarch64-apple-darwin", "aarch64-linux-android", "x86_64-unknown-freebsd", "aarch64-unknown-linux-musl", - "aarch64-pc-windows-msvc", "armv7-linux-androideabi" ] } @@ -35,9 +34,9 @@ }, "scripts": { "artifacts": "napi artifacts", - "build": "npm install && napi build --platform --pipe \"prettier -w\"", - "build:release": "npm install && napi build --platform --release --strip --pipe \"prettier -w\"", - "build:benchmark": "npm install && napi build --platform --release --pipe \"prettier -w\"", + "build": "npm install && napi build --platform --pipe \"prettier -w\" $npm_config_build_flags", + "build:release": "npm install && napi build --platform --release --strip --pipe \"prettier -w\" $npm_config_build_flags", + "build:benchmark": "npm install && napi build --platform --release --pipe \"prettier -w\" $npm_config_build_flags", "format": "run-p format:prettier format:rs", "format:prettier": "prettier . -w", "format:rs": "cargo fmt",