Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: automate creation of GitHub releases and tags #1571

Merged
merged 9 commits into from
Aug 19, 2024
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
name: Release
name: Release Checker

on:
release:
types: [published]
pull_request_target:
paths: ["Cargo.toml"]
types: [ opened, synchronize, reopened, labeled, unlabeled ]
workflow_dispatch:

env:
RUSTFLAGS: -Dwarnings
permissions:
contents: write
pull-requests: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
release:
release-check:
uses: ipdxco/unified-github-workflows/.github/workflows/release-check.yml@v1.0
with:
sources: '["Cargo.toml"]'
upload-release-assets:
needs: [release-check]
if: fromJSON(needs.release-check.outputs.json)['Cargo.toml']
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_INCREMENTAL: 0
CACHE_SKIP_SAVE: ${{ matrix.push == '' || matrix.push == 'false' }}
RUSTFLAGS: -Dwarnings
strategy:
matrix:
network: [ 'mainnet', 'caterpillarnet', 'butterflynet', 'calibrationnet', 'devnet', 'testing', 'testing-fake-proofs' ]
steps:
- name: Checking out
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setting up cache
uses: pl-strflt/rust-sccache-action@v1
env:
Expand All @@ -31,10 +45,10 @@ jobs:
BUILD_FIL_NETWORK: ${{ matrix.network }}
run: |
cargo run --locked -- -o output/builtin-actors.car
- name: Publishing release and uploading bundle to GitHub
- name: Upload release assets to GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REF: ${{ github.ref }}
GITHUB_RELEASE_URL: ${{ fromJSON(needs.release-check.outputs.json)['Cargo.toml'].url }}
BUILD_FIL_NETWORK: ${{ matrix.network }}
run: |
./scripts/publish-release.sh
./scripts/upload-release-assets.sh
21 changes: 21 additions & 0 deletions .github/workflows/releaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Releaser

on:
push:
paths: ["Cargo.toml"]
workflow_dispatch:

permissions:
contents: write

concurrency:
group: ${{ github.workflow }}-${{ github.sha }}
cancel-in-progress: true

jobs:
releaser:
uses: ipdxco/unified-github-workflows/.github/workflows/releaser.yml@v1.0
with:
sources: '["Cargo.toml"]'
secrets:
UCI_GITHUB_TOKEN: ${{ secrets.UCI_GITHUB_TOKEN }}
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ Precompiled actor bundles are provided as [release binaries][releases] in this r
We release all actors, the runtime, and the state abstraction at the same time by:

1. Changing the `workspace.package.version` in the top-level `Cargo.toml` file.
galargh marked this conversation as resolved.
Show resolved Hide resolved
2. Creating a [release][releases] in GitHub.

This will trigger an automatic bundle-build by GitHub CI, and the generated bundles will be attached to the GitHub release.
This will trigger an automatic GitHub release and associated tags creation and then it will also trigger bundle-build by GitHub CI, and the generated bundles will be attached to the GitHub release.
galargh marked this conversation as resolved.
Show resolved Hide resolved

## Instructions for client implementations

Expand Down
34 changes: 27 additions & 7 deletions scripts/publish-release.sh → scripts/upload-release-assets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ if [ -z "$GITHUB_TOKEN" ]; then
die "no GITHUB_TOKEN"
fi

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

# make sure we have a target set
Expand All @@ -28,8 +28,6 @@ release_target=builtin-actors-${BUILD_FIL_NETWORK}.car
release_target_hash=builtin-actors-${BUILD_FIL_NETWORK}.sha256
release_file=output/$release_target
release_file_hash=output/$release_target_hash
# the ref is of the form refs/tags/<tag>; drop the prefix to get the actual release tag
release_tag="${GITHUB_REF:10}"

# prepare artifacts
pushd output
Expand All @@ -45,16 +43,27 @@ REPO="builtin-actors"
__release_response=`
curl \
--header "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$ORG/$REPO/releases/tags/$release_tag"
"$GITHUB_RELEASE_URL"
`
__release_id=`echo $__release_response | jq '.id'`
if [ "$__release_id" = "null" ]; then
echo "release $release_tag does not exist"
echo "release does not exist"
exit 1
fi

__release_upload_url=`echo $__release_response | jq -r '.upload_url' | cut -d'{' -f1`

__release_target_asset=`echo $__release_response | jq -r ".assets | .[] | select(.name == \"$release_target\")"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a blocker, more of a preference thing so take it or leave it: I prefer subshell $() use rather than backticks for this kind of thing, better ergonomics and IMO better readability

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, but it was a convention already used in the script and I didn't want to update all the occurrences at this time given all the other changes we're introducing.


if [ -n "$__release_target_asset" ]; then
echo "deleting $release_target"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the delete fails? Will the following upload fail as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A delete failure should fail the script.

__release_target_asset_url=`echo $__release_target_asset | jq -r '.url'`
curl \
--request DELETE \
--header "Authorization: token $GITHUB_TOKEN" \
"$__release_target_asset_url"
fi

echo "uploading $release_target"
curl \
--request POST \
Expand All @@ -63,6 +72,17 @@ curl \
--data-binary "@$release_file" \
"$__release_upload_url?name=$release_target"

__release_target_hash_asset=`echo $__release_response | jq -r ".assets | .[] | select(.name == \"$release_target_hash\")"`

if [ -n "$__release_target_hash_asset" ]; then
echo "deleting $release_target_hash"
__release_target_hash_asset_url=`echo $__release_target_hash_asset | jq -r '.url'`
curl \
--request DELETE \
--header "Authorization: token $GITHUB_TOKEN" \
"$__release_target_hash_asset_url"
fi

echo "uploading $release_target_hash"
curl \
--request POST \
Expand Down
Loading