Skip to content

Commit

Permalink
add workflow to publish release bundles (#244)
Browse files Browse the repository at this point in the history
* add workflow to publish release bundles on certain branches

master, release/*, and experimental/* are the blessed ones

* keep the build step in the default workflow

* apply suggestions from code review

Co-authored-by: raulk <raul@protocol.ai>
  • Loading branch information
vyzo and raulk authored Apr 18, 2022
1 parent 41640c7 commit b15df2e
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 20 deletions.
20 changes: 0 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,3 @@ jobs:
BUILD_FIL_NETWORK: ${{ matrix.network }}
run: |
cargo run -- -o output/builtin-actors.car
- name: Uploading bundle to Estuary
env:
ESTUARY_TOKEN: ${{ secrets.ESTUARY_TOKEN }}
run: |
BUNDLE_PATH="output/builtin-actors.car"
UPLOAD_AS="builtin-actors-${{ matrix.network }}.car"
curl -k -X POST -F "data=@${BUNDLE_PATH};type=application/octet-stream;filename=\"${UPLOAD_AS}\"" \
-H "Authorization: Bearer $ESTUARY_TOKEN" \
-H "Content-Type: multipart/form-data" \
https://shuttle-4.estuary.tech/content/add > output/upload.json
cat output/upload.json
shasum -a 256 "$BUNDLE_PATH" > "$BUNDLE_PATH".sha256sum
- name: Publishing build artifacts to GitHub
uses: actions/upload-artifact@v2
with:
name: bundle-${{ matrix.network }}
path: |
output/builtin-actors.car
output/builtin-actors.car.sha256sum
output/upload.json
43 changes: 43 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Release

on:
push:
branches:
- 'master'
- 'release/**'
- 'experimental/**'

env:
RUSTFLAGS: -Dwarnings

jobs:
release:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_INCREMENTAL: 0
CACHE_SKIP_SAVE: ${{ matrix.push == '' || matrix.push == 'false' }}
strategy:
matrix:
network: [ 'mainnet', 'caterpillarnet', 'butterflynet', 'calibrationnet', 'devnet' ]
steps:
- name: Checking out
uses: actions/checkout@v2
- name: Install Rust toolchain
uses: ./.github/actions/rust-cargo-run
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
command: version
- name: Writing bundle
env:
BUILD_FIL_NETWORK: ${{ matrix.network }}
run: |
cargo run -- -o output/builtin-actors.car
- name: Publishing release and uploading bundle to GitHub
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_SHA: ${{ github.sha }}
BUILD_FIL_NETWORK: ${{ matrix.network }}
run: |
./scripts/publish-release.sh
68 changes: 68 additions & 0 deletions scripts/publish-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env bash

set -e

die() {
echo "$1"
exit 1
}

# make sure we have a token set, api requests won't work otherwise
if [ -z "$GITHUB_TOKEN" ]; then
die "no GITHUB_TOKEN"
fi

# make sure we have a release tag set
if [ -z "$GITHUB_SHA" ]; then
die "no GITHUB_SHA"
fi

# make sure we have a target set
if [ -z "$BUILD_FIL_NETWORK" ]; then
die "no BUILD_FIL_NETWORK"
fi


release_file=output/builtin-actors.car
release_target=builtin-actors-${BUILD_FIL_NETWORK}.car
release_tag="${GITHUB_SHA:0:16}"

ORG="filecoin-project"
REPO="builtin-actors"

# see if the release already exists by tag
__release_response=`
curl \
--header "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$ORG/$REPO/releases/tags/$release_tag"
`
__release_id=`echo $__release_response | jq '.id'`
if [ "$__release_id" = "null" ]; then
echo "creating release $release_tag"
release_data="{
\"tag_name\": \"$release_tag\",
\"target_commitish\": \"$GITHUB_SHA\",
\"name\": \"$release_tag\",
\"body\": \"\"
}"

__release_response=`
curl \
--request POST \
--header "Authorization: token $GITHUB_TOKEN" \
--header "Content-Type: application/json" \
--data "$release_data" \
"https://api.github.com/repos/$ORG/$REPO/releases"
`
else
echo "release $release_tag already exists"
fi

echo "uploading $release_target"
__release_upload_url=`echo $__release_response | jq -r '.upload_url' | cut -d'{' -f1`
curl \
--request POST \
--header "Authorization: token $GITHUB_TOKEN" \
--header "Content-Type: application/octet-stream" \
--data-binary "@$release_file" \
"$__release_upload_url?name=$release_target"

0 comments on commit b15df2e

Please sign in to comment.