name: CD
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch: inputs:
is_manual_cd:
default: true
description: Manual trigger
jobs:
common-assertions:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cargo version matches tag
if: github.event_name == 'push'
run: |
function ok() {
echo -e "\e[1;32mOK\e[0m"
}
function err() {
echo -e "\e[1;31m${@}\e[0m" >&2
exit 1
}
CRATE_VERSION=$(cat Cargo.toml | grep -e "^version" | head -1 | cut -d '=' -f2 | sed -e "s/ //" -e "s/\"//g")
[[ $GITHUB_REF == *"refs/tags"* ]] && TAG=$GITHUB_REF || err "Cannot determine git tag."
TAG=${TAG/refs\/tags\//}
[ "$CRATE_VERSION" = "$TAG" ] && ok "OK" || err "ERROR: Crate version does not match the git (release) tag."
publish-to-github:
name: Building ${{ matrix.job.target }}
runs-on: ${{ matrix.job.os }}
needs:
- common-assertions
strategy:
matrix:
job:
- { os: macos-latest, target: x86_64-apple-darwin, use-cross: false }
- { os: ubuntu-latest , target: x86_64-unknown-linux-gnu, use-cross: false }
- { os: ubuntu-latest, target: aarch64-unknown-linux-gnu, use-cross: true }
- { os: ubuntu-latest, target: arm-unknown-linux-gnueabihf, use-cross: true }
- { os: ubuntu-latest, target: i686-unknown-linux-gnu, use-cross: true }
steps:
- name: Installing Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Install required dependencies
env:
RUSTFLAGS: "-C target-feature=-crt-static"
shell: bash
run: |
if [[ ${{ matrix.job.target }} == arm-unknown-linux-gnueabihf ]]; then
sudo apt update
sudo apt-get install -y binutils-arm-linux-gnueabihf
fi
if [[ ${{ matrix.job.target }} == aarch64-unknown-linux-gnu ]]; then
sudo apt update
sudo apt-get install -y binutils-aarch64-linux-gnu
fi
- name: Checkout repository
uses: actions/checkout@v2
- name: Cargo build
env:
MACOSX_DEPLOYMENT_TARGET: 10.7
uses: actions-rs/cargo@v1
with:
command: build
use-cross: ${{ matrix.job.use-cross }}
args: --release --target ${{ matrix.job.target }}
- name: Generate Cargo Lockfile for easy package updates under NetBSD
shell: bash
run: |
cargo generate-lockfile
- name: Packaging final binary
shell: bash
env:
TARGET: ${{ matrix.job.target }}
PROJECT_NAME: dusage
PACKAGE_NAME: dusage
OS_NAME: ${{ matrix.job.os }}
run: ./.github/workflows/pack.sh
- name: Releasing assets
if: github.event_name == 'push'
uses: softprops/action-gh-release@v1
with:
files: |
dusage-*-${{ matrix.job.target }}.*
dusage*.deb
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-to-dockerhub:
if: ${{ false }} runs-on: ubuntu-latest
needs:
- common-assertions
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Prepare
id: prep
run: |
set -x
DOCKER_IMAGE=${GITHUB_REPOSITORY}
LATEST_TAG=$(git describe --tags --abbrev=0)
TAGS="${DOCKER_IMAGE}:${LATEST_TAG},${DOCKER_IMAGE}:latest"
echo $TAGS
echo ::set-output name=tags::${TAGS}
echo ::set-output name=docker_image::${DOCKER_IMAGE}
- name: Set up QEMU
uses: docker/setup-qemu-action@master
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
with:
driver-opts: image=moby/buildkit:master
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/amd64, linux/arm64
push: true
tags: ${{ steps.prep.outputs.tags }}
publish-to-cargo:
name: Publishing to Cargo
if: github.event_name == 'push'
needs:
- publish-to-github
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- uses: actions-rs/cargo@v1
with:
command: publish
args: --token ${{ secrets.CARGO_API_KEY }} --allow-dirty