Skip to content

Commit

Permalink
Refactor workflows (#2)
Browse files Browse the repository at this point in the history
* update build

* update pnpm to v9

* add cargo target

* update workflow dependencies

* refactor workflows into reusables
  • Loading branch information
Maneren committed Aug 2, 2024
1 parent 38c53d9 commit aa2aecc
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 175 deletions.
100 changes: 22 additions & 78 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,100 +1,56 @@
name: Build and upload binaries to release
name: Build the binaries
on:
push:
tags:
- v[0-9].*
workflow_call:
inputs:
target:
required: true
type: string
os:
required: true
type: string
jobs:
build-and-release:
name: Build and release
strategy:
matrix:
job:
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.job.os }}
reusable-build:
name: Build
runs-on: ${{ inputs.os }}
env:
CARGO_TARGET_DIR: target
LEPTOS_BIN_TARGET_TRIPLE: ${{ matrix.job.target }}
LEPTOS_BIN_TARGET_TRIPLE: ${{ inputs.target }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Initialize workflow variables
id: vars
shell: bash
run: |
TARGET=${{ matrix.job.target }}
case $TARGET in
*-pc-windows-*) BINARY="file-share.exe" ;;
*) BINARY="file-share" ;;
esac;
echo "BINARY=${BINARY}"
echo "BINARY=${BINARY}" >> "$GITHUB_ENV"
case $TARGET in
case ${{ inputs.target }} in
x86_64-*) CROSS="false" ;;
*) CROSS="true" ;;
esac;
echo "CROSS=${CROSS}"
echo "CROSS=${CROSS}" >> "$GITHUB_ENV"
case $TARGET in
*-linux-*) ARCHIVE="file-share_$TARGET.tar.gz" ;;
*) ARCHIVE="file-share_$TARGET.zip" ;;
esac;
echo "ARCHIVE=${ARCHIVE}"
echo "ARCHIVE=${ARCHIVE}" >> "$GITHUB_ENV"
RELEASE="target/${{ matrix.job.target }}/release"
echo "RELEASE=${RELEASE}"
echo "RELEASE=${RELEASE}" >> "$GITHUB_ENV"
case ${{ matrix.job.target }} in
aarch64-*linux*) STRIP="aarch64-linux-gnu-strip" ;;
*-pc-windows-msvc) STRIP="" ;;
*) STRIP="strip"
esac;
echo "STRIP=${STRIP}"
echo "STRIP=${STRIP}" >> "$GITHUB_ENV"
- name: Install strip and gcc for other archs
if: contains(matrix.job.target, 'linux')
- name: Install gcc and linker for other archs
if: contains(inputs.target, 'linux')
run: |
sudo apt-get -y update
case ${{ matrix.job.target }} in
aarch64-*linux*) sudo apt-get -y install binutils-aarch64-linux-gnu gcc-aarch64-linux-gnu ;;
case ${{ inputs.target }} in
aarch64-*linux*) sudo apt-get -y install gcc-aarch64-linux-gnu ;;
x86_64-*linux*) sudo apt-get -y install mold ;;
esac;
- name: Install NodeJS
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: latest
- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
name: Install pnpm and Tailwind
with:
version: 8
version: 9
run_install: true
- name: Install rust tooling
uses: moonrepo/setup-rust@v1
with:
bins: cargo-leptos, cross
targets: '${{ matrix.job.target }},wasm32-unknown-unknown'
targets: "${{ inputs.target }},wasm32-unknown-unknown"
profile: minimal
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -106,15 +62,3 @@ jobs:
run: cargo leptos build --release
env:
LEPTOS_BIN_CARGO_COMMAND: cross
- name: Strip the binary
if: ${{ env.STRIP }}
run: ${{ env.STRIP }} '${{ env.RELEASE }}/${{ env.BINARY }}'
- name: Create archive
run: tar caf ${{ env.ARCHIVE }} -C ${{ env.RELEASE }} ${{ env.BINARY }}
- name: Upload binary to release
uses: svenstaro/[email protected]
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ env.ARCHIVE }}
asset_name: ${{ env.ARCHIVE }}
tag: ${{ github.ref }}
83 changes: 83 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Build and upload binaries to release
on:
push:
tags:
- v[0-9].*
jobs:
build-for-release:
name: Build and release
strategy:
matrix:
job:
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
uses: ./.github/workflows/build.yml
with:
target: ${{ matrix.job.target }}
os: ${{ matrix.job.os }}
release:
strategy:
matrix:
job:
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.job.os }}
env:
CARGO_TARGET_DIR: target
LEPTOS_BIN_TARGET_TRIPLE: ${{ matrix.job.target }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Initialize workflow variables
id: vars
shell: bash
run: |
TARGET=${{ matrix.job.target }}
case $TARGET in
*-pc-windows-*) BINARY="file-share.exe" ;;
*) BINARY="file-share" ;;
esac;
echo "BINARY=${BINARY}"
echo "BINARY=${BINARY}" >> "$GITHUB_ENV"
case $TARGET in
*-linux-*) ARCHIVE="file-share_$TARGET.tar.gz" ;;
*) ARCHIVE="file-share_$TARGET.zip" ;;
esac;
echo "ARCHIVE=${ARCHIVE}"
echo "ARCHIVE=${ARCHIVE}" >> "$GITHUB_ENV"
RELEASE="target/${{ matrix.job.target }}/release"
echo "RELEASE=${RELEASE}"
echo "RELEASE=${RELEASE}" >> "$GITHUB_ENV"
- name: Create archive
run: tar caf ${{ env.ARCHIVE }} -C ${{ env.RELEASE }} ${{ env.BINARY }}
- name: Upload binary to release
uses: svenstaro/[email protected]
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ env.ARCHIVE }}
asset_name: ${{ env.ARCHIVE }}
tag: ${{ github.ref }}
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Test building binaries
on:
pull_request:
types: [synchronize]
jobs:
build-for-release:
name: Build and release
strategy:
matrix:
job:
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
uses: ./.github/workflows/build.yml
with:
target: ${{ matrix.job.target }}
os: ${{ matrix.job.os }}
97 changes: 0 additions & 97 deletions .github/workflows/test_build.yml

This file was deleted.

0 comments on commit aa2aecc

Please sign in to comment.