From 6ccf62d3fad71ea9ca5905b16797f787f2993eb6 Mon Sep 17 00:00:00 2001 From: Thom Nichols <95562+thom-nic@users.noreply.github.com> Date: Tue, 14 Dec 2021 13:16:12 -0500 Subject: [PATCH] .github: added github actions --- .github/workflows/build-pack-publish.yml | 101 +++++++++++++++++++++++ .github/workflows/ci.yaml | 9 +- .travis.yml | 1 + Dockerfile | 67 --------------- Dockerfile-arm | 4 +- Dockerfile-arm64 | 4 +- Dockerfile-x64 | 43 ++++++++++ appveyor.yml | 2 + build-all.sh | 14 ++-- 9 files changed, 161 insertions(+), 84 deletions(-) create mode 100644 .github/workflows/build-pack-publish.yml delete mode 100755 Dockerfile create mode 100755 Dockerfile-x64 diff --git a/.github/workflows/build-pack-publish.yml b/.github/workflows/build-pack-publish.yml new file mode 100644 index 0000000..88d6d58 --- /dev/null +++ b/.github/workflows/build-pack-publish.yml @@ -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: 20 + 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' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: 20 + 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' + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: 20 + 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}} + + + + diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index afc6a86..4c7deb5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,16 +13,13 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - node-version: [14.x, 16.x, 18.x] + node-version: [14, 16, 18, 20] steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 + uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - - name: Install dependencies - run: | - sudo apt-get install -y python3 make g++ - name: Test run: npm test @@ -30,7 +27,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - node-version: [14, 16, 18] + node-version: [14, 16, 18, 20] container: image: node:${{ matrix.node-version }}-alpine steps: diff --git a/.travis.yml b/.travis.yml index d13f941..7c94bf9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,7 @@ node_js: - '16' - '17' - '18' +- '18' addons: apt: diff --git a/Dockerfile b/Dockerfile deleted file mode 100755 index fd55fb4..0000000 --- a/Dockerfile +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/echo docker build . -f -# -*- coding: utf-8 -*- -# SPDX-License-Identifier: ISC -# Copyright 2021 VoltServer Inc -#{ -# ISC License -# Copyright (c) 2004-2010 by Internet Systems Consortium, Inc. ("ISC") -# Copyright (c) 1995-2003 by Internet Software Consortium -# Permission to use, copy, modify, and /or distribute this software -# for any purpose with or without fee is hereby granted, -# provided that the above copyright notice -# and this permission notice appear in all copies. -# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES -# OF MERCHANTABILITY AND FITNESS. -# IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, -# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -# WHETHER IN AN ACTION OF CONTRACT, -# NEGLIGENCE OR OTHER TORTIOUS ACTION, -# ARISING OUT OF OR IN CONNECTION WITH THE USE -# OR PERFORMANCE OF THIS SOFTWARE. -#} -# -# Usage: -# -# docker build -t voltserver/bcryptjs-linux-x64-builder . -# docker create --name donut voltserver/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 diff --git a/Dockerfile-arm b/Dockerfile-arm index ecddc1c..40a7703 100755 --- a/Dockerfile-arm +++ b/Dockerfile-arm @@ -20,7 +20,7 @@ RUN echo "#log: ${project}: Setup system" \ python3 \ && apt-get clean \ && update-alternatives --install /usr/local/bin/python python /usr/bin/python3 20 \ - && npm i -g prebuildify node-gyp \ + && npm i -g prebuildify node-gyp nodeunit \ && sync ADD . /usr/local/opt/${project} @@ -28,7 +28,7 @@ WORKDIR /usr/local/opt/${project} RUN echo "#log: ${project}: Running build" \ && set -x \ - && npm i \ + && npm ci \ && npm run build ARG RUN_TESTS=true diff --git a/Dockerfile-arm64 b/Dockerfile-arm64 index 92256c5..9ab11cc 100755 --- a/Dockerfile-arm64 +++ b/Dockerfile-arm64 @@ -20,7 +20,7 @@ RUN echo "#log: ${project}: Setup system" \ python3 \ && apt-get clean \ && update-alternatives --install /usr/local/bin/python python /usr/bin/python3 20 \ - && npm i -g prebuildify node-gyp \ + && npm i -g prebuildify node-gyp nodeunit \ && sync ADD . /usr/local/opt/${project} @@ -28,7 +28,7 @@ WORKDIR /usr/local/opt/${project} RUN echo "#log: ${project}: Running build" \ && set -x \ - && npm i \ + && npm ci \ && npm run build ARG RUN_TESTS=true diff --git a/Dockerfile-x64 b/Dockerfile-x64 new file mode 100755 index 0000000..02723f7 --- /dev/null +++ b/Dockerfile-x64 @@ -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 nodeunit \ + && sync + +ADD . /usr/local/opt/${project} +WORKDIR /usr/local/opt/${project} + +RUN echo "#log: ${project}: Running build" \ + && set -x \ + && npm ci \ + && 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 diff --git a/appveyor.yml b/appveyor.yml index 51d10c1..36b7b37 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,6 +10,8 @@ environment: platform: x86 - nodejs_version: "18" platform: x64 + - nodejs_version: "20" + platform: x64 install: - where npm diff --git a/build-all.sh b/build-all.sh index b3194ea..fcd89ab 100755 --- a/build-all.sh +++ b/build-all.sh @@ -1,7 +1,7 @@ #!/bin/bash -ue CLEAN=${CLEAN:-""} -RUN_TESTS=${RUN_TESTS:-false} # tests presently fail on arm :( +RUN_TESTS=${RUN_TESTS:-true} if [ -n "$CLEAN" ]; then rm -rf build build-tmp* @@ -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 --build-arg RUN_TESTS="$RUN_TESTS" . + 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