Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: CI-CD

on:
pull_request:
branches:
- master

env:
CARGO_TERM_COLOR: always
PROJECT_NAME: snm

jobs:
build:
name: Release
strategy:
matrix:
job:
- os: ubuntu-latest,
target: aarch64-unknown-linux-gnu,
use_cross: true,
- os: ubuntu-latest,
target: x86_64-unknown-linux-gnu,
use_cross: true,
- os: ubuntu-latest,
target: armv7-unknown-linux-gnueabihf,
use_cross: true,
- os: windows-latest,
target: x86_64-pc-windows-msvc,
use_cross: false,
- os: macos-latest,
target: x86_64-apple-darwin,
use_cross: false,
runs-on: ${{ matrix.job.os }}
steps:
- name: Git Checkout
uses: actions/checkout@v2

- name: Install prerequisites
shell: bash
run: |
case ${{ matrix.job.target }} in
armv7-unknown-linux-gnueabihf) sudo apt-get -y update ; sudo apt-get -y install gcc-7-arm-linux-gnueabihf ;;
aarch64-unknown-linux-gnu) sudo apt-get -y update ; sudo apt-get -y install gcc-aarch64-linux-gnu ;;
esac

- name: Initialize workflow variables
id: vars
shell: bash
run: |
# parse commit reference info
REF_NAME=${GITHUB_REF#refs/*/}
unset REF_BRANCH ; case ${GITHUB_REF} in refs/heads/*) REF_BRANCH=${GITHUB_REF#refs/heads/} ;; esac;
unset REF_TAG ; case ${GITHUB_REF} in refs/tags/*) REF_TAG=${GITHUB_REF#refs/tags/} ;; esac;
REF_SHAS=${GITHUB_SHA:0:8}
echo set-output name=REF_NAME::${REF_NAME}
echo set-output name=REF_BRANCH::${REF_BRANCH}
echo set-output name=REF_TAG::${REF_TAG}
echo set-output name=REF_SHAS::${REF_SHAS}
echo ::set-output name=REF_NAME::${REF_NAME}
echo ::set-output name=REF_BRANCH::${REF_BRANCH}
echo ::set-output name=REF_TAG::${REF_TAG}
echo ::set-output name=REF_SHAS::${REF_SHAS}
# staging directory
STAGING='_staging'
echo set-output name=STAGING::${STAGING}
echo ::set-output name=STAGING::${STAGING}
# Determine EXE suffix
EXE_suffix="" ;
case ${{ matrix.job.target }} in *-pc-windows-*) EXE_suffix=".exe" ;; esac;
echo set-output name=EXE_suffix::${EXE_suffix}
echo ::set-output name=EXE_suffix::${EXE_suffix}
# package name
CONTENT_TYPE="x-tar"
PKG_suffix=".tar.gz" ;
case ${{ matrix.job.target }} in
*-pc-windows-*)
CONTENT_TYPE="zip"
PKG_suffix=".zip"
;;
esac;
PKG_BASENAME=${PROJECT_NAME}-${{ matrix.job.target }}
PKG_NAME=${PKG_BASENAME}${PKG_suffix}
echo set-output name=CONTENT_TYPE::${CONTENT_TYPE}
echo set-output name=PKG_suffix::${PKG_suffix}
echo set-output name=PKG_BASENAME::${PKG_BASENAME}
echo set-output name=PKG_NAME::${PKG_NAME}
echo ::set-output name=CONTENT_TYPE::${CONTENT_TYPE}
echo ::set-output name=PKG_suffix::${PKG_suffix}
echo ::set-output name=PKG_BASENAME::${PKG_BASENAME}
echo ::set-output name=PKG_NAME::${PKG_NAME}

- name: Create all needed build/work directories
shell: bash
run: |
mkdir -p '${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_BASENAME }}'

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.job.target }}
override: true
profile: minimal

- name: Test
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.job.use_cross }}
command: test
args: --target=${{ matrix.job.target }}

- name: Build
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.job.use_cross }}
command: build
args: --release --target=${{ matrix.job.target }}

- name: Upload build artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ env.PROJECT_NAME }}-${{ matrix.job.target }}
path: target/${{ matrix.job.target }}/release/${{ env.PROJECT_NAME }}${{ steps.vars.outputs.EXE_suffix }}