Skip to content

Commit 838cd82

Browse files
committed
Merge remote-tracking branch 'origin/build-on-ci'
2 parents 62c2512 + 4938bca commit 838cd82

9 files changed

+671
-1
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@
66

77
# Backup files generated by rustfmt
88
**/*.rs.bk
9+
10+
# Continuous Integration
11+
/ci/node_modules/
12+
13+
# Files used when building releases
14+
/build

.travis.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
language: rust
2+
rust:
3+
- stable
4+
script:
5+
- cargo build --release --manifest-path gitrs_server/Cargo.toml --verbose --all
6+
cache: cargo
7+
matrix:
8+
include:
9+
- os: linux
10+
env: TARGET=x86_64-unknown-linux-gnu
11+
- os: osx
12+
env: TARGET=x86_64-apple-darwin
13+
before_install:
14+
- nvm install 8
15+
- nvm use 8
16+
- npm i -g npm@6.1.0
17+
- npm ci --prefix ./ci
18+
before_deploy:
19+
- node ./ci/checkTomlSemver.js
20+
- node ./ci/buildRelease.js
21+
after_success:
22+
- node ./ci/checkIsRelease.js && DO_DEPLOY=true || true
23+
deploy:
24+
skip_cleanup: true
25+
provider: releases
26+
api_key:
27+
secure: eALDh9y1T3WdPOekCS9yocrSohP5nxou2cfijDZgkgV7KnuB3fY01lJg0GV8+Jt7tnamgzn0PCD3dw3TYc6GdRO3vzLUcmB6F+IW/g+kucIFVfpj4cgsFTPBefHxPsmmaEa9tB3P9gObL4gz6R1UF9BrtFm4Ix+5YC9Lwe9wJNVZd/GqdbnBYjFqmCvoKJHXdu0bFB2w46ZednFuHpz7Le/5tnKpzLi7vA5FDbrhEIrFWT6NQSijJ6S/6M8e1LkLLS3+soxqwyA4i0fYEJAcqtHBfbdXXJbk8hnEY41A0Rx28hZi+JJmNAElyYBtpQp0vWJ3ZR3okbUWTrQmU6L+N+n4ninLqlAuseqPiY9dCYFZGeeN0+HwLYeSq8sc3YXRHPQKMfB5/Es1lR7tnTf76vA3eyUmADCIskn/loi7PMBxflZ2nUW4sHAuD9gg5/ikQzrk/+QxVN/CCSQix/l9lnUKfi/oHFc6KMeaUHuMgcHBia0LcdNE2nflIV1XZn08PQuycQ0qyPi5v/26tyPhQYF4pqwRlGLwoP7zwNmOCLpBw7oOJs++gFuYsXywb0SlZ26zBg7FEKVI7Q0YT4KobUq3ASDIAt1ZcL/YkSK4K0n/z3YWwWIzR76g+YVfFQ1PNZHbTmXni/eRf3bt4Pxydbq6ARO8mEmUrB5RQlvo/EA=
28+
file: "$TARGET.tar.gz"
29+
on:
30+
repo: stevek-axo/git-rs
31+
tags: true
32+
condition: "$DO_DEPLOY"

appveyor.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
image: Visual Studio 2013
2+
environment:
3+
global:
4+
CHANNEL: stable
5+
matrix:
6+
- TARGET: x86_64-pc-windows-msvc
7+
# Install Rust and Cargo
8+
# (Based on from https://github.com/rust-lang/libc/blob/master/appveyor.yml)
9+
build: false
10+
install:
11+
- ps: Install-Product node 8 x64
12+
- npm i -g npm@6.1.0
13+
- npm ci --prefix .\ci
14+
- appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
15+
- rustup-init.exe --default-host %TARGET% --default-toolchain %CHANNEL% -y
16+
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
17+
- rustc -Vv
18+
- cargo -V
19+
20+
after_test:
21+
- node .\ci\checkIsRelease.js && set "DO_DEPLOY=true" || exit 0
22+
23+
build_script:
24+
- cargo build --release --manifest-path gitrs_server/Cargo.toml --verbose --all
25+
26+
before_deploy:
27+
- node .\ci\checkTomlSemver.js
28+
- node .\ci\buildRelease.js
29+
- appveyor PushArtifact %TARGET%.tar.gz
30+
31+
deploy:
32+
provider: GitHub
33+
auth_token:
34+
secure: QX2lo06wkU6C9NYtk6h8dDiXR63UADvTkcjzBqoh0UFjwZu3ubzHDPe76dWpz34Q
35+
artifact: '%TARGET%.tar.gz'
36+
on:
37+
DO_DEPLOY: true

ci/buildRelease.js

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
const checksum = require('checksum');
2+
const fs = require('fs');
3+
const mkdirp = require('mkdirp');
4+
const path = require('path');
5+
const request = require('request');
6+
const tar = require('tar');
7+
const url = require('url');
8+
9+
const config = {
10+
buildDirectory: '',
11+
expectedChecksum: '',
12+
gitRsBinaryName: '',
13+
gitRsBinaryPath: '',
14+
source: '',
15+
target: process.env.TARGET,
16+
tempFile: '',
17+
vendorDirectoryName: 'vendor',
18+
vendorDirectoryPath: ''
19+
};
20+
21+
switch (process.env.TARGET) {
22+
case 'x86_64-apple-darwin':
23+
config.expectedChecksum = 'f92ff67688ddc9ce48ba50e9e9ed8cf49e958a697ca2571edce898a4b9dae474';
24+
config.source = url.parse(
25+
'https://github.com/desktop/dugite-native/releases/download/v2.17.1-2/dugite-native-v2.17.1-macOS.tar.gz'
26+
);
27+
config.gitRsBinaryName = 'git_server';
28+
break;
29+
case 'x86_64-unknown-linux-gnu':
30+
config.expectedChecksum = 'a3750dade1682d1805623661e006f842c6bbf9cc4e450ed161e49edeb2847a86';
31+
config.source = url.parse(
32+
'https://github.com/desktop/dugite-native/releases/download/v2.17.1-2/dugite-native-v2.17.1-ubuntu.tar.gz'
33+
);
34+
config.gitRsBinaryName = 'git_server';
35+
break;
36+
case 'x86_64-pc-windows-msvc':
37+
config.expectedChecksum = '6a7f166a8211c60d724cc23ef378a059375a67f1c352f5a44846dd0c84285f30';
38+
config.source = url.parse(
39+
'https://github.com/desktop/dugite-native/releases/download/v2.17.1-2/dugite-native-v2.17.1-win32.tar.gz'
40+
);
41+
config.gitRsBinaryName = 'git_server.exe';
42+
break;
43+
}
44+
45+
config.buildDirectory = path.join(process.cwd(), 'build');
46+
config.gitRsBinaryPath = path.join(process.cwd(), 'gitrs_server', 'target', 'release', config.gitRsBinaryName);
47+
config.vendorDirectoryPath = path.join(config.buildDirectory, config.vendorDirectoryName);
48+
config.tempFile = path.join(config.buildDirectory, 'git.tar.gz');
49+
50+
const getFileChecksum = async (filePath) => new Promise((resolve) => {
51+
checksum.file(filePath, { algorithm: 'sha256' } , (_, hash) => resolve(hash));
52+
});
53+
54+
const unpackFile = async (filePath, destinationPath) => tar.extract({
55+
cwd: destinationPath,
56+
file: filePath
57+
});
58+
59+
const packBundle = async (context, sourcePaths, destinationFile) => tar.create(
60+
{
61+
cwd: context,
62+
file: destinationFile,
63+
gzip: true
64+
},
65+
sourcePaths
66+
);
67+
68+
69+
const bundleGit = ({
70+
buildDirectory,
71+
expectedChecksum,
72+
gitRsBinaryName,
73+
gitRsBinaryPath,
74+
source,
75+
target,
76+
tempFile,
77+
vendorDirectoryName,
78+
vendorDirectoryPath
79+
}) => {
80+
mkdirp(buildDirectory, (error) => {
81+
if (error) {
82+
console.log(`Could not create build directory`);
83+
process.exit(1);
84+
}
85+
});
86+
87+
const options = {
88+
url: source
89+
};
90+
const req = request.get(options);
91+
req.pipe(fs.createWriteStream(tempFile));
92+
93+
req.on('error', (error) => {
94+
console.log('Failed to fetch Git binaries');
95+
process.exit(1);
96+
});
97+
98+
req.on('response', (res) => {
99+
if (res.statusCode !== 200) {
100+
console.log(`Non-200 response returned from ${source.toString()} - (${res.statusCode})`);
101+
process.exit(1);
102+
}
103+
});
104+
105+
req.on('end', async () => {
106+
const checksum = await getFileChecksum(tempFile, config);
107+
if (checksum !== expectedChecksum) {
108+
console.log(`Checksum validation failed. Expected ${expectedChecksum} but got ${checksum}`);
109+
process.exit(1);
110+
}
111+
112+
mkdirp(vendorDirectoryPath, (error) => {
113+
if (error) {
114+
console.log(`Could not create ${vendor} directory to extract files to`);
115+
process.exit(1);
116+
}
117+
});
118+
119+
fs.copyFile(gitRsBinaryPath, path.join(buildDirectory, gitRsBinaryName), (error) => {
120+
if (error) {
121+
console.log(`Could not copy git-rs binaries`);
122+
process.exit(1);
123+
}
124+
});
125+
126+
try {
127+
await unpackFile(tempFile, vendorDirectoryPath);
128+
} catch (error) {
129+
console.log('Could not extract git archive');
130+
process.exit(1);
131+
}
132+
133+
try {
134+
await packBundle(buildDirectory, [vendorDirectoryName, gitRsBinaryName], `${process.env.TARGET}.tar.gz`);
135+
} catch (error) {
136+
console.log('Could not build git-rs archive');
137+
console.error(error);
138+
process.exit(1);
139+
}
140+
});
141+
}
142+
143+
bundleGit(config);

ci/checkIsRelease.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const semverRegex = /^\d+\.\d+\.+\d(-RC\d+)?$/;
2+
const tagName = process.env.TRAVIS_TAG || process.env.APPVEYOR_REPO_TAG_NAME;
3+
if (semverRegex.test(tagName)) {
4+
process.exit(0);
5+
} else {
6+
process.exit(1);
7+
}

ci/checkTomlSemver.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var fs = require('fs');
2+
var readline = require('readline');
3+
4+
const versionRegex = /^version = "(.+)"$/;
5+
const tagName = process.env.TRAVIS_TAG || process.env.APPVEYOR_REPO_TAG_NAME;
6+
7+
const lineReader = readline.createInterface({
8+
input: fs.createReadStream('gitrs_server/Cargo.toml'),
9+
output: null,
10+
console: false
11+
});
12+
13+
let foundVersion;
14+
15+
lineReader.on('line', (line) => {
16+
const capture = versionRegex.exec(line);
17+
if (capture !== null) {
18+
foundVersion = capture[1];
19+
}
20+
});
21+
22+
lineReader.on('close', () => {
23+
if (foundVersion && foundVersion === tagName) {
24+
process.exit(0);
25+
} else {
26+
process.exit(1);
27+
}
28+
});

0 commit comments

Comments
 (0)