From 96ace8590eb138e02179e16f49a1027e9cf81f72 Mon Sep 17 00:00:00 2001 From: Mendy Man Date: Sat, 22 Feb 2025 19:07:41 -0500 Subject: [PATCH] Build and publish binaries after new release This new workflow runs after a github release is published. It builds for 5 targets, and after all 5 builds are successful The newly built releases are published to the release tag --- .github/workflows/release.yml | 99 +++++++++++++++++++++++++++++++ LICENSE | 21 +++++++ scripts/generate_release_files.sh | 38 ++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 LICENSE create mode 100755 scripts/generate_release_files.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..5be7b68 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,99 @@ +name: Release +permissions: + contents: "write" + +on: + release: + types: [published] + +jobs: + build-linux: + runs-on: ubuntu-24.04 + strategy: + matrix: + target: ["x86_64-unknown-linux-musl", "aarch64-unknown-linux-gnu"] + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} + - name: Install deps + # cargo-dist uses cargo zigbuild to build for arm/x86 (zig is required to use cargo zigbuild) + # I use brew because I don't think apt has a zig package, and I may as well install cargo zigbuild from brew + run: | + eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" + brew install zig cargo-zigbuild + - name: Build ${{ matrix.target }} + run: | + eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" + cargo zigbuild --release --target ${{ matrix.target }} + ./scripts/generate_release_files.sh ${{ matrix.target }} + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: artifact-${{ matrix.target }} + path: target/distrib/* + + build-macos: + runs-on: macos-14 + strategy: + matrix: + target: ["aarch64-apple-darwin", "x86_64-apple-darwin"] + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} + - name: Install deps + # cargo-dist uses cargo zigbuild to build for arm/x86 (zig is required to use cargo zigbuild) + # I use brew to install zig and coreutils (sha256sum needs to be installed by coreutils), and I may as well install cargo zigbuild from brew + run: | + brew install zig cargo-zigbuild coreutils + - name: Build ${{ matrix.target }} + run: | + cargo zigbuild --release --target ${{ matrix.target }} + ./scripts/generate_release_files.sh ${{ matrix.target }} + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: artifact-${{ matrix.target }} + path: target/distrib/* + + build-windows: + runs-on: windows-2022 + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + targets: x86_64-pc-windows-msvc + - name: Build x86_64-pc-windows-msvc + run: | + cargo build --release --target x86_64-pc-windows-msvc + bash ./scripts/generate_release_files.sh x86_64-pc-windows-msvc + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: artifact-x86_64-pc-windows-msvc + path: target/distrib/* + + publish-artifacts: + runs-on: ubuntu-24.04 + needs: + - build-linux + - build-macos + - build-windows + steps: + - uses: actions/checkout@v4 + - name: Fetch local artifacts + uses: actions/download-artifact@v4 + with: + pattern: artifact-* + path: target/distrib/ + merge-multiple: true + - name: Upload files to release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release upload ${{ github.event.release.tag_name }} target/distrib/* + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..568637b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2025 Svix (https://www.svix.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/scripts/generate_release_files.sh b/scripts/generate_release_files.sh new file mode 100755 index 0000000..c486add --- /dev/null +++ b/scripts/generate_release_files.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +if [ -z "$1" ] + then + echo "No argument supplied" + exit 1 +fi + +set -eox pipefail + +if [ "$(uname)" == "Darwin" ]; then + TAR_BIN="gtar" +else + TAR_BIN="tar" +fi + +BIN_NAME="openapi-codegen" +mkdir -p target/distrib + +if [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then + PKG_FILENAME="$BIN_NAME-$1.zip" + 7z a -tzip \ + "target/distrib/$PKG_FILENAME" \ + README.md \ + LICENSE \ + "./target/$1/release/$BIN_NAME.exe" -w"./target/$1/release" +else + PKG_FILENAME="$BIN_NAME-$1.tar.xz" + $TAR_BIN -czf \ + "target/distrib/$PKG_FILENAME" \ + README.md \ + LICENSE \ + --transform="s|target/$1/release/$BIN_NAME|$BIN_NAME|" \ + "target/$1/release/$BIN_NAME" +fi + +cd target/distrib +sha256sum $PKG_FILENAME > "$PKG_FILENAME.sha256" +