Skip to content

Commit 5a190cd

Browse files
committed
Add build/release/ci scripts
1 parent 4a1217e commit 5a190cd

File tree

4 files changed

+177
-0
lines changed

4 files changed

+177
-0
lines changed

.travis.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
env: [ CARGO_TERM_COLOR=always ]
2+
cache:
3+
directories: [ $HOME/docker-cache ]
4+
jobs:
5+
include:
6+
# Prepare docker images as a separate step to avoid hitting Travis's time limit
7+
- stage: Prepare
8+
name: Prepare build env
9+
script: >
10+
git submodule update --init --recursive &&
11+
docker build -t bwt-builder - < libbwt/bwt/scripts/builder.Dockerfile &&
12+
docker build -t bwt-builder-osx - < libbwt/bwt/scripts/builder-osx.Dockerfile &&
13+
14+
rm -rf ~/docker-cache && mkdir ~/docker-cache &&
15+
docker save bwt-builder bwt-builder-osx | gzip -2 > ~/docker-cache/images.tar.gz
16+
17+
18+
- stage: Reproducible builds
19+
name: Reproducible builds
20+
script:
21+
- >
22+
git submodule update --init --recursive &&
23+
gzip -d < ~/docker-cache/images.tar.gz | docker load &&
24+
echo -e tr''avis_fo''ld:start:build\\nBuilding... &&
25+
26+
echo Building libbwt... &&
27+
docker run -u `id -u` -v `pwd`/libbwt:/usr/src/libbwt -w /usr/src/libbwt \
28+
--entrypoint scripts/build.sh bwt-builder &&
29+
docker run -u `id -u` -v `pwd`/libbwt:/usr/src/libbwt -w /usr/src/libbwt \
30+
--entrypoint scripts/build.sh bwt-builder-osx &&
31+
32+
echo Packaging libbwt-nodejs... &&
33+
docker run -u `id -u` -v `pwd`:/usr/src/libbwt-nodejs -w /usr/src/libbwt-nodejs \
34+
-e LIBBWT_DIST=/usr/src/libbwt-nodejs/libbwt/dist \
35+
--entrypoint scripts/build.sh node:14 &&
36+
echo tr''avis_fol''d:end:build
37+
- >
38+
echo '-----BEGIN SHA256SUM-----' &&
39+
(cd dist && sha256sum *.tgz | sort) &&
40+
echo

scripts/build.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
set -xeo pipefail
3+
4+
[ -f libbwt/Cargo.toml ] || (echo >&2 "Missing libbwt submodule, run 'git submodule update --init --recursive'" && exit 1)
5+
6+
version=$(grep -E '^version =' libbwt/Cargo.toml | cut -d'"' -f2)
7+
8+
echo Building libbwt-nodejs v$version
9+
10+
if [ -z "$LIBBWT_DIST" ] || [ ! -d "$LIBBWT_DIST" ]; then
11+
echo >&2 LIBBWT_DIST is missing
12+
exit 1
13+
fi
14+
15+
mkdir -p dist && rm -rf dist/*
16+
17+
# Update SHA256SUMS
18+
(cd $LIBBWT_DIST && sha256sum *.tar.gz) | sort > SHA256SUMS
19+
20+
# Update version
21+
npm version --allow-same-version --no-git-tag-version $version
22+
23+
# Prepare package
24+
npm pack
25+
mv libbwt-$version.tgz dist/libbwt-nodejs-$version.tgz

scripts/release-footer.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
------------
3+
4+
### Verifying signatures
5+
6+
The releases are signed by Nadav Ivgi (@shesek). The public key can be verified on the [PGP WoT](http://keys.gnupg.net/pks/lookup?op=vindex&fingerprint=on&search=0x81F6104CD0F150FC), [github](https://api.github.com/users/shesek/gpg_keys), [twitter](https://twitter.com/shesek), [keybase](https://keybase.io/nadav), [hacker news](https://news.ycombinator.com/user?id=nadaviv) and [this video presentation](https://youtu.be/SXJaN2T3M10?t=4) (bottom of slide).
7+
8+
```bash
9+
# Download
10+
$ wget https://github.com/bwt-dev/libbwt-nodejs/releases/download/vVERSION/libbwt-nodejs-VERSION.tgz
11+
12+
# Fetch public key
13+
$ gpg --keyserver keyserver.ubuntu.com --recv-keys FCF19B67866562F08A43AAD681F6104CD0F150FC
14+
15+
# Verify signature
16+
$ wget -qO - https://github.com/bwt-dev/libbwt-nodejs/releases/download/vVERSION/SHA256SUMS.asc \
17+
| gpg --decrypt - | sha256sum -c -
18+
```
19+
20+
The signature verification should show `Good signature from "Nadav Ivgi <[email protected]>" ... Primary key fingerprint: FCF1 9B67 ...` and `libbwt-nodejs-VERSION.tgz: OK`.
21+
22+
### Reproducible builds
23+
24+
The builds are fully reproducible.
25+
26+
You can verify the checksums against the vVERSION builds on Travis CI: https://travis-ci.org/github/bwt-dev/libbwt-nodejs/builds/TRAVIS_JOB
27+
28+
See [more details here](https://github.com/bwt-dev/libbwt-nodejs#reproducible-builds).

scripts/release.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
set -xeo pipefail
3+
shopt -s expand_aliases
4+
5+
gh_repo=bwt-dev/libbwt-nodejs
6+
node_image=node:14
7+
8+
git diff-index --quiet HEAD || (echo >&2 git working directory is dirty && exit 1)
9+
10+
[ -n "$BWT_BASE" ] || (echo >&2 BWT_BASE is required && exit 1)
11+
[ -n "$LIBBWT_COMMIT" ] || (echo >&2 LIBBWT_COMMIT is required && exit 1)
12+
13+
(cd libbwt && git fetch local && git reset --hard $LIBBWT_COMMIT)
14+
15+
version=$(grep -E '^version =' libbwt/Cargo.toml | cut -d'"' -f2)
16+
17+
echo -e "Releasing libbwt-nodejs v$version\n"
18+
19+
# Prepare unreleased changelog
20+
changelog=$(sed -nr '/^## (Unreleased|'$version' )/{n;:a;n;/^## /q;p;ba}' CHANGELOG.md)
21+
changelog="- Update to [bwt v$version](https://github.com/bwt-dev/bwt/releases/tag/v$version)"$'\n'$changelog
22+
grep '## Unreleased' CHANGELOG.md > /dev/null \
23+
&& sed -i "s/^## Unreleased/## $version - $(date +%Y-%m-%d)/" CHANGELOG.md
24+
25+
# Update version number in README
26+
sed -i -r "s~libbwt-nodejs-[0-9a-z.-]+\.~libbwt-nodejs-$version.~g; s~/(download|tag)/v[0-9a-z.-]+~/\1/v$version~;" README.md
27+
28+
# Build
29+
if [ -z "$SKIP_BUILD" ]; then
30+
echo Building...
31+
rm -rf dist/*
32+
33+
docker run -it --rm -u `id -u` -v $(pwd):/usr/src/libbwt-nodejs -w /usr/src/libbwt-nodejs \
34+
-v $BWT_BASE/libbwt/dist:/usr/src/libbwt-dist -e LIBBWT_DIST=/usr/src/libbwt-dist \
35+
$node_image ./scripts/build.sh
36+
37+
rm -rf dist/*/ # remove subdirectories, keep files only
38+
fi
39+
40+
# Sign
41+
gpg --clearsign --digest-algo sha256 SHA256SUMS > SHA256SUMS.asc
42+
43+
# Git tag and push
44+
if [ -z "$SKIP_GIT" ]; then
45+
git add {package,npm-shrinkwrap}.json {CHANGELOG,README}.md SHA256SUMS SHA256SUMS.asc libbwt
46+
git commit -S -m v$version
47+
git tag --sign -m "$changelog" v$version
48+
git branch -f latest HEAD
49+
git push gh master latest
50+
git push gh --tags
51+
fi
52+
53+
if [ -z "$SKIP_NPM" ]; then
54+
echo Publishing to npm...
55+
npm publish file:dist/libbwt-nodejs-$version.tgz
56+
fi
57+
58+
# Upload distribution files to GitHub releases
59+
if [[ -z "$SKIP_UPLOAD" && -n "$GH_TOKEN" ]]; then
60+
echo Uploading to github...
61+
gh_auth="Authorization: token $GH_TOKEN"
62+
gh_base=https://api.github.com/repos/$gh_repo
63+
64+
sleep 3 # allow some time for the job to show up on travis
65+
travis_job=$(curl -s "https://api.travis-ci.org/v3/repo/${gh_repo/\//%2F}/branch/v$version" | jq -r '.last_build.id // ""')
66+
67+
release_text="### Changelog"$'\n'$'\n'$changelog$'\n'$'\n'$(sed "s/VERSION/$version/g; s/TRAVIS_JOB/$travis_job/g;" scripts/release-footer.md)
68+
release_opt=$(jq -n --arg version v$version --arg text "$release_text" \
69+
'{ tag_name: $version, name: $version, body: $text, draft:true }')
70+
gh_release=$(curl -sf -H "$gh_auth" $gh_base/releases/tags/v$version \
71+
|| curl -sf -H "$gh_auth" -d "$release_opt" $gh_base/releases)
72+
gh_upload=$(echo "$gh_release" | jq -r .upload_url | sed -e 's/{?name,label}//')
73+
74+
for file in SHA256SUMS.asc dist/*; do
75+
echo ">> Uploading $file"
76+
77+
curl -f --progress-bar -H "$gh_auth" -H "Content-Type: application/octet-stream" \
78+
--data-binary @"$file" "$gh_upload?name=$(basename "$file")" | (grep -v browser_download_url || true)
79+
done
80+
81+
# mark release as public once everything is ready
82+
curl -sf -H "$gh_auth" -X PATCH "$gh_base/releases/$(echo "$gh_release" | jq -r .id)" \
83+
-d '{"draft":false}' > /dev/null
84+
fi

0 commit comments

Comments
 (0)