Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare release automation #401

Merged
merged 5 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
pipeline {
agent {
node {
label 'ibmi7.3'
}
}
environment {
NODE_PATH = '/QOpenSys/pkgs/lib/nodejs18/bin'
}
stages {
stage('build') {
steps {
sh '''
export PATH=$NODE_PATH:$PATH
npm ci --production
./node_modules/.bin/node-pre-gyp rebuild --production
./node_modules/.bin/node-pre-gyp package
'''
}
}
stage('update-gh-release') {
environment {
GH_TOKEN = credentials('node-odbc-gh-token')
}
steps {
sh '''
export PATH=$NODE_PATH:$PATH
export GITHUB_TOKEN=$GH_TOKEN_PSW
node .github/upload-release-asset.js build/stage/*.tar.gz
'''
}
}
}
}
34 changes: 34 additions & 0 deletions .github/fix-node-pre-gyp-windows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Patch node-pre-gyp to work around unresolved issue on Windows
// See https://github.com/mapbox/node-pre-gyp/issues/715
// Need to set shell: true on the spawn API on Windows now
const fs = require('node:fs/promises');

const path = 'node_modules/@mapbox/node-pre-gyp/lib/util/compile.js';

const before = " const cmd = cp.spawn(shell_cmd, final_args, { cwd: undefined, env: process.env, stdio: [0, 1, 2] });";
const after = " const cmd = cp.spawn(shell_cmd, final_args, { cwd: undefined, env: process.env, stdio: [0, 1, 2], shell: process.platform === 'win32' });";

(async function script() {
const fh = await fs.open(path, 'r+');

let i = 0;
let out = '';
for await (let line of fh.readLines({autoClose: false})) {
i++;;

if (i == 80) {
if (line != before) {
console.error("Patch failed!\n");
process.exit(1);
}
line = after;
}

out += line + "\n";
}

await fh.write(out, 0);

await fh.close();
})();

60 changes: 60 additions & 0 deletions .github/upload-release-asset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const fs = require('fs');
const path = require('node:path');

const tag = process.env.TAG_NAME;
const token = process.env.GITHUB_TOKEN;
const files = process.argv.slice(2);

if (!tag) {
console.error("Must set TAG_NAME environment variable");
process.exit(1);
}
if (!token) {
console.error("Must set GITHUB_TOKEN environment variable");
process.exit(1);
}
if (!files.length) {
console.error("No files passed");
process.exit(1);
}

const options = {
headers: {
"Authorization": `Bearer ${token}`,
"X-GitHub-Api-Version": "2022-11-28",
"Accept": "application/vnd.github+json",
"Content-Type": "application/octet-stream",
}
};

(async function script() {
const response = await fetch(`https://api.github.com/repos/IBM/node-odbc/releases/tags/${tag}`);

if (!response.ok) {
console.error(`ERROR: Getting release failed: ${response.status}`)
process.exit(1);
}

const release_obj = await response.json();

// Returns a goofy URL "template", get rid of the parameters
const upload_url = release_obj.upload_url.substr(0, release_obj.upload_url.indexOf('{'));;

for (const file of files) {
const name = path.basename(file);
console.log(`Uploading ${file} -> ${name}`);

const content = fs.readFileSync(file);

const response = await fetch(`${upload_url}?name=${name}`, {
method: "POST",
body: content,
...options
});

if (!response.ok) {
console.error(`ERROR: Upload of ${file} failed: ${response.status}`)
process.exit(1);
}
}
})();
49 changes: 9 additions & 40 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,24 @@ name: Build
on: pull_request

jobs:
build-windows:

runs-on: windows-latest

strategy:
matrix:
node-version: [18.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Build package
run: npm ci --production --build-from-source

build-ubuntu:

runs-on: ubuntu-latest

build-matrix:
strategy:
matrix:
node-version: [18.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Build package
run: npm ci --production --build-from-source

build-macos:

runs-on: macos-latest

strategy:
matrix:
node-version: [18.x]

node-version:
- 18.x
os:
- windows-latest
- ubuntu-latest
- macos-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
if: ${{ startsWith(matrix.os, 'macos') }}
run: brew install unixodbc
- name: Build package
run: npm ci --production --build-from-source
Loading
Loading