Browse Source

dev: Add a github action workflow for building releases upon tagging

pull/2/head v0.3.2
JuanLeon Lahoz 5 years ago
parent
commit
fb2893f2bd
  1. 118
      .github/workflows/release.yml
  2. 2
      .github/workflows/test.yml

118
.github/workflows/release.yml

@ -0,0 +1,118 @@
# This is a simplification of the workflow for sharkdp/bat.
name: Release
on:
push:
# The idea here is to trigger a release upon receiving a release-like tag
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
env:
CICD_INTERMEDIATES_DIR: "_cicd-intermediates"
jobs:
build:
name: ${{ matrix.job.os }} (${{ matrix.job.target }})
runs-on: ${{ matrix.job.os }}
strategy:
fail-fast: false
matrix:
job:
- { os: ubuntu-18.04, target: x86_64-unknown-linux-gnu }
- { os: ubuntu-18.04, target: i686-unknown-linux-gnu, use-cross: true }
- { os: ubuntu-18.04, target: i686-unknown-linux-musl, use-cross: true }
- { os: ubuntu-18.04, target: x86_64-unknown-linux-musl, use-cross: true }
- { os: macos-10.15 , target: x86_64-apple-darwin }
steps:
- name: Checkout source code
uses: actions/checkout@v2
- name: Extract crate information
shell: bash
run: |
echo "PROJECT_NAME=$(sed -n 's/^name = "\(.*\)"/\1/p' Cargo.toml)" >> $GITHUB_ENV
echo "PROJECT_VERSION=v$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.job.target }}
override: true
profile: minimal
- name: Show version information (Rust, cargo, GCC)
shell: bash
run: |
gcc --version || true
rustup -V
rustup toolchain list
rustup default
cargo -V
rustc -V
- name: Build
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.job.use-cross }}
command: build
args: --release --target=${{ matrix.job.target }}
- name: Strip debug information from executable
id: strip
shell: bash
run: |
BIN_DIR="${{ env.CICD_INTERMEDIATES_DIR }}/stripped-release-bin"
mkdir -p "${BIN_DIR}"
BIN_NAME="${{ env.PROJECT_NAME }}"
BIN_PATH="${BIN_DIR}/${BIN_NAME}"
# Copy the release build binary to the result location
cp "target/${{ matrix.job.target }}/release/${BIN_NAME}" "${BIN_DIR}"
strip "${BIN_PATH}"
# Let subsequent steps know where to find the (stripped) bin
echo ::set-output name=BIN_PATH::${BIN_PATH}
echo ::set-output name=BIN_NAME::${BIN_NAME}
- name: Run tests
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.job.use-cross }}
command: test
args: --target=${{ matrix.job.target }} -- --test-threads 1
- name: Create tarball
id: package
shell: bash
run: |
PKG_BASENAME=${PROJECT_NAME}-${PROJECT_VERSION}-${{ matrix.job.target }}
PKG_NAME=${PKG_BASENAME}.tar.gz
echo ::set-output name=PKG_NAME::${PKG_NAME}
PKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/package"
ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/"
mkdir -p "${ARCHIVE_DIR}"
cp "${{ steps.strip.outputs.BIN_PATH }}" "$ARCHIVE_DIR"
ls -l ${{ env.CICD_INTERMEDIATES_DIR }}
ls -lR ${{ env.CICD_INTERMEDIATES_DIR }}/package
echo "${PKG_STAGING}" end test
tar -C "${PKG_STAGING}/${PKG_BASENAME}" -cvzf "${PKG_STAGING}/${PKG_NAME}" "${PROJECT_NAME}"
# Let subsequent steps know where to find the compressed package
echo ::set-output name=PKG_PATH::"${PKG_STAGING}/${PKG_NAME}"
- name: "Artifact upload: tarball"
uses: actions/upload-artifact@master
with:
name: ${{ steps.package.outputs.PKG_NAME }}
path: ${{ steps.package.outputs.PKG_PATH }}
- name: Publish archives and packages
uses: softprops/action-gh-release@v1
with:
files: |
${{ steps.package.outputs.PKG_PATH }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

2
.github/workflows/test.yml

@ -1,4 +1,4 @@
name: Rust
name: Test
on: [push, pull_request]

Loading…
Cancel
Save