build: overhaul ci/cd pipelines

pull/25/head
sgoudham 1 year ago committed by Hamothy
parent b72a5a33fb
commit 6ee58693ee

@ -1,25 +0,0 @@
name: build
on:
push:
paths-ignore:
- 'src/**'
- 'tests/**'
- '.github/**'
- 'Cargo.toml'
- 'Cargo.lock'
branches:
- '**'
pull_request:
paths-ignore:
- 'src/**'
- 'tests/**'
- '.github/**'
- 'Cargo.toml'
- 'Cargo.lock'
jobs:
build:
runs-on: ubuntu-latest
steps:
- run: 'echo "No build required"'

@ -1,116 +1,151 @@
# Copyright (c) 2023 Hamothy
# Copyright (c) 2015 Andrew Gallant
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
name: build name: build
on: on:
workflow_dispatch:
push: push:
paths: paths:
- 'src/**' - "src/**"
- 'tests/**' - "Cargo.toml"
- '.github/**' - "Cargo.lock"
- 'Cargo.toml'
- 'Cargo.lock'
branches:
- '**'
pull_request: pull_request:
paths: paths:
- 'src/**' - "src/**"
- 'tests/**' - "Cargo.toml"
- '.github/**' - "Cargo.lock"
- 'Cargo.toml'
- 'Cargo.lock' env:
BINARY: git-view
jobs: jobs:
windows: compile:
runs-on: windows-latest env:
# For some builds, we use cross to test on 32-bit and big-endian systems.
CARGO: cargo
# When CARGO is set to CROSS, this is set to `--target matrix.target`.
TARGET_FLAGS:
# When CARGO is set to CROSS, TARGET_DIR includes matrix.target.
TARGET_DIR: ./target
# Emit backtraces on panics.
RUST_BACKTRACE: 1
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
strategy: strategy:
fail-fast: false
matrix: matrix:
target: build:
- x86_64-pc-windows-gnu - stable
- x86_64-pc-windows-msvc - nightly-gnu
- nightly-musl
- nightly-32
- nightly-arm
- macos
- win-msvc
- win-gnu
include:
- build: stable
os: ubuntu-22.04
rust: stable
- build: nightly-gnu
os: ubuntu-22.04
rust: nightly
target: x86_64-unknown-linux-gnu
- build: nightly-musl
os: ubuntu-22.04
rust: nightly
target: x86_64-unknown-linux-musl
- build: nightly-32
os: ubuntu-22.04
rust: nightly
target: i686-unknown-linux-gnu
- build: nightly-arm
os: ubuntu-22.04
rust: nightly
target: arm-unknown-linux-gnueabihf
- build: macos
os: macos-12
rust: nightly
target: x86_64-apple-darwin
- build: win-msvc
os: windows-2022
rust: nightly
- build: win-gnu
os: windows-2022
rust: nightly-x86_64-gnu
steps: steps:
- uses: actions/checkout@v3 - name: Checkout repository
- name: Cache Cargo uses: actions/checkout@v3
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
./target
# Example key: windows-stable-x86_64-pc-windows-gnu-3k4j234lksjfd9
key: windows-stable-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
windows-stable-${{ matrix.target }}-
windows-stable-
windows-
- name: Set Rust Channel
run: rustup default stable
shell: bash
- name: Set Rust Target
run: rustup target add ${{ matrix.target }}
shell: bash
- name: Build
run: cargo build --target ${{ matrix.target }}
shell: bash
- name: Test
run: cargo test --target ${{ matrix.target }}
shell: bash
macos: - name: Install packages (Ubuntu)
runs-on: macos-latest if: matrix.os == 'ubuntu-22.04'
strategy: run: sudo apt-get update && sudo apt-get install -y --no-install-recommends musl-tools
matrix:
target:
- x86_64-apple-darwin
steps: - name: Install Rust
- uses: actions/checkout@v3 uses: dtolnay/rust-toolchain@master
- name: Cache Cargo
uses: actions/cache@v3
with: with:
path: | toolchain: ${{ matrix.rust }}
~/.cargo/registry
./target - name: Cache Rust
# Example key: macos-stable-x86_64-apple-darwin-3k4j234lksjfd9 uses: Swatinem/rust-cache@v2
key: macos-stable-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: | - name: Use Cross
macos-stable-${{ matrix.target }}- if: matrix.target != ''
macos-stable- run: |
macos- cargo install cross
- name: Set Rust Channel echo "CARGO=cross" >> $GITHUB_ENV
run: rustup default stable echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
- name: Set Rust Target echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
run: rustup target add ${{ matrix.target }}
- name: Build - name: Show command used for Cargo
run: cargo build --target ${{ matrix.target }} run: |
echo "cargo command is: ${{ env.CARGO }}"
echo "target flag is: ${{ env.TARGET_FLAGS }}"
- name: Compile
run: ${{ env.CARGO }} build --verbose ${{ env.TARGET_FLAGS }}
- name: Test - name: Test
run: cargo test --target ${{ matrix.target }} run: ${{ env.CARGO }} test --verbose ${{ env.TARGET_FLAGS }}
linux: - name: View Target Dir
runs-on: ubuntu-latest run: ls -la ${{ env.TARGET_DIR }}/debug
strategy:
matrix: - name: Retrieve Name of Binary
target: id: upload-artifact
- x86_64-unknown-linux-gnu run: |
- x86_64-unknown-linux-musl if [ "${{ matrix.os }}" == "windows-2022" ]; then
echo "name=${{ env.TARGET_DIR }}/debug/${{ env.BINARY }}.exe" >> $GITHUB_OUTPUT
else
echo "name=${{ env.TARGET_DIR}}/debug/${{ env.BINARY }}" >> $GITHUB_OUTPUT
fi
- name: Upload Binary
uses: actions/upload-artifact@v3
with:
name: ${{ env.BINARY }}-${{ matrix.build }}
path: ${{ steps.upload-artifact.outputs.name }}
rustfmt:
name: rustfmt
runs-on: ubuntu-22.04
steps: steps:
- uses: actions/checkout@v3 - name: Checkout repository
- name: Cache Cargo uses: actions/checkout@v3
uses: actions/cache@v3 - name: Install Rust
uses: dtolnay/rust-toolchain@master
with: with:
path: | toolchain: stable
~/.cargo/registry components: rustfmt
./target - name: Check formatting
# Example key: linux-stable-x86_64-unknown-linux-gnu-3k4j234lksjfd9 run: cargo fmt --all --check
key: linux-stable-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
linux-stable-${{ matrix.target }}-
linux-stable-
linux-
- name: Set Rust Channel
run: rustup default stable
- name: Set Rust Target
run: rustup target add ${{ matrix.target }}
- name: Build
run: cargo build --target ${{ matrix.target }}
- name: Test
run: cargo test --target ${{ matrix.target }}

@ -1,18 +0,0 @@
name: generate-changelog
on:
release:
types: [released]
jobs:
generate-changelog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: BobAnkh/auto-generate-changelog@master
with:
ACCESS_TOKEN: ${{secrets.CHANGELOG}}
PATH: 'CHANGELOG.md'
COMMIT_MESSAGE: 'docs(CHANGELOG): Update release notes'
TYPE: 'feat:Feature,fix:Bug Fixes,docs:Documentation,refactor:Refactor,perf:Performance Improvements,tests:Tests'

@ -1,169 +1,175 @@
name: deploy # Copyright (c) 2023 Hamothy
# Copyright (c) 2015 Andrew Gallant
on:
push: # Permission is hereby granted, free of charge, to any person obtaining a copy
# Sequence of patterns matched against refs/tags # of this software and associated documentation files (the "Software"), to deal
tags: # in the Software without restriction, including without limitation the rights
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
env: # furnished to do so, subject to the following conditions:
bin: git-view
name: release
jobs:
windows: on:
runs-on: windows-latest push:
strategy: tags:
matrix: - "v*"
target:
- x86_64-pc-windows-gnu env:
- x86_64-pc-windows-msvc BINARY: git-view
steps: jobs:
- uses: actions/checkout@v3 build-release:
- name: Cache Cargo runs-on: ${{ matrix.os }}
uses: actions/cache@v3 defaults:
with: run:
path: | shell: bash
~/.cargo/registry env:
./target CARGO: cargo
# Example key: windows-stable-x86_64-pc-windows-gnu-3k4j234lksjfd9 # When CARGO is set to CROSS, this is set to `--target matrix.target`.
key: windows-stable-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} TARGET_FLAGS:
restore-keys: | # When CARGO is set to CROSS, TARGET_DIR includes matrix.target.
windows-stable-${{ matrix.target }}- TARGET_DIR: ./target
windows-stable- # Emit backtraces on panics.
windows- RUST_BACKTRACE: 1
- name: Set Rust Channel strategy:
run: rustup default stable fail-fast: false
shell: bash matrix:
- name: Set Rust Target build:
run: rustup target add ${{ matrix.target }} [linux, linux-gnu, linux-arm, macos, win-msvc, win-gnu, win32-msvc]
shell: bash include:
- name: Build Release Binary - build: linux
run: cargo build --target ${{ matrix.target }} --release os: ubuntu-22.04
shell: bash rust: nightly
- name: Compress Windows Binary target: x86_64-unknown-linux-musl
run: | - build: linux-gnu
cd ./target/${{ matrix.target }}/release/ os: ubuntu-22.04
7z a "${{ env.bin }}-${{ matrix.target }}.zip" "${{ env.bin }}.exe" rust: nightly
mv "${{ env.bin }}-${{ matrix.target }}.zip" $GITHUB_WORKSPACE target: x86_64-unknown-linux-gnu
shell: bash - build: linux-arm
- name: Archive Windows Artifact os: ubuntu-22.04
uses: actions/upload-artifact@v3 rust: nightly
with: target: arm-unknown-linux-gnueabihf
name: Windows - build: macos
path: | os: macos-12
${{ github.workspace }}/${{ env.bin }}-${{ matrix.target }}.zip rust: nightly
target: x86_64-apple-darwin
macos: - build: win-msvc
runs-on: macos-latest os: windows-2022
strategy: rust: nightly
matrix: target: x86_64-pc-windows-msvc
target: - build: win-gnu
- x86_64-apple-darwin os: windows-2022
rust: nightly-x86_64-gnu
steps: target: x86_64-pc-windows-gnu
- uses: actions/checkout@v3 - build: win32-msvc
- name: Cache Cargo os: windows-2022
uses: actions/cache@v3 rust: nightly
with: target: i686-pc-windows-msvc
path: |
~/.cargo/registry steps:
./target - name: Checkout repository
# Example key: macos-stable-x86_64-apple-darwin-3k4j234lksjfd9 uses: actions/checkout@v3
key: macos-stable-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: | - name: Install packages (Ubuntu)
macos-stable-${{ matrix.target }}- if: matrix.os == 'ubuntu-22.04'
macos-stable- run: sudo apt-get update && sudo apt-get install -y --no-install-recommends musl-tools
macos-
- name: Set Rust Channel - name: Install Rust
run: rustup default stable uses: dtolnay/rust-toolchain@master
- name: Set Rust Target with:
run: rustup target add ${{ matrix.target }} toolchain: ${{ matrix.rust }}
- name: Build Release Binary target: ${{ matrix.target }}
run: cargo build --target ${{ matrix.target }} --release
- name: Compress macOS Binary - name: Cache Rust
run: tar -czvf ${{ env.bin }}-${{ matrix.target }}.tar.gz --directory=target/${{ matrix.target }}/release ${{ env.bin }} uses: Swatinem/rust-cache@v2
- name: Archive macOS Artifact with:
uses: actions/upload-artifact@v3 key: ${{ matrix.rust }}
with:
name: macOS - name: Use Cross
path: | if: matrix.os != 'windows-2022'
./${{ env.bin }}-${{ matrix.target }}.tar.gz run: |
cargo install cross
linux: echo "CARGO=cross" >> $GITHUB_ENV
runs-on: ubuntu-latest echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
strategy: echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
matrix:
target: - name: Show command used for Cargo
- x86_64-unknown-linux-gnu run: |
- x86_64-unknown-linux-musl echo "cargo command is: ${{ env.CARGO }}"
echo "target flag is: ${{ env.TARGET_FLAGS }}"
steps: echo "target dir is: ${{ env.TARGET_DIR }}"
- uses: actions/checkout@v3
- name: Cache Cargo - name: Compile
uses: actions/cache@v3 run: ${{ env.CARGO }} build --release --verbose ${{ env.TARGET_FLAGS }}
with:
path: | - name: Strip release binary (linux and macos)
~/.cargo/registry if: matrix.build == 'linux' || matrix.build == 'linux-gnu' || matrix.build == 'macos'
./target run: strip "target/${{ matrix.target }}/release/${{ env.BINARY }}"
# Example key: linux-stable-x86_64-unknown-linux-gnu-3k4j234lksjfd9
key: linux-stable-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} - name: Strip release binary (arm)
restore-keys: | if: matrix.build == 'linux-arm'
linux-stable-${{ matrix.target }}- run: |
linux-stable- docker run --rm -v \
linux- "$PWD/target:/target:Z" \
- name: Set Rust Channel rustembedded/cross:arm-unknown-linux-gnueabihf \
run: rustup default stable arm-linux-gnueabihf-strip \
- name: Set Rust Target /target/arm-unknown-linux-gnueabihf/release/${{ env.BINARY }}
run: rustup target add ${{ matrix.target }}
- name: Build Release Binary - name: Zip Artifact
run: cargo build --target ${{ matrix.target }} --release id: zip-artifact
- name: Compress Linux Binary run: |
run: tar -czvf ${{ env.bin }}-${{ matrix.target }}.tar.gz --directory=target/${{ matrix.target }}/release ${{ env.bin }} staging="${{ env.BINARY }}-${{ matrix.target }}"
- name: Archive Linux Artifact mkdir "$staging"
uses: actions/upload-artifact@v3
with: if [ "${{ matrix.os }}" == "windows-2022" ]; then
name: Linux cp "${{ env.TARGET_DIR }}/release/${{ env.BINARY }}.exe" "$staging/"
path: | 7z a "$staging.zip" "$staging"
./${{ env.bin }}-${{ matrix.target }}.tar.gz echo "asset=$staging.zip" >> $GITHUB_OUTPUT
else
deploy-artifacts: cp "${{ env.TARGET_DIR }}/release/${{ env.BINARY }}" "$staging/"
name: Deploy Artifacts tar czf "$staging.tar.gz" "$staging"
needs: [ windows, macos, linux ] echo "asset=$staging.tar.gz" >> $GITHUB_OUTPUT
runs-on: ubuntu-latest fi
steps: - name: Upload Artifact
- name: Download Artifacts uses: actions/upload-artifact@v3
uses: actions/download-artifact@v3 with:
- name: Display Structure name: ${{ env.BINARY }}-${{ matrix.build }}
run: ls -R path: ${{ steps.zip-artifact.outputs.asset }}
- name: Release
uses: softprops/action-gh-release@v1 create-release:
with: needs: build-release
files: | runs-on: ubuntu-22.04
./Linux/*.tar.gz steps:
./macOS/*.tar.gz - name: Download Artifacts
./Windows/*.zip uses: actions/download-artifact@v3
- name: Display Directory Structure
homebrew: run: ls -R
name: Bump Homebrew Formula - name: Create Release
needs: deploy-artifacts uses: softprops/action-gh-release@v1
runs-on: ubuntu-latest with:
generate_release_notes: true
steps: files: |
- name: Extract Version ./${{ env.BINARY }}-*/*.tar.gz
run: printf "::set-output name=%s::%s\n" tag-name "${GITHUB_REF#refs/tags/}" ./${{ env.BINARY }}-*/*.zip
- uses: mislav/bump-homebrew-formula-action@v2
if: "!contains(github.ref, '-')" # Skip Pre-Releases homebrew:
with: name: Bump Homebrew Formula
create-pullrequest: true needs: create-release
formula-name: ${{ env.bin }} runs-on: ubuntu-22.04
formula-path: Formula/${{ env.bin }}.rb steps:
homebrew-tap: sgoudham/homebrew-tap - uses: mislav/bump-homebrew-formula-action@v2
download-url: https://github.com/sgoudham/${{ env.bin }}/releases/download/${{ steps.extract-version.outputs.tag-name }}/${{ env.bin }}-x86_64-apple-darwin.tar.gz if: !github.event.release.prerelease
commit-message: | with:
{{formulaName}} -> {{version}} create-pullrequest: true
formula-name: ${{ env.BINARY }}
Created by https://github.com/mislav/bump-homebrew-formula-action formula-path: Formula/${{ env.BINARY }}.rb
env: homebrew-tap: sgoudham/homebrew-tap
COMMITTER_TOKEN: ${{ secrets.HOMEBREW }} download-url: https://github.com/sgoudham/${{ env.BINARY }}/releases/download/${{ github.ref_name }}/${{ env.BINARY }}-x86_64-apple-darwin.tar.gz
commit-message: |
{{formulaName}} -> {{version}}
Created by https://github.com/mislav/bump-homebrew-formula-action
env:
COMMITTER_TOKEN: ${{ secrets.HOMEBREW }}

@ -1,4 +1,4 @@
name: bump-homebrew-formula name: Bump Homebrew
on: on:
workflow_dispatch: workflow_dispatch:
Loading…
Cancel
Save