Skip to content

Commit a2fb178

Browse files
authored
Merge pull request #416 from filecoin-project/spikes/release-publishing
release publishing
2 parents 194e6eb + 955fd87 commit a2fb178

File tree

3 files changed

+136
-1
lines changed

3 files changed

+136
-1
lines changed

.circleci/config.yml

+61
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,61 @@ jobs:
193193
name: Run cargo clippy
194194
command: cargo clippy --all
195195

196+
build_linux_release:
197+
docker:
198+
- image: filecoin/rust:latest
199+
working_directory: /mnt/crate
200+
resource_class: xlarge
201+
steps:
202+
- checkout
203+
- attach_workspace:
204+
at: "."
205+
- restore_cache:
206+
keys:
207+
- cargo-v7-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}
208+
- run:
209+
name: Build (release)
210+
command: cargo +$(cat rust-toolchain) build --release --verbose --frozen --all
211+
- run:
212+
name: Install jq
213+
command: apt-get install jq -yqq
214+
- run:
215+
name: Run publish-release.sh
216+
command: bash ./scripts/publish-release.sh
217+
218+
build_darwin_release:
219+
macos:
220+
xcode: "10.0.0"
221+
working_directory: ~/crate
222+
resource_class: large
223+
steps:
224+
- run:
225+
name: Configure environment variables
226+
command: |
227+
echo 'export PATH="${HOME}/.cargo/bin:${HOME}/.bin:${PATH}"' >> $BASH_ENV
228+
echo 'export CIRCLE_ARTIFACTS="/tmp"' >> $BASH_ENV
229+
- checkout
230+
- run:
231+
name: Install Rust
232+
command: |
233+
curl https://sh.rustup.rs -sSf | sh -s -- -y
234+
- run: rustup install $(cat rust-toolchain)
235+
- run: rustup default $(cat rust-toolchain)
236+
- run: cargo update
237+
- run: cargo fetch
238+
- run:
239+
name: Build (release)
240+
command: cargo +$(cat rust-toolchain) build --release --verbose --frozen --all
241+
- run:
242+
name: Install jq
243+
command: |
244+
mkdir $HOME/.bin
245+
curl --location https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64 --output $HOME/.bin/jq
246+
chmod +x $HOME/.bin/jq
247+
- run:
248+
name: Run publish-release.sh
249+
command: bash ./scripts/publish-release.sh
250+
196251
workflows:
197252
version: 2
198253
test_all:
@@ -222,3 +277,9 @@ workflows:
222277
- bench_nightly:
223278
requires:
224279
- cargo_fetch
280+
- build_linux_release:
281+
requires:
282+
- cargo_fetch
283+
- build_darwin_release:
284+
requires:
285+
- cargo_fetch

filecoin-proofs/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
77
edition = "2018"
88

99
[lib]
10-
crate-type = ["rlib", "cdylib"]
10+
crate-type = ["rlib", "staticlib", "cdylib"]
1111

1212
[dependencies]
1313
sector-base = { path = "../sector-base" }

scripts/publish-release.sh

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bash
2+
3+
RELEASE_BRANCH="master"
4+
RELEASE_NAME="$CIRCLE_PROJECT_REPONAME-$(uname)"
5+
RELEASE_PATH="$CIRCLE_ARTIFACTS/$RELEASE_NAME"
6+
RELEASE_FILE="$RELEASE_PATH.tar.gz"
7+
RELEASE_TAG="${CIRCLE_SHA1:0:16}"
8+
9+
# make sure we're on the sanctioned branch
10+
if [ "$CIRCLE_BRANCH" != "$RELEASE_BRANCH" ]; then
11+
echo "not on branch \"$BRANCH\", skipping publish"
12+
exit 0
13+
fi
14+
15+
# make sure we have a token set, api requests won't work otherwise
16+
if [ -z $GITHUB_TOKEN ]; then
17+
echo "\$GITHUB_TOKEN not set, publish failed"
18+
exit 1
19+
fi
20+
21+
echo "preparing release file"
22+
23+
# pack up compiled lib and header
24+
mkdir $RELEASE_PATH
25+
cp target/release/libfilecoin_proofs.a $RELEASE_PATH
26+
cp filecoin-proofs/libfilecoin_proofs.h $RELEASE_PATH
27+
pushd $RELEASE_PATH
28+
tar -czf $RELEASE_FILE ./libfilecoin_proofs.*
29+
popd
30+
31+
echo "release file created: $RELEASE_FILE"
32+
33+
# see if the release already exists by tag
34+
RELEASE_RESPONSE=`
35+
curl \
36+
--header "Authorization: token $GITHUB_TOKEN" \
37+
"https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/releases/tags/$RELEASE_TAG"
38+
`
39+
40+
RELEASE_ID=`echo $RELEASE_RESPONSE | jq '.id'`
41+
42+
if [ "$RELEASE_ID" = "null" ]; then
43+
echo "creating release"
44+
45+
RELEASE_DATA="{
46+
\"tag_name\": \"$RELEASE_TAG\",
47+
\"target_commitish\": \"$CIRCLE_SHA1\",
48+
\"name\": \"$RELEASE_TAG\",
49+
\"body\": \"\"
50+
}"
51+
52+
# create it if it doesn't exist yet
53+
RELEASE_RESPONSE=`
54+
curl \
55+
--request POST \
56+
--header "Authorization: token $GITHUB_TOKEN" \
57+
--header "Content-Type: application/json" \
58+
--data "$RELEASE_DATA" \
59+
"https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/releases"
60+
`
61+
else
62+
echo "release already exists"
63+
fi
64+
65+
RELEASE_UPLOAD_URL=`echo $RELEASE_RESPONSE | jq -r '.upload_url' | cut -d'{' -f1`
66+
67+
curl \
68+
--request POST \
69+
--header "Authorization: token $GITHUB_TOKEN" \
70+
--header "Content-Type: application/octet-stream" \
71+
--data-binary "@$RELEASE_FILE" \
72+
"$RELEASE_UPLOAD_URL?name=$(basename $RELEASE_FILE)"
73+
74+
echo "release file uploaded"

0 commit comments

Comments
 (0)