Skip to content

Commit

Permalink
.github: added github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
thom-nic committed Dec 14, 2021
1 parent 1e0f357 commit 5956934
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 73 deletions.
101 changes: 101 additions & 0 deletions .github/workflows/build-pack-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Prebuildify, package, publish

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
release:
types: [ prereleased, released ]

jobs:

build:
runs-on: ubuntu-latest
strategy:
matrix:
arch: [x64, arm, arm64]
steps:
- uses: actions/checkout@v2
- uses: docker/setup-qemu-action@v1
with:
image: tonistiigi/binfmt:latest
platforms: arm,arm64 #all
- run: docker build . -f ./Dockerfile-${{ matrix.arch }}
--tag node-bcrypt-builder-${{ matrix.arch }}
- run: docker create --name node-bcryptjs-builder node-bcrypt-builder-${{ matrix.arch }}
- run: docker cp "node-bcryptjs-builder:/usr/local/opt/bcrypt-js/prebuilds" .
- run: find prebuilds
- uses: actions/upload-artifact@v2
with:
name: prebuild-${{ matrix.arch }}
path: ./prebuilds

pack:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- uses: actions/download-artifact@v2
with:
path: /tmp/prebuilds/
- name: Coalesce prebuilds from build matrix
run: |
mkdir prebuilds
for d in /tmp/prebuilds/*; do
mv $d/* prebuilds/
done
- run: chmod a+x prebuilds/*/*.node && find prebuilds -executable -type f
- run: echo "PACK_FILE=$(npm pack)" >> $GITHUB_ENV
- uses: actions/upload-artifact@v2
with:
name: package-tgz
path: ${{ env.PACK_FILE }}

publish-npm:
needs: pack
if: github.event_name == 'release' && contains('prereleased,released', github.event.action)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
- uses: actions/download-artifact@v2
with:
name: package-tgz
path: /tmp/package/
- run: npm publish /tmp/package/bcrypt*.tgz
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

publish-gpr:
needs: pack
if: github.event_name == 'release' && contains('prereleased,released', github.event.action)
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
registry-url: https://npm.pkg.github.com/
- uses: actions/download-artifact@v2
with:
name: package-tgz
path: /tmp/package/
- run: npm publish /tmp/package/bcrypt*.tgz
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}




29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: Test on PR/ Merge

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test-and-build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12, 14, 16]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm i -g prebuildify node-gyp
- run: npm ci
- run: npm test
- run: npm run build
67 changes: 0 additions & 67 deletions Dockerfile

This file was deleted.

43 changes: 43 additions & 0 deletions Dockerfile-x64
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Usage:
#
# docker build -t bcryptjs-linux-x64-builder .
# docker create --name donut bcryptjs-linux-x64-builder
# # Then copy the artifact to your host:
# docker cp donut:/usr/local/opt/bcrypt-js/prebuilds .

FROM node:14-bullseye

ENV project bcrypt-js
ENV DEBIAN_FRONTEND noninteractive
ENV LC_ALL en_US.UTF-8
ENV LANG ${LC_ALL}

RUN echo "#log: ${project}: Setup system" \
&& set -x \
&& apt-get update -y \
&& apt-get install -y \
build-essential \
python3 \
&& apt-get clean \
&& update-alternatives --install /usr/local/bin/python python /usr/bin/python3 20 \
&& npm i -g prebuildify node-gyp \
&& sync

ADD . /usr/local/opt/${project}
WORKDIR /usr/local/opt/${project}

RUN echo "#log: ${project}: Running build" \
&& set -x \
&& npm i \
&& npm run build

ARG RUN_TESTS=true

RUN if "${RUN_TESTS}"; then \
echo "#log ${project}: Running tests" \
&& npm test; \
else \
echo "#log ${project}: Tests were skipped!"; \
fi

CMD /bin/bash -l
12 changes: 6 additions & 6 deletions build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ npm run build

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

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

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

0 comments on commit 5956934

Please sign in to comment.