Skip to content

Commit 5956934

Browse files
committed
.github: added github actions
1 parent 1e0f357 commit 5956934

File tree

5 files changed

+179
-73
lines changed

5 files changed

+179
-73
lines changed
+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Prebuildify, package, publish
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
release:
9+
types: [ prereleased, released ]
10+
11+
jobs:
12+
13+
build:
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
arch: [x64, arm, arm64]
18+
steps:
19+
- uses: actions/checkout@v2
20+
- uses: docker/setup-qemu-action@v1
21+
with:
22+
image: tonistiigi/binfmt:latest
23+
platforms: arm,arm64 #all
24+
- run: docker build . -f ./Dockerfile-${{ matrix.arch }}
25+
--tag node-bcrypt-builder-${{ matrix.arch }}
26+
- run: docker create --name node-bcryptjs-builder node-bcrypt-builder-${{ matrix.arch }}
27+
- run: docker cp "node-bcryptjs-builder:/usr/local/opt/bcrypt-js/prebuilds" .
28+
- run: find prebuilds
29+
- uses: actions/upload-artifact@v2
30+
with:
31+
name: prebuild-${{ matrix.arch }}
32+
path: ./prebuilds
33+
34+
pack:
35+
needs: build
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v2
39+
- uses: actions/setup-node@v2
40+
with:
41+
node-version: 16
42+
registry-url: 'https://registry.npmjs.org'
43+
- run: npm ci
44+
- uses: actions/download-artifact@v2
45+
with:
46+
path: /tmp/prebuilds/
47+
- name: Coalesce prebuilds from build matrix
48+
run: |
49+
mkdir prebuilds
50+
for d in /tmp/prebuilds/*; do
51+
mv $d/* prebuilds/
52+
done
53+
- run: chmod a+x prebuilds/*/*.node && find prebuilds -executable -type f
54+
- run: echo "PACK_FILE=$(npm pack)" >> $GITHUB_ENV
55+
- uses: actions/upload-artifact@v2
56+
with:
57+
name: package-tgz
58+
path: ${{ env.PACK_FILE }}
59+
60+
publish-npm:
61+
needs: pack
62+
if: github.event_name == 'release' && contains('prereleased,released', github.event.action)
63+
runs-on: ubuntu-latest
64+
steps:
65+
- uses: actions/checkout@v2
66+
- uses: actions/setup-node@v2
67+
with:
68+
node-version: 16
69+
registry-url: 'https://registry.npmjs.org'
70+
- uses: actions/download-artifact@v2
71+
with:
72+
name: package-tgz
73+
path: /tmp/package/
74+
- run: npm publish /tmp/package/bcrypt*.tgz
75+
env:
76+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
77+
78+
publish-gpr:
79+
needs: pack
80+
if: github.event_name == 'release' && contains('prereleased,released', github.event.action)
81+
runs-on: ubuntu-latest
82+
permissions:
83+
contents: read
84+
packages: write
85+
steps:
86+
- uses: actions/checkout@v2
87+
- uses: actions/setup-node@v2
88+
with:
89+
node-version: 16
90+
registry-url: https://npm.pkg.github.com/
91+
- uses: actions/download-artifact@v2
92+
with:
93+
name: package-tgz
94+
path: /tmp/package/
95+
- run: npm publish /tmp/package/bcrypt*.tgz
96+
env:
97+
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
98+
99+
100+
101+

.github/workflows/test.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3+
4+
name: Test on PR/ Merge
5+
6+
on:
7+
push:
8+
branches: [ master ]
9+
pull_request:
10+
branches: [ master ]
11+
12+
jobs:
13+
test-and-build:
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
node-version: [12, 14, 16]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Use Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v2
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
- run: npm i -g prebuildify node-gyp
27+
- run: npm ci
28+
- run: npm test
29+
- run: npm run build

Dockerfile

-67
This file was deleted.

Dockerfile-x64

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Usage:
2+
#
3+
# docker build -t bcryptjs-linux-x64-builder .
4+
# docker create --name donut bcryptjs-linux-x64-builder
5+
# # Then copy the artifact to your host:
6+
# docker cp donut:/usr/local/opt/bcrypt-js/prebuilds .
7+
8+
FROM node:14-bullseye
9+
10+
ENV project bcrypt-js
11+
ENV DEBIAN_FRONTEND noninteractive
12+
ENV LC_ALL en_US.UTF-8
13+
ENV LANG ${LC_ALL}
14+
15+
RUN echo "#log: ${project}: Setup system" \
16+
&& set -x \
17+
&& apt-get update -y \
18+
&& apt-get install -y \
19+
build-essential \
20+
python3 \
21+
&& apt-get clean \
22+
&& update-alternatives --install /usr/local/bin/python python /usr/bin/python3 20 \
23+
&& npm i -g prebuildify node-gyp \
24+
&& sync
25+
26+
ADD . /usr/local/opt/${project}
27+
WORKDIR /usr/local/opt/${project}
28+
29+
RUN echo "#log: ${project}: Running build" \
30+
&& set -x \
31+
&& npm i \
32+
&& npm run build
33+
34+
ARG RUN_TESTS=true
35+
36+
RUN if "${RUN_TESTS}"; then \
37+
echo "#log ${project}: Running tests" \
38+
&& npm test; \
39+
else \
40+
echo "#log ${project}: Tests were skipped!"; \
41+
fi
42+
43+
CMD /bin/bash -l

build-all.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ npm run build
1414

1515
# build for linux/x64:
1616
if [ ! -d prebuilds/linux-x64 ]; then
17-
docker build -t voltserver/bcryptjs-linux-x64-builder .
18-
CONTAINER=$(docker create voltserver/bcryptjs-linux-x64-builder)
17+
docker build -t bcryptjs-linux-x64-builder -f Dockerfile-x64 .
18+
CONTAINER=$(docker create bcryptjs-linux-x64-builder)
1919
docker cp "$CONTAINER:/usr/local/opt/bcrypt-js/prebuilds" .
2020
docker rm "$CONTAINER"
2121
fi
2222

2323
# build for linux/arm32:
2424
if [ ! -d prebuilds/linux-arm ]; then
25-
docker build -t voltserver/bcryptjs-linux-arm-builder -f Dockerfile-arm --build-arg RUN_TESTS="$RUN_TESTS" .
26-
CONTAINER=$(docker create --platform linux/arm/v7 voltserver/bcryptjs-linux-arm-builder)
25+
docker build -t bcryptjs-linux-arm-builder -f Dockerfile-arm --build-arg RUN_TESTS="$RUN_TESTS" .
26+
CONTAINER=$(docker create --platform linux/arm/v7 bcryptjs-linux-arm-builder)
2727
docker cp "$CONTAINER:/usr/local/opt/bcrypt-js/prebuilds" .
2828
docker rm "$CONTAINER"
2929
fi
3030

3131
# build for linux/arm64:
3232
if [ ! -d prebuilds/linux-arm64 ]; then
33-
docker build -t voltserver/bcryptjs-linux-arm64-builder -f Dockerfile-arm64 --build-arg RUN_TESTS="$RUN_TESTS" .
34-
CONTAINER=$(docker create --platform linux/arm64/v8 voltserver/bcryptjs-linux-arm64-builder)
33+
docker build -t bcryptjs-linux-arm64-builder -f Dockerfile-arm64 --build-arg RUN_TESTS="$RUN_TESTS" .
34+
CONTAINER=$(docker create --platform linux/arm64/v8 bcryptjs-linux-arm64-builder)
3535
docker cp "$CONTAINER:/usr/local/opt/bcrypt-js/prebuilds" .
3636
docker rm "$CONTAINER"
3737
fi

0 commit comments

Comments
 (0)