Improve B2 upload workflow
This commit is contained in:
parent
a5263993a1
commit
2187ebc95e
|
@ -31,36 +31,47 @@ jobs:
|
|||
EXT: ''
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- name: Get version
|
||||
id: version
|
||||
shell: bash
|
||||
run: echo ::set-output name=VERSION::"$([[ "$GITHUB_REF" == refs/tags/v* ]] && echo ${GITHUB_REF#refs/tags/v} || echo '0.0.0')"
|
||||
|
||||
- name: Get file name
|
||||
id: file
|
||||
shell: bash
|
||||
run: echo ::set-output name=FILE::${{ steps.version.outputs.VERSION }}-${{ matrix.ARCH }}${{ matrix.EXT }}
|
||||
|
||||
- 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 CLI
|
||||
working-directory: ./cli
|
||||
run: cargo build --release -vvv
|
||||
- name: Set up Backblaze B2 CLI
|
||||
uses: wilsonzlin/setup-b2@v3
|
||||
|
||||
- name: Upload to B2
|
||||
run: |
|
||||
b2 authorize-account ${{ secrets.CICD_CLI_B2_KEY_ID }} ${{ secrets.CICD_CLI_B2_APPLICATION_KEY }}
|
||||
b2 upload-file --contentType ${{ matrix.MIME }} ${{ secrets.CICD_CLI_B2_BUCKET_NAME }} ./cli/target/release/minify-html-cli${{ matrix.EXT }} minify-html/bin/${{ steps.file.outputs.FILE }}
|
||||
uses: wilsonzlin/b2-upload-action@v1.0.0
|
||||
with:
|
||||
bucket: ${{ secrets.CICD_CLI_B2_BUCKET_NAME }}
|
||||
uploadKey: minify-html/bin/${{ steps.file.outputs.FILE }}
|
||||
keyId: ${{ secrets.CICD_CLI_B2_KEY_ID }}
|
||||
applicationKey: ${{ secrets.CICD_CLI_B2_APPLICATION_KEY }}
|
||||
file: ./cli/target/release/minify-html-cli${{ matrix.EXT }}
|
||||
contentType: ${{ matrix.MIME }}
|
||||
|
|
|
@ -48,46 +48,24 @@ jobs:
|
|||
|
||||
- name: Build native module
|
||||
working-directory: ./nodejs
|
||||
id: module
|
||||
shell: bash
|
||||
run: |
|
||||
node package.json.gen.js ${{ matrix.feature }}
|
||||
npm install
|
||||
npm run build
|
||||
node compress.js
|
||||
echo ::set-output name=BINARY_NAME::"$(node -e 'console.log([process.platform, process.arch].join("__"))')"
|
||||
|
||||
- name: Upload to B2
|
||||
shell: bash
|
||||
run: |
|
||||
binary_name="$(node -e 'console.log([process.platform, process.arch].join("__"))')"
|
||||
file=nodejs/index.node.gz
|
||||
# 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'));")"
|
||||
# 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 }}",
|
||||
});
|
||||
req.on("error", err => {
|
||||
console.error(err);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
req.on("response", res => {
|
||||
console.log("Upload responded with", res.statusCode);
|
||||
if (res.statusCode < 200 || res.statusCode > 299) {
|
||||
process.exitCode = 1;
|
||||
}
|
||||
res.on("data", chunk => process.stdout.write(chunk));
|
||||
res.on("error", err => {
|
||||
console.log("\nEncountered error during response:", err);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
});
|
||||
req.end(fs.readFileSync("$file"));
|
||||
EOD
|
||||
uses: wilsonzlin/b2-upload-action@v1.0.0
|
||||
with:
|
||||
bucket: ${{ secrets.CICD_CLI_B2_BUCKET_NAME }}
|
||||
uploadKey: minify-html/bin/nodejs/${{ steps.version.outputs.VERSION }}/${{ matrix.feature }}/${{ steps.module.outputs.BINARY_NAME }}.node.gz
|
||||
keyId: ${{ secrets.CICD_CLI_B2_KEY_ID }}
|
||||
applicationKey: ${{ secrets.CICD_CLI_B2_APPLICATION_KEY }}
|
||||
file: ./nodejs/index.node.gz
|
||||
|
||||
package:
|
||||
strategy:
|
||||
matrix:
|
||||
|
|
|
@ -117,7 +117,7 @@ const renderChart = (cfg) => new Promise((resolve, reject) => {
|
|||
req.on('response', res => {
|
||||
const err = res.headers['x-quickchart-error'];
|
||||
if (res.statusCode < 200 || res.statusCode > 299 || err) {
|
||||
reject(new Error(err || `Status ${res.statusCode}`));
|
||||
return reject(new Error(err || `Status ${res.statusCode}`));
|
||||
}
|
||||
const chunks = [];
|
||||
res.on('error', reject);
|
||||
|
|
Loading…
Reference in New Issue