Skip to content

Commit

Permalink
replace GH action to cover both build and releasing
Browse files Browse the repository at this point in the history
  • Loading branch information
jfding committed Sep 10, 2024
1 parent 6b784f4 commit bb39b53
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 22 deletions.
119 changes: 119 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
on:
# Indicates I want to run this workflow on all branches, PR, and tags
push:
branches: [ "main" ]
tags: [ "*" ]
pull_request:
branches: [ "main" ]

env:
RUST_VERSION: 1.80.1
BIN_NAME: "todor"

jobs:
build:
name: Build - ${{ matrix.platform.name }}
# By default, runs on Ubuntu, otherwise, override with the desired os
runs-on: ${{ matrix.platform.os || 'ubuntu-22.04' }}
strategy:
matrix:
# Set platforms you want to build your binaries on
platform:
# Linux
- name: Linux x86_64
target: x86_64-unknown-linux-musl
build-args: "--release"

# - name: Linux aarch64
# target: aarch64-unknown-linux-musl
# build-args: "--release"
#
# Mac OS
- name: MacOS x86_64
os: macos-latest
target: x86_64-apple-darwin
build-args: "--release"

# - name: MacOS aarch64
# os: macos-latest
# target: aarch64-apple-darwin
# build-args: "--release"

steps:
- name: Install package for linux
if: contains(matrix.platform.target, 'linux')
run: sudo apt install musl-tools

- name: Checkout Git repo
uses: actions/checkout@v3

# Linux & Windows
- name: Install rust toolchain for Linux
uses: actions-rs/toolchain@v1
with:
# We setup Rust toolchain and the desired target
profile: minimal
toolchain: "${{ env.RUST_VERSION }}"
override: true
target: ${{ matrix.platform.target }}
components: rustfmt, clippy

- name: Show command used for Cargo
run: |
echo "cargo command is: ${{ env.CARGO }}"
echo "target flag is: ${{ env.BUILD_ARGS }}"
- name: Build ${{ matrix.platform.name }} binary
uses: actions-rs/cargo@v1
# We use cross-rs if not running on x86_64 architecture on Linux
with:
command: build
use-cross: ${{ !contains(matrix.platform.target, 'x86_64') || contains(matrix.platform.target, 'freebsd') }}
args: ${{ matrix.platform.build-args }} --target ${{ matrix.platform.target }}

- name: archive the bin
run: |
export _BIN=${{ env.BIN_NAME }}${{ contains(matrix.platform.target, 'windows') && '.exe' || '' }}
mv target/${{ matrix.platform.target }}/release${{ contains(matrix.platform.target, 'windows') && '-with-symbols' || '' }}/$_BIN .
zip -r ${{ env.BIN_NAME }}-${{ matrix.platform.target }}.zip $_BIN
- name: Store artifact
uses: actions/upload-artifact@v4
with:
# Finally, we store the binary as GitHub artifact for later usage
name: ${{ env.BIN_NAME }}-${{ matrix.platform.target }}.zip
path: ${{ env.BIN_NAME }}-${{ matrix.platform.target }}.zip
retention-days: 1
compression-level: 9

release:
name: Release
needs: [ build ]
# We run the release job only if a tag starts with 'v' letter
#if: startsWith( github.ref, 'refs/tags/v' )
runs-on: ubuntu-22.04
steps:
- name: Checkout Git repo
uses: actions/checkout@v3
with:
fetch-depth: 0

# Download all artifacts
- uses: actions/download-artifact@v4
with:
merge-multiple: true

- name: list artifacts
run: ls

# - name: archive
# run: |
# bash -c 'cd artifacts; for _dir in `ls -d */`; do tar czpfv ${_dir}.tar.gz $_dir; done'

- name: Release
uses: softprops/action-gh-release@v2
with:
files: |
todor*.zip
make_latest: true
token: ${{ secrets.GITHUB_TOKEN }}
22 changes: 0 additions & 22 deletions .github/workflows/rust.yml

This file was deleted.

0 comments on commit bb39b53

Please sign in to comment.