Skip to content

Commit c67b436

Browse files
committed
Use GitHub Actions for CI
1 parent fc9b483 commit c67b436

4 files changed

Lines changed: 197 additions & 6 deletions

File tree

.github/workflows/tests.yml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
on:
2+
push:
3+
branches:
4+
- master
5+
- backport/*
6+
tags:
7+
- v*.*.*
8+
pull_request:
9+
10+
name: Testing
11+
12+
jobs:
13+
nix-tests:
14+
name: "*nix Tests"
15+
strategy:
16+
matrix:
17+
node: [8, 10, 12]
18+
os: [ubuntu-16.04, macOS-10.14]
19+
runs-on: ${{ matrix.os }}
20+
steps:
21+
- name: Setup Environment
22+
run: |
23+
mkdir ~/.ssh
24+
chmod 700 ~/.ssh
25+
echo -e "Host *\n\tStrictHostKeyChecking no\n" > ~/.ssh/config
26+
echo -e "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDBkHMoNRRkHYNE7EnQLdFxMgVcqGgNPYDhrWiLMlYuzpmEcUnhwW3zNaIa4J2JlGkRNgYZVia1Ic1V3koJPE3YO2+exAfJBIPeb6O1qDADc2hFFHzd28wmHKUkO61yzo2ZjDQfaEVtjN39Yiy19AbddN3bzNrgvuQT574fa6Rghl2RfecKYO77iHA1RGXIFc8heXVIUuUV/jHjb56WqoHH8vyt1DqUz89oyiHq8Cku0qzKN80COheZPseA1EvT0zlIgbXBxwijN4xRmvInK0fB5Kc9r3kddH2tT7V09bOFJsvGQaQmQ1WFTCqjpBFw1CHKcbfPLOxbLpVIR9gyx03R" > ~/.ssh/id_rsa.pub
27+
echo -e "-----BEGIN RSA PRIVATE KEY-----\nMIIEogIBAAKCAQEAwZBzKDUUZB2DROxJ0C3RcTIFXKhoDT2A4a1oizJWLs6ZhHFJ\n4cFt8zWiGuCdiZRpETYGGVYmtSHNVd5KCTxN2DtvnsQHyQSD3m+jtagwA3NoRRR8\n3dvMJhylJDutcs6NmYw0H2hFbYzd/WIstfQG3XTd28za4L7kE+e+H2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n18u+uo9RJPhPDBd7Gj7r8QKBgFraxWy7t24xkZMDgK4fiM/3tQhFvhz/CY2wPbxG\n5Ae8UfkmLcOCUfTIReqfd9fAnsAFZNIKa5izHRu/wsh9NwYIJSlvm8PsEVtTrPRy\nfgvWet+i24/2eYZGsag8b19gaLCNKQzXDT1czYg8RNVsRSX427BoLzXeXNkW9uNu\nFbI9AoGAV2kxcdcKS4BtNHKPeGgV87dM0DWhQaAtEXEIcQquFtba0lAXioGHg8U4\nzeiugl4Qzchwk5qd3wnZ4SOhx0s16/5gQDlnkbjFR6EREUnvLRwV92zBXUTOGIkh\nZ7Z4rcgUKlVAaHT3OHN/lTyqJG/ib+K4wZhbztl/ox+JUFsvD98=\n-----END RSA PRIVATE KEY-----" > ~/.ssh/id_rsa
28+
chmod 600 ~/.ssh/id_rsa*
29+
git config --global user.name "John Doe"
30+
git config --global user.email johndoe@example.com
31+
32+
- uses: actions/checkout@master
33+
34+
- name: Use Node.js 8.x
35+
uses: actions/setup-node@master
36+
with:
37+
node-version: ${{ matrix.node }}
38+
39+
- name: Install Dependencies for Ubuntu
40+
if: startsWith(matrix.os, 'ubuntu')
41+
run: sudo apt install build-essential libssl-dev libkrb5-dev libc++-dev
42+
43+
- name: Install
44+
env:
45+
CC: clang
46+
CXX: clang++
47+
npm_config_clang: 1
48+
GYP_DEFINES: use_obsolete_asm=true
49+
run: npm install
50+
51+
- name: Test
52+
run: |
53+
set -e
54+
eval `ssh-agent -s`
55+
ssh-add ~/.ssh/id_rsa
56+
node utils/retry npm test
57+
58+
- name: Deploy
59+
if: startsWith(github.ref, 'refs/tags/test-v')
60+
env:
61+
node_pre_gyp_bucket: ${{ secrets.node_pre_gyp_bucket }}
62+
node_pre_gyp_accessKeyId: ${{ secrets.node_pre_gyp_accessKeyId }}
63+
node_pre_gyp_secretAccessKey: ${{ secrets.node_pre_gyp_secretAccessKey }}
64+
run: |
65+
npm install -g node-pre-gyp aws-sdk
66+
node lifecycleScripts/clean
67+
node-pre-gyp package
68+
node-pre-gyp publish
69+
70+
windows-tests:
71+
name: Windows Tests
72+
strategy:
73+
matrix:
74+
node: [8, 10, 12]
75+
arch: [x86, x64]
76+
runs-on: windows-2016
77+
steps:
78+
- name: Setup Environment
79+
run: |
80+
git config --file C:\ProgramData\Git\config core.autocrlf input
81+
git config --system core.autocrlf input
82+
git config --global core.autocrlf input
83+
git config --global user.name "John Doe"
84+
git config --global user.email johndoe@example.com
85+
npm install -g node-pre-gyp aws-sdk
86+
87+
- uses: actions/checkout@master
88+
89+
- name: Use Node.js 8.x
90+
uses: implausible/setup-node@feature/expose-architecture-override
91+
with:
92+
node-version: ${{ matrix.node }}
93+
node-arch: ${{ matrix.arch }}
94+
95+
- name: Install
96+
run: npm install
97+
98+
- name: Test
99+
env:
100+
GIT_SSH: ${{ github.workspace }}\vendor\plink.exe
101+
run: |
102+
powershell -command "Start-Process ${{ github.workspace }}\vendor\pageant.exe ${{ github.workspace }}\vendor\private.ppk"
103+
node utils/retry npm test
104+
105+
# You're probably wondering why this isn't a single `run: |` step, it certainly is for *nix,
106+
# but it's not, because the CI runner for windows doesn't wait for each step as listed here
107+
# and it treats each additional step past the first as an orphaned process.
108+
- name: Deploy (Dependencies)
109+
if: startsWith(github.ref, 'refs/tags/test-v')
110+
run: npm install -g node-pre-gyp aws-sdk
111+
112+
- name: Deploy (Clean)
113+
if: startsWith(github.ref, 'refs/tags/test-v')
114+
run: node lifecycleScripts\clean
115+
116+
- name: Deploy (Package)
117+
if: startsWith(github.ref, 'refs/tags/test-v')
118+
run: node-pre-gyp package
119+
120+
- name: Deploy (Publish)
121+
if: startsWith(github.ref, 'refs/tags/test-v')
122+
env:
123+
node_pre_gyp_bucket: ${{ secrets.node_pre_gyp_bucket }}
124+
node_pre_gyp_accessKeyId: ${{ secrets.node_pre_gyp_accessKeyId }}
125+
node_pre_gyp_secretAccessKey: ${{ secrets.node_pre_gyp_secretAccessKey }}
126+
run: node-pre-gyp publish

generate/index.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@ var submoduleStatus = require("../lifecycleScripts/submodules/getStatus");
66
module.exports = function generate() {
77
console.log("[nodegit] Generating native code");
88

9+
function tryGenerate(numRetries = 3) {
10+
// There appears to be a race condition in the generate code somewhere
11+
// Until we fix that, we should try to generate a few times before
12+
try {
13+
generateJson();
14+
generateNativeCode();
15+
generateMissingTests();
16+
} catch (error) {
17+
if (numRetries > 0) {
18+
console.log("[nodegit] WARNING - Failed to generate native code, trying again");
19+
tryGenerate(numRetries - 1);
20+
} else {
21+
throw error;
22+
}
23+
}
24+
}
25+
926
return submoduleStatus()
1027
.then(function(statuses) {
1128
var dirtySubmodules = statuses
@@ -22,14 +39,11 @@ module.exports = function generate() {
2239
});
2340
}
2441
})
25-
.then(function() {
26-
generateJson();
27-
generateNativeCode();
28-
generateMissingTests();
29-
})
42+
.then(tryGenerate)
3043
.catch(function(e) {
3144
console.error("[nodegit] ERROR - Could not generate native code");
3245
console.error(e);
46+
throw e;
3347
});
3448
}
3549

test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var args = cov.concat([
1818
"15000"
1919
]);
2020

21-
if (!process.env.APPVEYOR && !process.env.TRAVIS) {
21+
if (!process.env.APPVEYOR && !process.env.TRAVIS && !process.env.GITHUB_ACTION) {
2222
var local = path.join.bind(path, __dirname);
2323
var dummyPath = local("home");
2424
process.env.HOME = dummyPath;

utils/retry.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const { spawn } = require('child_process');
2+
3+
const [, , cmd, ...args] = process.argv;
4+
if (!cmd) {
5+
process.exit(-1);
6+
}
7+
8+
const once = (fn) => {
9+
let runOnce = false;
10+
return (...args) => {
11+
if (runOnce) {
12+
return;
13+
}
14+
15+
runOnce = true;
16+
fn(...args);
17+
}
18+
};
19+
20+
const retry = (numRetries = 3) => {
21+
const child = spawn(cmd, args, {
22+
shell: process.platform === 'win32',
23+
stdio: [0, 'pipe', 'pipe']
24+
});
25+
26+
child.setMaxListeners(0);
27+
28+
child.stdout.setEncoding('utf8');
29+
child.stderr.setEncoding('utf8');
30+
31+
child.stdout.pipe(process.stdout);
32+
child.stderr.pipe(process.stderr);
33+
34+
const cleanupAndExit = once((error, status) => {
35+
child.kill();
36+
if (numRetries > 0 && (error || status !== 0)) {
37+
retry(numRetries - 1);
38+
} else if (error) {
39+
console.log(error);
40+
process.exit(-1);
41+
} else {
42+
process.exit(status);
43+
}
44+
});
45+
const onClose = status => cleanupAndExit(null, status);
46+
47+
child.on('close', onClose);
48+
child.on('error', cleanupAndExit);
49+
};
50+
51+
retry();

0 commit comments

Comments
 (0)