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

[release] Updating typeshare release flow #4

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 6 additions & 33 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ jobs:
dist-args: --artifacts=global
target: ''
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
- os: macos-11
dist-args: --artifacts=local --target=aarch64-apple-darwin --target=x86_64-apple-darwin
target: 'aarch64-apple-darwin x86_64-apple-darwin'
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
# Since we don't have a macos-11 runner, we will build manually on mac and upload
# - os: macos-11
# dist-args: --artifacts=local --target=aarch64-apple-darwin --target=x86_64-apple-darwin
# target: 'aarch64-apple-darwin x86_64-apple-darwin'
# 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
- os: ubuntu-20.04
dist-args: --artifacts=local --target=x86_64-unknown-linux-gnu
target: 'x86_64-unknown-linux-gnu'
Expand Down Expand Up @@ -122,35 +123,7 @@ jobs:
# The two platforms don't agree on how to talk about env vars but they
# do agree on 'cat' and '$()' so we use that to marshal values between commands.
run: |
pip3 install ziglang
cargo install cargo-zigbuild
rustup target add ${{ matrix.target }}
cargo zigbuild --target ${{ matrix.target }} --release

# Set binary name to typeshare
BINARY_NAME="typeshare"
TARGET_DIR="target/${{ matrix.target }}/release"

# Create zip directory
mkdir -p "dist"

# Create zip file with binary
ZIP_NAME="${BINARY_NAME}-${{ github.ref_name }}-${{ matrix.target }}.zip"
cd ${TARGET_DIR} && zip "../../../dist/${ZIP_NAME}" "${BINARY_NAME}${BINARY_SUFFIX}"
cd ../../..

# Create manifest file similar to cargo-dist
echo "{\"artifacts\": [{\"path\": \"dist/${ZIP_NAME}\"}]}" > dist-manifest.json

echo "Build complete, contents of dist-manifest.json:"
cat dist-manifest.json

# Upload to release
cat dist-manifest.json | jq --raw-output ".artifacts[]?.path | select( . != null )" > uploads.txt
echo "uploading..."
cat uploads.txt
gh release upload ${{ github.ref_name }} $(cat uploads.txt)
echo "uploaded!"
scripts/build.sh --target "${{ matrix.target }}" "${{ github.ref_name }}"

# Mark the Github Release™ as a non-draft now that everything has succeeded!
publish-release:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ dist/
# IDE specific files
.idea/
.vscode/

upload.txt
dist-manifest.json
.intentionally-empty-file.o
37 changes: 37 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Deploy binary to releases

This script is used to deploy a binary to the releases page of a GitHub repository.

## Pre-requisites
`gh cli` must be installed and authenticated.

Installation:
```sh
brew install gh
```

Authentication:
```sh
gh auth login
```

## Usage

```sh
Usage: ./build.sh [options]
Options:
--version <version> Version of the release
--target <platform> Target platform
Platforms:
* "aarch64-apple-darwin"
* "x86_64-apple-darwin"
* "aarch64-unknown-linux-gnu"
* "x86_64-unknown-linux-gnu"
* "x86_64-pc-windows-msvc"
```

## Example

```sh
./build.sh --version 1.12.0 --target aarch64-apple-darwin
```
95 changes: 95 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash


set -e

function help() {
echo "Usage: $0 [options]"
echo "Options:"
echo " --version <version> Version of the release"
echo " --target <platform> Target platform"
echo " Platforms: "
echo " * \"aarch64-apple-darwin\""
echo " * \"x86_64-apple-darwin\""
echo " * \"aarch64-unknown-linux-gnu\""
echo " * \"x86_64-unknown-linux-gnu\""
echo " * \"x86_64-pc-windows-msvc\""
exit 0
}

# Options:
# apple-arm64: aarch64-apple-darwin
# apple-x86: x86_64-apple-darwin
# linux-arm64: aarch64-unknown-linux-gnu
# linux-x86: x86_64-unknown-linux-gnu
# windows-x86: x86_64-pc-windows-msvc
TARGET=""
# --version <version>
VERSION=""

# Parse command line arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--target)
TARGET="$2"
shift
shift
;;
--version)
VERSION="$2"
shift
shift
;;
-h|--help)
help
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done

# Check if required arguments are provided
if [ -z "${TARGET}" ]; then
echo "Missing required argument: --target"
exit 1
fi

if [ -z "$VERSION" ]; then
echo "Missing required argument: --version"
exit 1
fi

# Build the project
pip3 install ziglang
cargo install cargo-zigbuild
rustup target add "${TARGET}"
cargo zigbuild --target "${TARGET}" --release

# Set binary name to typeshare
BINARY_NAME="typeshare"
TARGET_DIR="target/${TARGET}/release"

# Create zip directory
mkdir -p "dist"

OUTPUT_DIR="$(pwd)/dist"

# Create zip file with binary
ZIP_NAME="${BINARY_NAME}-${VERSION}-${TARGET}.zip"
pushd ${TARGET_DIR} && zip "${OUTPUT_DIR}/${ZIP_NAME}" "${BINARY_NAME}${BINARY_SUFFIX}" && popd

# Create manifest file similar to cargo-dist
echo "{\"artifacts\": [{\"path\": \"dist/${ZIP_NAME}\"}]}" > dist-manifest.json

echo "Build complete, contents of dist-manifest.json:"
cat dist-manifest.json

# Upload to release
cat dist-manifest.json | jq --raw-output ".artifacts[]?.path | select( . != null )" > uploads.txt
echo "uploading..."
cat uploads.txt
gh release upload ${VERSION} $(cat uploads.txt)
echo "uploaded!"
Loading