Skip to content

Commit 4d88281

Browse files
[release] Updating typeshare release flow (#4)
## Description * Move mac binary to be manual due to lack of mac os workers * Added `scripts/README.md` ## Test Plan * CI ## Revert Plan * Revert
1 parent 4276775 commit 4d88281

File tree

4 files changed

+142
-33
lines changed

4 files changed

+142
-33
lines changed

.github/workflows/release.yml

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@ jobs:
8989
dist-args: --artifacts=global
9090
target: ''
9191
install-dist: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.0.4/cargo-dist-v0.0.4-installer.sh | sh
92-
- os: macos-11
93-
dist-args: --artifacts=local --target=aarch64-apple-darwin --target=x86_64-apple-darwin
94-
target: 'aarch64-apple-darwin x86_64-apple-darwin'
95-
install-dist: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.0.4/cargo-dist-v0.0.4-installer.sh | sh
92+
# Since we don't have a macos-11 runner, we will build manually on mac and upload
93+
# - os: macos-11
94+
# dist-args: --artifacts=local --target=aarch64-apple-darwin --target=x86_64-apple-darwin
95+
# target: 'aarch64-apple-darwin x86_64-apple-darwin'
96+
# install-dist: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.0.4/cargo-dist-v0.0.4-installer.sh | sh
9697
- os: ubuntu-20.04
9798
dist-args: --artifacts=local --target=x86_64-unknown-linux-gnu
9899
target: 'x86_64-unknown-linux-gnu'
@@ -122,35 +123,7 @@ jobs:
122123
# The two platforms don't agree on how to talk about env vars but they
123124
# do agree on 'cat' and '$()' so we use that to marshal values between commands.
124125
run: |
125-
pip3 install ziglang
126-
cargo install cargo-zigbuild
127-
rustup target add ${{ matrix.target }}
128-
cargo zigbuild --target ${{ matrix.target }} --release
129-
130-
# Set binary name to typeshare
131-
BINARY_NAME="typeshare"
132-
TARGET_DIR="target/${{ matrix.target }}/release"
133-
134-
# Create zip directory
135-
mkdir -p "dist"
136-
137-
# Create zip file with binary
138-
ZIP_NAME="${BINARY_NAME}-${{ github.ref_name }}-${{ matrix.target }}.zip"
139-
cd ${TARGET_DIR} && zip "../../../dist/${ZIP_NAME}" "${BINARY_NAME}${BINARY_SUFFIX}"
140-
cd ../../..
141-
142-
# Create manifest file similar to cargo-dist
143-
echo "{\"artifacts\": [{\"path\": \"dist/${ZIP_NAME}\"}]}" > dist-manifest.json
144-
145-
echo "Build complete, contents of dist-manifest.json:"
146-
cat dist-manifest.json
147-
148-
# Upload to release
149-
cat dist-manifest.json | jq --raw-output ".artifacts[]?.path | select( . != null )" > uploads.txt
150-
echo "uploading..."
151-
cat uploads.txt
152-
gh release upload ${{ github.ref_name }} $(cat uploads.txt)
153-
echo "uploaded!"
126+
scripts/build.sh --target "${{ matrix.target }}" "${{ github.ref_name }}"
154127
155128
# Mark the Github Release™ as a non-draft now that everything has succeeded!
156129
publish-release:

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ dist/
1313
# IDE specific files
1414
.idea/
1515
.vscode/
16+
17+
upload.txt
18+
dist-manifest.json
19+
.intentionally-empty-file.o

scripts/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Deploy binary to releases
2+
3+
This script is used to deploy a binary to the releases page of a GitHub repository.
4+
5+
## Pre-requisites
6+
`gh cli` must be installed and authenticated.
7+
8+
Installation:
9+
```sh
10+
brew install gh
11+
```
12+
13+
Authentication:
14+
```sh
15+
gh auth login
16+
```
17+
18+
## Usage
19+
20+
```sh
21+
Usage: ./build.sh [options]
22+
Options:
23+
--version <version> Version of the release
24+
--target <platform> Target platform
25+
Platforms:
26+
* "aarch64-apple-darwin"
27+
* "x86_64-apple-darwin"
28+
* "aarch64-unknown-linux-gnu"
29+
* "x86_64-unknown-linux-gnu"
30+
* "x86_64-pc-windows-msvc"
31+
```
32+
33+
## Example
34+
35+
```sh
36+
./build.sh --version 1.12.0 --target aarch64-apple-darwin
37+
```

scripts/build.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
3+
4+
set -e
5+
6+
function help() {
7+
echo "Usage: $0 [options]"
8+
echo "Options:"
9+
echo " --version <version> Version of the release"
10+
echo " --target <platform> Target platform"
11+
echo " Platforms: "
12+
echo " * \"aarch64-apple-darwin\""
13+
echo " * \"x86_64-apple-darwin\""
14+
echo " * \"aarch64-unknown-linux-gnu\""
15+
echo " * \"x86_64-unknown-linux-gnu\""
16+
echo " * \"x86_64-pc-windows-msvc\""
17+
exit 0
18+
}
19+
20+
# Options:
21+
# apple-arm64: aarch64-apple-darwin
22+
# apple-x86: x86_64-apple-darwin
23+
# linux-arm64: aarch64-unknown-linux-gnu
24+
# linux-x86: x86_64-unknown-linux-gnu
25+
# windows-x86: x86_64-pc-windows-msvc
26+
TARGET=""
27+
# --version <version>
28+
VERSION=""
29+
30+
# Parse command line arguments
31+
while [[ $# -gt 0 ]]; do
32+
key="$1"
33+
case $key in
34+
--target)
35+
TARGET="$2"
36+
shift
37+
shift
38+
;;
39+
--version)
40+
VERSION="$2"
41+
shift
42+
shift
43+
;;
44+
-h|--help)
45+
help
46+
;;
47+
*)
48+
echo "Unknown option: $1"
49+
exit 1
50+
;;
51+
esac
52+
done
53+
54+
# Check if required arguments are provided
55+
if [ -z "${TARGET}" ]; then
56+
echo "Missing required argument: --target"
57+
exit 1
58+
fi
59+
60+
if [ -z "$VERSION" ]; then
61+
echo "Missing required argument: --version"
62+
exit 1
63+
fi
64+
65+
# Build the project
66+
pip3 install ziglang
67+
cargo install cargo-zigbuild
68+
rustup target add "${TARGET}"
69+
cargo zigbuild --target "${TARGET}" --release
70+
71+
# Set binary name to typeshare
72+
BINARY_NAME="typeshare"
73+
TARGET_DIR="target/${TARGET}/release"
74+
75+
# Create zip directory
76+
mkdir -p "dist"
77+
78+
OUTPUT_DIR="$(pwd)/dist"
79+
80+
# Create zip file with binary
81+
ZIP_NAME="${BINARY_NAME}-${VERSION}-${TARGET}.zip"
82+
pushd ${TARGET_DIR} && zip "${OUTPUT_DIR}/${ZIP_NAME}" "${BINARY_NAME}${BINARY_SUFFIX}" && popd
83+
84+
# Create manifest file similar to cargo-dist
85+
echo "{\"artifacts\": [{\"path\": \"dist/${ZIP_NAME}\"}]}" > dist-manifest.json
86+
87+
echo "Build complete, contents of dist-manifest.json:"
88+
cat dist-manifest.json
89+
90+
# Upload to release
91+
cat dist-manifest.json | jq --raw-output ".artifacts[]?.path | select( . != null )" > uploads.txt
92+
echo "uploading..."
93+
cat uploads.txt
94+
gh release upload ${VERSION} $(cat uploads.txt)
95+
echo "uploaded!"

0 commit comments

Comments
 (0)