Skip to content

Commit

Permalink
Add Jenkins automation for IBM i release builds
Browse files Browse the repository at this point in the history
  • Loading branch information
kadler committed Aug 21, 2024
1 parent 96f0d2f commit 7e02158
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
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
'''
}
}
}
}
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);
}
}
})();

0 comments on commit 7e02158

Please sign in to comment.