From 59370d15c2bfc5805e34aebfdb626e80bf7c7d83 Mon Sep 17 00:00:00 2001 From: jbeemster Date: Sun, 7 Feb 2021 14:44:24 +0100 Subject: [PATCH] More tweaks --- .github/workflows/cd.yml | 104 +++++++++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 16 +++--- .gitignore | 2 + Makefile | 60 ++++++++++++++++++++++ 4 files changed, 174 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/cd.yml create mode 100644 Makefile diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..4a5a19d --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,104 @@ +name: cd + +on: + push: + tags: + - '*' + +jobs: + release-ubuntu: + name: Release + strategy: + matrix: + os: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04] + runs-on: ${{ matrix.os }} + + steps: + - name: Install latest rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + default: true + override: true + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Test + run: make test + + - name: Extract tag version from ref + id: get_version + run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} + + - name: Build + run: make zip + env: + PLATFORM: ${{ matrix.os }} + BUILD_VERSION: ${{ steps.get_version.outputs.VERSION }} + + - name: Create Release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false + + - name: Upload release binaries + uses: alexellis/upload-assets@0.2.3 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + asset_paths: '["./build/compiled/*"]' + + release-macos: + name: Release + strategy: + matrix: + os: [macos-10.15] + runs-on: ${{ matrix.os }} + + steps: + - name: Install latest rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: x86_64-apple-darwin + default: true + override: true + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Test + run: make test + + - name: Extract tag version from ref + id: get_version + run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} + + - name: Build + run: make zip + env: + PLATFORM: ${{ matrix.os }} + BUILD_VERSION: ${{ steps.get_version.outputs.VERSION }} + + - name: Create Release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false + + - name: Upload release binaries + uses: alexellis/upload-assets@0.2.3 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + asset_paths: '["./build/compiled/*"]' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d8a2ce..06c6f49 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,11 +26,11 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - - name: Build - run: cargo build --verbose - - name: Test - run: cargo test --verbose + run: make test + + - name: Build + run: make debug - uses: Swatinem/rust-cache@v1 @@ -53,10 +53,10 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - - name: Build - run: cargo build --verbose - - name: Test - run: cargo test --verbose + run: make test + + - name: Build + run: make debug - uses: Swatinem/rust-cache@v1 diff --git a/.gitignore b/.gitignore index 043807d..b1d0461 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ Cargo.lock .factotum .vagrant +# Project +build/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a3b2d22 --- /dev/null +++ b/Makefile @@ -0,0 +1,60 @@ +.PHONY: debug release zip test check-env clean + +# ----------------------------------------------------------------------------- +# CONSTANTS +# ----------------------------------------------------------------------------- + +version = $(shell cat Cargo.toml | grep "^version = \"" | sed -n 's/^.*version = "\(.*\)".*/\1/p' | xargs) + +build_dir = build +target_dir = target +factotum_dir = .factotum + +compiled_dir = $(build_dir)/compiled + +# ----------------------------------------------------------------------------- +# BUILDING +# ----------------------------------------------------------------------------- + +debug: + cargo build --verbose + +release: + cargo build --verbose --release + +zip: release check-env +ifeq ($(version),$(BUILD_VERSION)) + mkdir -p $(compiled_dir) + (cd target/release && zip -r staging.zip factotum) + mv target/release/staging.zip $(compiled_dir)/factotum_$(version)_$(PLATFORM)_x86_64.zip +else + $(error BUILD_VERSION and Cargo.toml version do not match - cannot release) +endif + +# ----------------------------------------------------------------------------- +# TESTING +# ----------------------------------------------------------------------------- + +test: + cargo test --verbose + +# ----------------------------------------------------------------------------- +# HELPERS +# ----------------------------------------------------------------------------- + +check-env: +ifndef PLATFORM + $(error PLATFORM is undefined) +endif +ifndef BUILD_VERSION + $(error BUILD_VERSION is undefined) +endif + +# ----------------------------------------------------------------------------- +# CLEANUP +# ----------------------------------------------------------------------------- + +clean: + rm -rf $(build_dir) + rm -rf $(target_dir) + rm -rf $(factotum_dir)