Skip to content

Commit

Permalink
Add github action workflows for tests and releases
Browse files Browse the repository at this point in the history
  • Loading branch information
mkroman committed Dec 13, 2020
1 parent ad7253e commit 1343aec
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: CI

on:
pull_request:
push:
workflow_dispatch:

jobs:
test-and-clippy:
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Run tests
run: cargo test --verbose

- name: Run clippy
run: cargo clippy
95 changes: 95 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Release

on:
push:
tags:
- 'v*'
workflow_dispatch:

jobs:
test-and-clippy:
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Run tests
run: cargo test --verbose

- name: Run clippy
run: cargo clippy

# Cross-compilation builds for other targets, using `cross`, from linux
linux-cross-build:
runs-on: ubuntu-latest
needs:
- test-and-clippy

strategy:
fail-fast: false
matrix:
target:
- aarch64-unknown-linux-musl
- arm-unknown-linux-musleabi
- i686-unknown-linux-musl
- x86_64-pc-windows-gnu
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install cross
run: cargo install cross

- name: Build for ${{ matrix.target }}
run: scripts/cross-build.sh ${{ matrix.target }}

- name: Upload ${{ matrix.target }} artifacts
uses: actions/upload-artifact@v2
with:
name: release-${{ matrix.target }}
path: release-dist/*

- name: Upload github release executable
run: |
export PATH=$PATH:$(go env GOPATH)/bin
go get github.com/tcnksm/ghr
version=$(git describe --tags | tr -d '\n')
ghr "${version}" release-dist/bouffalo-cli-*.gz
macos-build:
runs-on: macos-latest
needs:
- test-and-clippy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Build release
run: cargo build --verbose --release

- name: Prepare artifacts
run: |
mkdir -p target/dist
version=$(git describe --tags | tr -d '\n')
bin="target/dist/bouffalo-cli-${version}-x86_64-apple-darwin"
cp target/release/bouffalo-cli "${bin}"
gzip "${bin}"
export PATH=$PATH:$(go env GOPATH)/bin
go get github.com/tcnksm/ghr
ghr "${version}" target/dist/*.gz
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: release-x86_64-apple-darwin
path: target/dist/*
35 changes: 35 additions & 0 deletions scripts/cross-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

# This scripts attempts to build the project using `cross` for a given target

if [ $# -ne 1 ]; then
echo "Usage ${0} <target>"
exit 1
fi

target=${1}
temp_dir="release-dist"
version=$(git describe --tags | tr -d '\n')

mkdir -p "${temp_dir}"

set -e -x

echo "Building for target ${target}"

cross build --verbose --release --target="${target}"

# Copy the binary to the temporary directory
if [[ $target =~ "-pc-windows-gnu" ]]; then
ext=.exe
else
ext=
fi

rls_path="target/${target}/release"
#
if [ -e "${rls_path}/bouffalo-cli${ext}" ]; then
rls_name="bouffalo-cli-${version}-${target}"
cp "${rls_path}/bouffalo-cli${ext}" "${temp_dir}/${rls_name}${ext}"
gzip "${temp_dir}/${rls_name}${ext}"
fi

0 comments on commit 1343aec

Please sign in to comment.