minify-html/.github/workflows/nodejs.yml

119 lines
3.7 KiB
YAML
Raw Normal View History

name: Build and publish Node.js package
on:
create:
tags:
- 'v*'
2021-07-26 12:14:31 -04:00
workflow_dispatch:
jobs:
build:
strategy:
matrix:
2021-04-05 23:43:55 -04:00
feature: [core, js]
2021-07-26 12:14:31 -04:00
os: [macos-11.0, ubuntu-18.04, windows-2019, self-hosted]
2021-04-05 23:43:55 -04:00
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- name: Get version
id: version
2020-01-01 07:39:45 -05:00
shell: bash
2020-06-18 23:00:25 -04:00
run: echo ::set-output name=VERSION::"$([[ "$GITHUB_REF" == refs/tags/v* ]] && echo ${GITHUB_REF#refs/tags/v} || echo '0.0.0')"
- name: Set up Node.js
uses: actions/setup-node@master
with:
2021-04-05 23:43:55 -04:00
node-version: 15.x
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
default: true
- name: Set up GCC (Windows)
if: runner.os == 'Windows'
run: .\.github\workflows\gcc.ps1
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '^1.14.0'
- name: Run prebuild steps
shell: bash
run: bash ./prebuild.sh
- name: Build native module
working-directory: ./nodejs
shell: bash
run: |
2021-04-05 23:59:14 -04:00
node package.json.gen.js ${{ matrix.feature }}
npm install
npm run build
2020-07-12 02:17:43 -04:00
node compress.js
2020-06-18 19:49:48 -04:00
- name: Upload to B2
shell: bash
2020-06-18 19:49:48 -04:00
run: |
binary_name="$(node -e 'console.log([process.platform, process.arch].join("__"))')"
file=nodejs/index.node.gz
2021-07-26 23:31:47 -04:00
# Use Node.js as sha1sum and/or curl might not exist on macOS or Windows.
sha1="$(node -e "h=crypto.createHash('sha1'); h.update(fs.readFileSync('$file')); console.log(h.digest('hex'));")"
2021-07-26 23:31:47 -04:00
# Use upload proxy as b2 CLI isn't available on ARM64.
url="https://b2-upload.wlin.workers.dev/${{ secrets.CICD_CLI_B2_BUCKET_NAME }}/minify-html/bin/nodejs/${{ steps.version.outputs.VERSION }}/${{ matrix.feature }}/$binary_name.node.gz?sha1=$sha1"
node << EOD
const fs = require("fs");
const https = require("https");
const req = https.request("$url", {
method: "POST",
auth: "${{ secrets.CICD_CLI_B2_KEY_ID }}:${{ secrets.CICD_CLI_B2_APPLICATION_KEY }}",
});
2021-07-26 23:00:22 -04:00
req.on("error", err => {
console.error(err);
process.exitCode = 1;
});
req.on("response", res => {
2021-07-26 23:00:22 -04:00
console.log("Upload responded with", res.statusCode);
if (res.statusCode < 200 || res.statusCode > 299) {
process.exitCode = 1;
}
2021-07-26 22:56:12 -04:00
res.on("data", chunk => process.stdout.write(chunk));
2021-07-26 23:00:22 -04:00
res.on("error", err => {
console.log("\nEncountered error during response:", err);
process.exitCode = 1;
});
});
req.end(fs.readFileSync("$file"));
EOD
package:
2021-04-06 01:01:04 -04:00
strategy:
matrix:
feature: [core, js]
2021-04-06 04:50:24 -04:00
runs-on: ubuntu-18.04
needs: build
steps:
- uses: actions/checkout@v1
- name: Get version
id: version
shell: bash
2020-06-18 23:00:25 -04:00
run: echo ::set-output name=VERSION::"$([[ "$GITHUB_REF" == refs/tags/v* ]] && echo ${GITHUB_REF#refs/tags/v} || echo '0.0.0')"
- name: Set up Node.js
uses: actions/setup-node@master
with:
2021-04-05 23:43:55 -04:00
node-version: 15.x
- name: Pack and publish package
working-directory: ./nodejs
run: |
2020-01-19 23:10:34 -05:00
cat << 'EOF' > .npmrc
package-lock=false
//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}
EOF
2020-01-19 09:13:21 -05:00
cp ../README.md .
2021-04-06 01:01:04 -04:00
node package.json.gen.js ${{ matrix.feature }}
2020-06-18 21:44:54 -04:00
if [[ "${{ steps.version.outputs.VERSION }}" != "0.0.0" ]]; then
2020-07-11 11:34:49 -04:00
npm publish --access public
2020-06-18 21:44:54 -04:00
fi