From a6c8560cfa87e1acd567fea00cf8f8501eac5b67 Mon Sep 17 00:00:00 2001 From: Naveen Narayanan Date: Wed, 6 Nov 2024 16:27:41 -0800 Subject: [PATCH 1/2] [release] Updating typeshare release flow --- .github/workflows/release.yml | 39 +++----------- .gitignore | 4 ++ scripts/README.md | 37 ++++++++++++++ scripts/build.sh | 95 +++++++++++++++++++++++++++++++++++ 4 files changed, 142 insertions(+), 33 deletions(-) create mode 100644 scripts/README.md create mode 100755 scripts/build.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 34071ec3..89536f14 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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' @@ -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 " " ${{ github.ref_name }} # Mark the Github Releaseā„¢ as a non-draft now that everything has succeeded! publish-release: diff --git a/.gitignore b/.gitignore index 5c90629c..f97f9bbb 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,7 @@ dist/ # IDE specific files .idea/ .vscode/ + +upload.txt +dist-manifest.json +.intentionally-empty-file.o diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 00000000..fb7e6945 --- /dev/null +++ b/scripts/README.md @@ -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 of the release + --target 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 +``` diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 00000000..35f28929 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,95 @@ +#!/bin/bash + + +set -e + +function help() { + echo "Usage: $0 [options]" + echo "Options:" + echo " --version Version of the release" + echo " --target 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="" + +# 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!" From 8b642cfb1223324ba7fe722692e34ef58b4b9e10 Mon Sep 17 00:00:00 2001 From: Naveen Narayanan Date: Wed, 6 Nov 2024 16:28:47 -0800 Subject: [PATCH 2/2] Cleanup --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 89536f14..1ac9e33a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -123,7 +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: | - scripts/build.sh --target " " ${{ github.ref_name }} + scripts/build.sh --target "${{ matrix.target }}" "${{ github.ref_name }}" # Mark the Github Releaseā„¢ as a non-draft now that everything has succeeded! publish-release: