Skip to content

fix(cli): correct scaffold for iac #41

fix(cli): correct scaffold for iac

fix(cli): correct scaffold for iac #41

Workflow file for this run

name: Build Binaries
on:
push:
branches:
- main
- ci
workflow_dispatch:
concurrency:
group: ${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
get_release_info:
name: Get Release Info
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.new_release_tag.outputs.TAG }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get latest release
if: startsWith(github.ref, 'refs/heads/main')
id: release
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: ${{ github.repository }}
excludes: prerelease, draft
- name: Determine if release build
if: startsWith(github.ref, 'refs/heads/main')
id: new_release_tag
env:
LATEST_RELEASE: ${{ steps.release.outputs.release }}
run: |
CARGO_VERSION=v$(grep "version" Cargo.toml | head -n 1 | cut -d\" -f2)
if [[ "${CARGO_VERSION}" != "${LATEST_RELEASE}" ]]; then
echo "::set-output name=TAG::${CARGO_VERSION}"
echo "::warning::Will create release for version: ${CARGO_VERSION}"
else
echo "::warning::Will not create a release"
fi
dist_surfpool:
name: Build Surfpool Distributions
runs-on: ${{ matrix.os }}
outputs:
LINUX_X64_SHA: ${{ steps.linux_x64_sha.outputs.LINUX_X64_SHA }}
MACOS_X64_SHA: ${{ steps.macos_x64_sha.outputs.MACOS_X64_SHA }}
MACOS_ARM64_SHA: ${{ steps.macos_arm64_sha.outputs.MACOS_ARM64_SHA }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-20.04
platform: linux
target: x86_64-unknown-linux-gnu
architecture: x64
# - os: windows-latest
# platform: windows
# target: x86_64-pc-windows-msvc
# architecture: x64
- os: macos-latest
platform: darwin
target: x86_64-apple-darwin
architecture: x64
- os: macos-latest
platform: darwin
target: aarch64-apple-darwin
architecture: arm64
steps:
# pre-build for windows
- name: Configure git to use LF (Windows)
if: matrix.os == 'windows-latest'
run: |
git config --global core.autocrlf false
git config --global core.eol lf
# pre-build for all OS
- name: Checkout repository
uses: actions/checkout@v4
# set up rust for all envs
- name: Install Rust toolchain
run: rustup toolchain install 1.84.0 --profile minimal --target ${{ matrix.target }}
- name: Install Rust Target
run: rustup target add ${{ matrix.target }}
# env vars unix
- name: Get Rust version (unix)
if: matrix.os != 'windows-latest'
run: echo "RUST_VERSION_HASH=$(rustc --version | shasum -a 256 | awk '{print $1}')" >> $GITHUB_ENV
# env vars windows
- name: "Get Rust version (windows)"
if: matrix.os == 'windows-latest'
shell: bash
run: echo "RUST_VERSION_HASH=$(rustc --version | sha256sum | awk '{print $1}')" >> $GITHUB_ENV
- name: Cache cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/
./target/${{ matrix.target }}/release/
key: ${{ runner.os }}-rust-${{ env.RUST_VERSION_HASH }}-cargo-${{ hashFiles('./Cargo.lock') }}
# Set environment variables required from cross compiling from macos-x86_64 to macos-arm64
- name: Configure macos-arm64 cross compile config
if: matrix.target == 'aarch64-apple-darwin'
run: |
echo "SDKROOT=$(xcrun -sdk macosx --show-sdk-path)" >> $GITHUB_ENV
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)" >> $GITHUB_ENV
- name: Configure artifact names
shell: bash
run: |
echo "SHORT_TARGET_NAME=${{ matrix.platform }}-${{ matrix.architecture }}" >> $GITHUB_ENV
echo "PRE_GYP_TARGET_NAME=${{ matrix.platform }}-${{ matrix.architecture }}-unknown" >> $GITHUB_ENV
- name: Build - Cargo
run:
cargo build --release --locked --target ${{ matrix.target }}
# Don't compress for Windows because winget can't yet unzip files
- name: Compress cargo artifact (not windows)
if: matrix.os != 'windows-latest'
run: tar -C target/${{ matrix.target }}/release -zcvf surfpool-${{ env.SHORT_TARGET_NAME }}.tar.gz surfpool
- name: Store SHA256 Hash of Tar (Linux x64)
if: matrix.os == 'ubuntu-20.04'
id: linux_x64_sha
run: |
echo "LINUX_X64_SHA=$(sha256sum surfpool-${{ env.SHORT_TARGET_NAME }}.tar.gz | awk '{ print $1 }')" >> "$GITHUB_OUTPUT"
- name: Store SHA256 Hash of Tar (Mac x64)
if: matrix.os == 'macos-latest' && matrix.architecture == 'x64'
id: macos_x64_sha
run: |
echo "MACOS_X64_SHA=$(shasum -a 256 surfpool-${{ env.SHORT_TARGET_NAME }}.tar.gz | awk '{ print $1 }')" >> "$GITHUB_OUTPUT"
- name: Store SHA256 Hash of Tar (Mac arm64)
if: matrix.os == 'macos-latest' && matrix.architecture == 'arm64'
id: macos_arm64_sha
run: |
echo "MACOS_ARM64_SHA=$(shasum -a 256 surfpool-${{ env.SHORT_TARGET_NAME }}.tar.gz | awk '{ print $1 }')" >> "$GITHUB_OUTPUT"
# Separate uploads to prevent paths from being preserved
- name: Upload cargo artifacts (not windows)
if: matrix.os != 'windows-latest'
uses: actions/upload-artifact@v4
with:
name: surfpool-${{ env.SHORT_TARGET_NAME }}
path: surfpool-${{ env.SHORT_TARGET_NAME }}.tar.gz
release:
name: Release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/heads/main') && needs.get_release_info.outputs.tag != ''
needs:
- dist_surfpool
- get_release_info
permissions:
actions: write
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download pre-built dists
uses: actions/download-artifact@v4
- name: Tag and Release
uses: ncipollo/release-action@v1
with:
artifacts: "**/*.tar.gz,**/*.msi"
tag: ${{ needs.get_release_info.outputs.tag }}
commit: ${{ env.GITHUB_SHA }}
- name: Pack artifacts
run: |
tar -czvf surfpool-linux-x64.tar.gz surfpool-linux-x64
tar -czvf surfpool-darwin-x64.tar.gz surfpool-darwin-x64
tar -czvf surfpool-darwin-arm64.tar.gz surfpool-darwin-arm64
homebrew:
name: Update Homebrew
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/heads/main') && needs.get_release_info.outputs.tag != ''
needs:
- dist_surfpool
- get_release_info
- release
permissions:
actions: write
contents: write
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Set up Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Clone the tap repository
run: |
git clone https://github.com/txtx/homebrew-taps.git
cd homebrew-taps
- name: Update the formula with new version and SHA256 values
run: |
pwd
ls
cd homebrew-taps
pwd
ls
# Define the new version
NEW_VERSION="${{ needs.get_release_info.outputs.tag }}"
# Update the version in all url fields, matching on any valid semver version
sed -i.bak "s/v[0-9]\+\.[0-9]\+\.[0-9]\+\(-[a-zA-Z0-9\.-]\+\)\?\(\+[a-zA-Z0-9\.-]\+\)\?/$(echo $NEW_VERSION)/g" Formula/surfpool.rb
# Update macOS x64 SHA256
sed -i.bak '/# sha for macos_x64/!b;n;c\ sha256 "'${{ needs.dist_surfpool.outputs.MACOS_X64_SHA }}'"' Formula/surfpool.rb
# Update macOS arm64 SHA256
sed -i.bak '/# sha for macos_arm64/!b;n;c\ sha256 "'${{ needs.dist_surfpool.outputs.MACOS_ARM64_SHA }}'"' Formula/surfpool.rb
# Update Linux x64 SHA256
sed -i.bak '/# sha for linux_x64/!b;n;c\ sha256 "'${{ needs.dist_surfpool.outputs.LINUX_X64_SHA }}'"' Formula/surfpool.rb
# Uncomment and update Linux ARM SHA256 when needed
# sed -i.bak '/# sha for linux_arm64/!b;n;c\ sha256 "'$SHA256_LINUX_ARM'"' Formula/surfpool.rb
# Remove backup file
rm Formula/surfpool.rb.bak
- name: Commit and push changes
run: |
pwd
ls
cd homebrew-taps
pwd
ls
git add Formula/surfpool.rb
git commit -m "Update to version ${{ needs.get_release_info.outputs.tag }}"
git push https://txtx:${{ secrets.TXTX_ACCESS_TOKEN }}@github.com/txtx/homebrew-taps.git
snapcraft:
name: Update Snapcraft
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/heads/main') && needs.get_release_info.outputs.tag != ''
needs:
- dist_surfpool
- get_release_info
- release
permissions:
actions: write
contents: write
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Set up Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Clone the tap repository
run: |
git clone https://github.com/txtx/snapcraft-surfpool.git
cd snapcraft-surfpool
- name: Update snapcraft.yaml
run: |
cd snapcraft-surfpool
NEW_VERSION="${{ needs.get_release_info.outputs.tag }}"
SOURCE_URL="https://github.com/txtx/surfpool/releases/download/${NEW_VERSION}/surfpool-linux-x64.tar.gz"
# Update the version and source URL in the snapcraft.yaml file
sed -i "s/^version:.*/version: '${NEW_VERSION}'/" snapcraft.yaml
sed -i "s|^ source: .*| source: ${SOURCE_URL}|" snapcraft.yaml
- name: Commit and push changes
run: |
cd snapcraft-surfpool
git add snapcraft.yaml
git commit -m "Update to version ${{ needs.get_release_info.outputs.tag }}"
git push https://txtx:${{ secrets.TXTX_ACCESS_TOKEN }}@github.com/txtx/snapcraft-surfpool.git