Skip to content

Commit f217238

Browse files
committed
ci: ensure release assets exist in releaser workflow
1 parent d29dd7b commit f217238

7 files changed

Lines changed: 108 additions & 23 deletions

File tree

.github/actions/upload-release-assets/action.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ inputs:
88
ref:
99
description: The release ref
1010
required: true
11+
force:
12+
description: Force upload
13+
required: false
14+
default: 'false'
1115

1216
runs:
1317
using: 'composite'
1418
steps:
1519
- run: echo "Running on $RUNNER_OS $RUNNER_ARCH"
1620
shell: bash
17-
- uses: actions/checkout@v4
21+
- uses: actions/checkout@v6
1822
with:
1923
ref: ${{ inputs.ref }}
2024
submodules: recursive
@@ -30,16 +34,22 @@ runs:
3034
env:
3135
GITHUB_TOKEN: ${{ github.token }}
3236
GITHUB_RELEASE_URL: ${{ github.api_url }}/repos/${{ github.repository }}/releases/${{ inputs.id }}
37+
INPUTS_FORCE: ${{ inputs.force }}
3338
run: |
3439
REPOSITORY_NAME=${GITHUB_REPOSITORY##*/}
3540
36-
TARBALL_PATH="/tmp/${REPOSITORY_NAME}-$(uname)-$(uname -m)-standard.tar.gz"
3741
RELEASE_NAME="${REPOSITORY_NAME}-$(uname)-$(uname -m)-standard"
42+
TARBALL_PATH="/tmp/${RELEASE_NAME}.tar.gz"
43+
44+
# Note: If assets should not be overwritten, exit early if they already exist
45+
if [[ "$INPUTS_FORCE" == 'false' && "$(./scripts/check-release.sh $TARBALL_PATH)" == 'true' ]]; then
46+
exit 0
47+
fi
3848
3949
# Note: the blst dependency uses the portable configuration for maximum compatibility
4050
./scripts/build-release.sh build --verbose --no-default-features --features multicore-sdr,opencl,blst-portable
4151
./scripts/package-release.sh $TARBALL_PATH
42-
./scripts/publish-release.sh $TARBALL_PATH $RELEASE_NAME
52+
./scripts/publish-release.sh $TARBALL_PATH
4353
working-directory: rust
4454
shell: bash
4555
- if: runner.os == 'Linux'
@@ -59,15 +69,21 @@ runs:
5969
env:
6070
GITHUB_TOKEN: ${{ github.token }}
6171
GITHUB_RELEASE_URL: ${{ github.api_url }}/repos/${{ github.repository }}/releases/${{ inputs.id }}
72+
INPUTS_FORCE: ${{ inputs.force }}
6273
run: |
6374
REPOSITORY_NAME=${GITHUB_REPOSITORY##*/}
6475
6576
RELEASE_NAME="${REPOSITORY_NAME}-$(uname)-standard"
6677
TARBALL_PATH="/tmp/${RELEASE_NAME}.tar.gz"
6778
79+
# Note: If assets should not be overwritten, exit early if they already exist
80+
if [[ "$INPUTS_FORCE" == 'false' && "$(./scripts/check-release.sh $TARBALL_PATH)" == 'true' ]]; then
81+
exit 0
82+
fi
83+
6884
# Note: the blst dependency uses the portable configuration for maximum compatibility
6985
./scripts/build-release.sh lipo --verbose --no-default-features --features multicore-sdr,opencl,blst-portable
7086
./scripts/package-release.sh $TARBALL_PATH
71-
./scripts/publish-release.sh $TARBALL_PATH $RELEASE_NAME
87+
./scripts/publish-release.sh $TARBALL_PATH
7288
working-directory: rust
7389
shell: bash

.github/workflows/release-check.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ jobs:
2929
runner: ['ubuntu-latest', ['self-hosted', 'linux', 'arm64', 'xlarge'], 'macos-latest']
3030
fail-fast: false
3131
steps:
32-
- uses: actions/checkout@v4
32+
- uses: actions/checkout@v6
3333
- uses: ./.github/actions/upload-release-assets
3434
with:
3535
id: ${{ fromJSON(needs.release-check.outputs.json)['version.json'].id }}
36+
force: true

.github/workflows/releaser.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,18 @@ jobs:
1919
sources: '["version.json"]'
2020
secrets:
2121
UCI_GITHUB_TOKEN: ${{ secrets.UCI_GITHUB_TOKEN }}
22+
upload-release-assets:
23+
needs: [releaser]
24+
if: fromJSON(needs.releaser.outputs.json)['version.json']
25+
name: Publish the static library (${{ matrix.runner }})
26+
runs-on: ${{ matrix.runner }}
27+
strategy:
28+
matrix:
29+
runner: ['ubuntu-latest', ['self-hosted', 'linux', 'arm64', 'xlarge'], 'macos-latest']
30+
fail-fast: false
31+
steps:
32+
- uses: actions/checkout@v6
33+
- uses: ./.github/actions/upload-release-assets
34+
with:
35+
id: ${{ fromJSON(needs.releaser.outputs.json)['version.json'].id }}
36+
force: false

.github/workflows/upload-release-assets.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ on:
99
ref:
1010
description: The release ref (e.g. refs/tags/v1.34.0)
1111
required: true
12+
force:
13+
type: boolean
14+
description: Whether the assets should be overwritten if they already exist
15+
required: false
16+
default: false
1217

1318
permissions:
1419
contents: write
@@ -27,8 +32,9 @@ jobs:
2732
runner: ['ubuntu-latest', ['self-hosted', 'linux', 'arm64', 'xlarge'], 'macos-latest']
2833
fail-fast: false
2934
steps:
30-
- uses: actions/checkout@v4
35+
- uses: actions/checkout@v6
3136
- uses: ./.github/actions/upload-release-assets
3237
with:
3338
id: ${{ inputs.id }}
3439
ref: ${{ inputs.ref }}
40+
force: ${{ inputs.force }}

RELEASE.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ This document describes the process for releasing a new version of the `filecoin
1414
5. Build the project for Linux (X64), Linux (ARM64), and MacOS.
1515
7. Upload the built assets to the draft release (replace any existing assets with the same name).
1616
- If for some reason asset uploading fails, the [Upload Release Assets](.github/workflows/upload-release-assets.yml) workflow can be manually run.
17-
3. On pull request merge, a [Releaser](.github/workflows/release.yml) workflow will run. It will perform the following actions:
17+
3. On pull request merge, a [Releaser](.github/workflows/releaser.yml) workflow will run. It will perform the following actions:
1818
1. Extract the version from the top-level `version.json` file.
1919
2. Check if a git tag for the version already exists. Continue only if it does not.
2020
3. Check if a draft GitHub release with the version as the tag exists.
2121
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+
5. Check if the release contains Linux (X64), Linux (ARM64), and MacOS assets. If not:
23+
1. Build the missing assets.
24+
2. Upload the built assets to the release.
25+
- If for some reason asset uploading fails, the [Upload Release Assets](.github/workflows/upload-release-assets.yml) workflow can be manually run.
26+
2227

2328
## Known Limitations
2429

2530
1. If one pushes an update to the `version` in the top-level `version.json` 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 [publish-release.sh](rust/scripts/publish-release.sh) script to upload the missing assets.
30-
- In the interim, if for some reason asset uploading fails, the [Upload Release Assets](.github/workflows/upload-release-assets.yml) workflow can be manually run.

rust/scripts/check-release.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
3+
set -Exeuo pipefail
4+
5+
main() {
6+
if [[ -z "$1" ]]
7+
then
8+
(>&2 echo '[check-release/main] Error: script requires a release (gzipped) tarball path, e.g. "/tmp/filecoin-ffi-Darwin-standard.tar.tz"')
9+
exit 1
10+
fi
11+
12+
# make sure we have a token set, api requests won't work otherwise
13+
if [ -z $GITHUB_TOKEN ]; then
14+
(>&2 echo "[check-release/main] \$GITHUB_TOKEN not set, check failed")
15+
exit 1
16+
fi
17+
18+
# make sure we have a release url set
19+
if [ -z "$GITHUB_RELEASE_URL" ]; then
20+
(>&2 echo "[check-release/main] \$GITHUB_RELEASE_URL not set, check failed")
21+
exit 1
22+
fi
23+
24+
local __release_file=$1
25+
local __release_url="${GITHUB_RELEASE_URL}"
26+
local __release_target="$(basename $__release_file)"
27+
28+
# see if the release already exists by tag
29+
local __release_response=`
30+
curl \
31+
--header "Authorization: token $GITHUB_TOKEN" \
32+
"$__release_url"
33+
`
34+
35+
local __release_id=`echo $__release_response | jq '.id'`
36+
37+
if [ "$__release_id" = "null" ]; then
38+
(>&2 echo '[check-release/main] release does not exist')
39+
exit 1
40+
fi
41+
42+
local __release_target_asset=`echo $__release_response | jq -r ".assets | .[] | select(.name == \"$__release_target\")"`
43+
44+
if [ -n "$__release_target_asset" ]; then
45+
(>&2 echo '[check-release/main] release asset exists')
46+
echo "true"
47+
else
48+
(>&2 echo '[check-release/main] release asset does not exist')
49+
echo "false"
50+
fi
51+
}
52+
53+
main "$@"; exit

rust/scripts/publish-release.sh

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,6 @@ main() {
99
exit 1
1010
fi
1111

12-
if [[ -z "$2" ]]
13-
then
14-
(>&2 echo '[publish-release/main] Error: script requires a release name, e.g. "filecoin-ffi-Darwin-standard" or "filecoin-ffi-Linux-standard"')
15-
exit 1
16-
fi
17-
18-
local __release_file=$1
19-
local __release_url="${GITHUB_RELEASE_URL}"
20-
local __release_target="$(basename $__release_file)"
21-
2212
# make sure we have a token set, api requests won't work otherwise
2313
if [ -z $GITHUB_TOKEN ]; then
2414
(>&2 echo "[publish-release/main] \$GITHUB_TOKEN not set, publish failed")
@@ -31,6 +21,10 @@ main() {
3121
exit 1
3222
fi
3323

24+
local __release_file=$1
25+
local __release_url="${GITHUB_RELEASE_URL}"
26+
local __release_target="$(basename $__release_file)"
27+
3428
# see if the release already exists by tag
3529
local __release_response=`
3630
curl \
@@ -45,7 +39,7 @@ main() {
4539
exit 1
4640
fi
4741

48-
__release_target_asset=`echo $__release_response | jq -r ".assets | .[] | select(.name == \"$__release_target\")"`
42+
local __release_target_asset=`echo $__release_response | jq -r ".assets | .[] | select(.name == \"$__release_target\")"`
4943

5044
if [ -n "$__release_target_asset" ]; then
5145
(>&2 echo "[publish-release/main] $__release_target_asset already exists, deleting")

0 commit comments

Comments
 (0)