-
Notifications
You must be signed in to change notification settings - Fork 53
203 lines (185 loc) · 7.46 KB
/
npm-cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# The cross platform build was created based on the [Packaging Rust Applications for the NPM Registry blog](https://blog.orhun.dev/packaging-rust-for-npm/).
name: Continuous Deployment
on:
push:
tags:
- "v*.*"
pull_request:
paths:
- .github/workflows/npm-cd.yml
jobs:
publish-binaries:
name: Publish packages to NPM
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,
NPM_PUBLISH: true,
PYPI_PUBLISH: false,
}
- {
OS: ubuntu-latest,
NAMED_OS: linux,
RUNNER: [self-hosted, Linux, ARM64],
ARCH: arm64,
TARGET: aarch64-unknown-linux-gnu,
NPM_PUBLISH: true,
PYPI_PUBLISH: false,
CONTAINER: "2_28",
}
- {
OS: macos-latest,
NAMED_OS: darwin,
RUNNER: macos-latest,
ARCH: x64,
TARGET: x86_64-apple-darwin,
NPM_PUBLISH: true,
PYPI_PUBLISH: false,
}
- {
OS: macos-latest,
NAMED_OS: darwin,
RUNNER: macos-13-xlarge,
arch: arm64,
TARGET: aarch64-apple-darwin,
NPM_PUBLISH: true,
PYPI_PUBLISH: false,
}
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
echo "RELEASE_VERSION=0.1.2" >> $GITHUB_ENV
###### NODEJS #####
- name: Setup node
if: matrix.build.NPM_PUBLISH == true
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
if: matrix.build.NPM_PUBLISH == true
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"
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to NPM
if: matrix.build.NPM_PUBLISH == true
shell: bash
working-directory: ./node
run: |
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
- name: Pack the Node package
if: matrix.build.NPM_PUBLISH == true
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 Node package
if: matrix.build.NPM_PUBLISH == true
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.build.TARGET }}
path: ./node/bin
if-no-files-found: error
publish-base-to-npm:
name: Publish the base NPM package
needs: publish-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/glide
run: |
export pkg_name=glide-for-redis
echo "${GITHUB_REF:11}"
export package_version=${GITHUB_REF:11}
export scope=`if [ "$NPM_SCOPE" != '' ]; then echo "$NPM_SCOPE/"; fi`
mv package.json package.json.tmpl
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: Build Node wrapper
uses: ./.github/workflows/build-node-wrapper
with:
os: ubuntu-latest
target: "x86_64-unknown-linux-gnu"
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Create a directory for the packed packages
shell: bash
working-directory: ./node/npm/glide
run: mkdir packages
- name: Download the packed packages
id: download
uses: actions/download-artifact@v3
with:
path: ./node/npm/glide/packages
- name: Install the packed packages
shell: bash
working-directory: ./node/npm/glide
run: |
ls -LR packages/
packages_list=`find ${{steps.download.outputs.download-path}} -type f -follow -print`
for package in $packages_list
do
if [[ "${package}" == *.tgz ]]
then
echo "Installing package $package"
npm i --no-save "$package"
fi
done
- name: Publish the base package
shell: bash
working-directory: ./node/npm/glide
run: |
# Copy the main README file
cp ../../README.md .
npm install
npm run build
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}