Skip to content

Commit 6906288

Browse files
galarghBigLep
andauthored
ci: automate creation of GitHub releases and tags (#1571)
* ci: automate creation of GitHub releases and tags * docs: update documentation on release creation * ci: upload release assets to the draft * chore: apply suggestions from code review Co-authored-by: Steve Loeppky <[email protected]> * chore: apply suggestions from code review Co-authored-by: Steve Loeppky <[email protected]> * docs: document the new release process and possible improvements * chore: apply suggestions from code review Co-authored-by: Steve Loeppky <[email protected]> * Apply suggestions from code review --------- Co-authored-by: Steve Loeppky <[email protected]>
1 parent 82d02e5 commit 6906288

File tree

5 files changed

+102
-25
lines changed

5 files changed

+102
-25
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
1-
name: Release
1+
name: Release Checker
22

33
on:
4-
release:
5-
types: [published]
4+
pull_request_target:
5+
paths: ["Cargo.toml"]
6+
types: [ opened, synchronize, reopened, labeled, unlabeled ]
7+
workflow_dispatch:
68

7-
env:
8-
RUSTFLAGS: -Dwarnings
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
916

1017
jobs:
11-
release:
18+
release-check:
19+
uses: ipdxco/unified-github-workflows/.github/workflows/[email protected]
20+
with:
21+
sources: '["Cargo.toml"]'
22+
upload-release-assets:
23+
needs: [release-check]
24+
if: fromJSON(needs.release-check.outputs.json)['Cargo.toml']
1225
runs-on: ubuntu-latest
1326
env:
1427
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1528
CARGO_INCREMENTAL: 0
1629
CACHE_SKIP_SAVE: ${{ matrix.push == '' || matrix.push == 'false' }}
30+
RUSTFLAGS: -Dwarnings
1731
strategy:
1832
matrix:
1933
network: [ 'mainnet', 'caterpillarnet', 'butterflynet', 'calibrationnet', 'devnet', 'testing', 'testing-fake-proofs' ]
2034
steps:
2135
- name: Checking out
22-
uses: actions/checkout@v3
36+
uses: actions/checkout@v4
2337
- name: Setting up cache
2438
uses: pl-strflt/rust-sccache-action@v1
2539
env:
@@ -31,10 +45,10 @@ jobs:
3145
BUILD_FIL_NETWORK: ${{ matrix.network }}
3246
run: |
3347
cargo run --locked -- -o output/builtin-actors.car
34-
- name: Publishing release and uploading bundle to GitHub
48+
- name: Upload release assets to GitHub Release
3549
env:
3650
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37-
GITHUB_REF: ${{ github.ref }}
51+
GITHUB_RELEASE_URL: ${{ fromJSON(needs.release-check.outputs.json)['Cargo.toml'].url }}
3852
BUILD_FIL_NETWORK: ${{ matrix.network }}
3953
run: |
40-
./scripts/publish-release.sh
54+
./scripts/upload-release-assets.sh

.github/workflows/releaser.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Releaser
2+
3+
on:
4+
push:
5+
paths: ["Cargo.toml"]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.sha }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
releaser:
17+
uses: ipdxco/unified-github-workflows/.github/workflows/[email protected]
18+
with:
19+
sources: '["Cargo.toml"]'
20+
secrets:
21+
UCI_GITHUB_TOKEN: ${{ secrets.UCI_GITHUB_TOKEN }}

README.md

+1-8
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,7 @@ Precompiled actor bundles are provided as [release binaries][releases] in this r
8282
[`fil_builtin_actors_bundle`](https://crates.io/crates/fil_builtin_actors_bundle) crate on
8383
[crates.io](https://crates.io) will not be updated.
8484

85-
## Releasing
86-
87-
We release all actors, the runtime, and the state abstraction at the same time by:
88-
89-
1. Changing the `workspace.package.version` in the top-level `Cargo.toml` file.
90-
2. Creating a [release][releases] in GitHub.
91-
92-
This will trigger an automatic bundle-build by GitHub CI, and the generated bundles will be attached to the GitHub release.
85+
## [Releasing](RELEASE.md)
9386

9487
## Instructions for client implementations
9588

RELEASE.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Release Process
2+
3+
This document describes the process for releasing a new version of the `builtin-actors` project.
4+
5+
## Current State
6+
7+
1. Create a pull request which updates the `workspace.package.version` in the [top-level `Cargo.toml` file](https://github.com/filecoin-project/builtin-actors/blob/master/Cargo.toml).
8+
- Title the PR `chore: release X.Y.Z`
9+
2. On pull request creation, a [Release Checker](.github/workflows/release-check.yml) workflow will run. It will perform the following actions:
10+
1. Extract the version from the top-level `Cargo.toml` file.
11+
2. Check if a git tag for the version already exists. Continue only if it does not.
12+
3. Create a draft GitHub release with the version as the tag. (A git tag with this version string will be created when the release is published.)
13+
4. Comment on the pull request with a link to the draft release.
14+
5. Build `builtin-actors.car`s for various networks.
15+
6. Generate checksums for the built `builtin-actors.car`s.
16+
7. Upload the built `builtin-actors.car`s and checksums as assets to the draft release (replace any existing assets with the same name).
17+
3. On pull request merge, a [Releaser](.github/workflows/release.yml) workflow will run. It will perform the following actions:
18+
1. Extract the version from the top-level `Cargo.toml` file.
19+
2. Check if a git tag for the version already exists. Continue only if it does not.
20+
3. Check if a draft GitHub release with the version as the tag exists.
21+
4. If the draft release exists, publish it. Otherwise, create and publish a new release with the version as the git tag. Publishing the release creates the git tag.
22+
23+
## Known Limitations
24+
25+
1. If one pushes an update to the `workspace.package.version` in the top-level `Cargo.toml` file without creating a pull request, the Release Checker workflow will not run. Hence, the release assets will not be automatically built and uploaded.
26+
27+
## Possible Improvements
28+
29+
1. Add a check to the [Releaser](.github/workflows/release.yml) workflow to ensure that the created/published release contains the expected assets. If it does not, create them and run the [upload-release-assets.sh](scripts/upload-release-assets.sh) script to upload the missing assets.

scripts/publish-release.sh scripts/upload-release-assets.sh

+27-7
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ if [ -z "$GITHUB_TOKEN" ]; then
1212
die "no GITHUB_TOKEN"
1313
fi
1414

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

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

3432
# prepare artifacts
3533
pushd output
@@ -45,16 +43,27 @@ REPO="builtin-actors"
4543
__release_response=`
4644
curl \
4745
--header "Authorization: token $GITHUB_TOKEN" \
48-
"https://api.github.com/repos/$ORG/$REPO/releases/tags/$release_tag"
46+
"$GITHUB_RELEASE_URL"
4947
`
5048
__release_id=`echo $__release_response | jq '.id'`
5149
if [ "$__release_id" = "null" ]; then
52-
echo "release $release_tag does not exist"
50+
echo "release does not exist"
5351
exit 1
5452
fi
5553

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

56+
__release_target_asset=`echo $__release_response | jq -r ".assets | .[] | select(.name == \"$release_target\")"`
57+
58+
if [ -n "$__release_target_asset" ]; then
59+
echo "deleting $release_target"
60+
__release_target_asset_url=`echo $__release_target_asset | jq -r '.url'`
61+
curl \
62+
--request DELETE \
63+
--header "Authorization: token $GITHUB_TOKEN" \
64+
"$__release_target_asset_url"
65+
fi
66+
5867
echo "uploading $release_target"
5968
curl \
6069
--request POST \
@@ -63,6 +72,17 @@ curl \
6372
--data-binary "@$release_file" \
6473
"$__release_upload_url?name=$release_target"
6574

75+
__release_target_hash_asset=`echo $__release_response | jq -r ".assets | .[] | select(.name == \"$release_target_hash\")"`
76+
77+
if [ -n "$__release_target_hash_asset" ]; then
78+
echo "deleting $release_target_hash"
79+
__release_target_hash_asset_url=`echo $__release_target_hash_asset | jq -r '.url'`
80+
curl \
81+
--request DELETE \
82+
--header "Authorization: token $GITHUB_TOKEN" \
83+
"$__release_target_hash_asset_url"
84+
fi
85+
6686
echo "uploading $release_target_hash"
6787
curl \
6888
--request POST \

0 commit comments

Comments
 (0)