From fa96099dd4ae8a946634513f1a743c2484ccab7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Zorro?= Date: Wed, 6 Mar 2024 18:00:11 -0500 Subject: [PATCH] ci: wrapped up release scripts --- .github/workflows/main.yaml | 30 ++++-------- pkg/standalone/install.envsubst | 81 +++++++++++++++++++++++++++++++++ scripts/release.sh | 28 +++++++----- scripts/render-install.sh | 6 +++ 4 files changed, 113 insertions(+), 32 deletions(-) create mode 100644 pkg/standalone/install.envsubst create mode 100755 scripts/render-install.sh diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 0260b57..da3a6a7 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -34,14 +34,6 @@ jobs: name: linux-arm64 target: aarch64-unknown-linux-gnu runs-on: ubuntu-latest - - os: ubuntu - name: linux-armv7 - target: armv7-unknown-linux-gnueabi - runs-on: ubuntu-latest - - os: ubuntu - name: linux-armv6 - target: arm-unknown-linux-gnueabi - runs-on: ubuntu-latest - os: macos name: macos-x64 target: x86_64-apple-darwin @@ -70,6 +62,7 @@ jobs: cd ./dist tar -czvf scfz-${{ matrix.name }}.tar.gz ./${{ matrix.name }}/ cd .. + # TODO: Checksums - uses: actions/upload-artifact@v4 with: name: tarball-${{matrix.target}} @@ -102,15 +95,12 @@ jobs: - uses: actions/download-artifact@v4 with: path: ./dist - - run: ls -la ./dist - # - name: Release - # uses: softprops/action-gh-release@v1 - # if: startsWith(github.ref, 'refs/tags/') - # with: - # draft: true - # prerelease: ${{contains(github.ref, '-beta')}} - # body_path: ./dist/changelog.txt - # files: | # FIXME: Bun issue with bin path - # ./lib/scfz - # ./dist/scfz.tar.gz - # LICENSE + - run: scripts/release.sh + - name: Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + draft: true + prerelease: ${{contains(github.ref, '-beta')}} + body_path: ./dist/changelog.txt + files: ./dist/releases/${{github.ref_name}}/* diff --git a/pkg/standalone/install.envsubst b/pkg/standalone/install.envsubst new file mode 100644 index 0000000..d8c2770 --- /dev/null +++ b/pkg/standalone/install.envsubst @@ -0,0 +1,81 @@ +#!/bin/sh +set -eu + +info() { + echo "$@" >&2 +} + +error() { + echo "$@" >&2 + exit 1 +} + +get_os() { + os="$(uname -s)" + if [ "$os" = Darwin ]; then + echo "macos" + elif [ "$os" = Linux ]; then + echo "linux" + else + error "unsupported OS: $os" + fi +} + +get_arch() { + arch="$(uname -m)" + if [ "$arch" = x86_64 ]; then + echo "x64" + elif [ "$arch" = aarch64 ] || [ "$arch" = arm64 ]; then + echo "arm64" + else + error "unsupported architecture: $arch" + fi +} + +download_file() { + url="$1" + filename="$(basename "$url")" + cache_dir="$(mktemp -d)" + file="$cache_dir/$filename" + + info "Scaffoldizr: installing scfz..." + + if command -v curl >/dev/null 2>&1; then + curl -#fLo "$file" "$url" + else + if command -v wget >/dev/null 2>&1; then + stderr=$(mktemp) + wget -O "$file" "$url" >"$stderr" 2>&1 || error "wget failed: $(cat "$stderr")" + else + error "scfz standalone install requires curl or wget but neither is installed. Aborting." + fi + fi + + echo "$file" +} + +install_tool() { + # download the tarball + version="$SCFZ_VERSION" + repo="arch-formula/scaffoldizr" + os="$(get_os)" + arch="$(get_arch)" + install_path="${SCFZ_INSTALL_PATH:-$HOME/.local/bin/scfz}" + install_dir="$(dirname "$install_path")" + tarball_url="https://github.com/${repo}/releases/download/${version}/mise-${version}-${os}-${arch}.tar.gz" + + cache_file=$(download_file "$tarball_url") + + # TODO: Validate checksum + # cd "$(dirname "$cache_file")" && get_checksum | "$(shasum_bin)" -c >/dev/null + + # extract tarball + mkdir -p "$install_dir" + rm -rf "$install_path" + cd "$(mktemp -d)" + tar -xzf "$cache_file" + mv dist/bin/scfz "$install_path" + info "Scaffoldizr: installed successfully to $install_path" +} + +install_mise \ No newline at end of file diff --git a/scripts/release.sh b/scripts/release.sh index c85aa78..e8e77bc 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -1,33 +1,37 @@ #!/usr/bin/env bash set -euxo pipefail +BASE_DIR="$(pwd)" RELEASE_DIR="dist/releases" +BIN_DIR="dist/bin" SCFZ_VERSION="$(git tag --list | tail -n 1)" -export RELEASE_DIR SCFZ_VERSION +export BASE_DIR RELEASE_DIR SCFZ_VERSION rm -rf "${RELEASE_DIR:?}/$SCFZ_VERSION" +rm -rf "${BIN_DIR:?}" mkdir -p "$RELEASE_DIR/$SCFZ_VERSION" -mkdir -p "dist/bin" -touch "dist/bin/scfz" +mkdir -p "$BIN_DIR" find dist -name 'tarball-*' -exec sh -c ' target=${1#dist/tarball-} - cp "dist/tarball-$target/"*.txt "$RELEASE_DIR/$SCFZ_VERSION" + cp "dist/tarball-$target/"*.tar.gz "$RELEASE_DIR/$SCFZ_VERSION" ' sh {} \; platforms=( linux-x64 linux-arm64 - linux-armv6 - linux-armv7 macos-x64 macos-arm64 ) for platform in "${platforms[@]}"; do - cp "$RELEASE_DIR/$SCFZ_VERSION/scfz-$platform.txt" "$RELEASE_DIR/$SCFZ_VERSION/scfz-$SCFZ_VERSION-$platform.txt" - cp "$RELEASE_DIR/$SCFZ_VERSION/scfz-$SCFZ_VERSION-$platform.txt" "$RELEASE_DIR/scfz-latest-$platform.txt" - tar -xvzf "$RELEASE_DIR/$SCFZ_VERSION/scfz-$SCFZ_VERSION-$platform.txt" - cp -v dist/bin/scfz "$RELEASE_DIR/scfz-latest-$platform" - cp -v dist/bin/scfz "$RELEASE_DIR/$SCFZ_VERSION/scfz-$SCFZ_VERSION-$platform" -done \ No newline at end of file + mv "$RELEASE_DIR/$SCFZ_VERSION/scfz-$platform.tar.gz" "$RELEASE_DIR/$SCFZ_VERSION/scfz-$SCFZ_VERSION-$platform.tar.gz" + cp "$RELEASE_DIR/$SCFZ_VERSION/scfz-$SCFZ_VERSION-$platform.tar.gz" "$RELEASE_DIR/scfz-latest-$platform.tar.gz" + tar -xvzf "$RELEASE_DIR/$SCFZ_VERSION/scfz-$SCFZ_VERSION-$platform.tar.gz" -C "$BIN_DIR" + cp -v "dist/bin/$platform/scfz" "$RELEASE_DIR/scfz-latest-$platform" + cp -v "dist/bin/$platform/scfz" "$RELEASE_DIR/$SCFZ_VERSION/scfz-$SCFZ_VERSION-$platform" +done + +./scripts/render-install.sh >"$RELEASE_DIR"/install.sh +chmod +x "$RELEASE_DIR"/install.sh +# TODO: Figure out where to publish the install file \ No newline at end of file diff --git a/scripts/render-install.sh b/scripts/render-install.sh new file mode 100755 index 0000000..9539287 --- /dev/null +++ b/scripts/render-install.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -euxo pipefail + +SCFZ_VERSION=$SCFZ_VERSION; + +envsubst '$SCFZ_VERSION' <"$BASE_DIR/pkg/standalone/install.envsubst" \ No newline at end of file