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