From b15df2ed488041a6d576a29536ec65b439edd903 Mon Sep 17 00:00:00 2001 From: vyzo Date: Mon, 18 Apr 2022 18:50:37 +0300 Subject: [PATCH] add workflow to publish release bundles (#244) * 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 --- .github/workflows/ci.yml | 20 ----------- .github/workflows/release.yml | 43 ++++++++++++++++++++++ scripts/publish-release.sh | 68 +++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100755 scripts/publish-release.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 82b8defe2..b9e059125 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..b0cba2ac1 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 diff --git a/scripts/publish-release.sh b/scripts/publish-release.sh new file mode 100755 index 000000000..4c938ec7c --- /dev/null +++ b/scripts/publish-release.sh @@ -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"