Skip to content

Commit

Permalink
Added Continuous Deployment workflow to publish to NPM
Browse files Browse the repository at this point in the history
  • Loading branch information
barshaul committed Dec 7, 2023
1 parent 6ab0d3f commit 6eb889b
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 9 deletions.
174 changes: 174 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -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 }}
3 changes: 2 additions & 1 deletion node/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
npm/
rust-client/index.*


Expand Down Expand Up @@ -137,4 +136,6 @@ yarn.lock

# Protobuf
src/ProtobufMessage*

.npmignore
package.json
15 changes: 7 additions & 8 deletions node/rust-client/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
]
}
Expand All @@ -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",
Expand Down

0 comments on commit 6eb889b

Please sign in to comment.