Skip to content

Commit

Permalink
🏭 Setup to create binaries (#29)
Browse files Browse the repository at this point in the history
- 🧹  Move migrations to runtime for binaries.
- ✨  Add install script for Mac and linux binaries.
- 🏭  Use "cross" to test and build binaries in the pipeline.
- πŸ›  Use "dunce" to support windows absolute paths.
- πŸ§ͺ  Update tests.
- πŸ”§  (WIP) homebrew template
  • Loading branch information
xsv24 authored Apr 15, 2023
1 parent 58e4f7d commit 83416f8
Show file tree
Hide file tree
Showing 16 changed files with 774 additions and 174 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/cargo-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: πŸ¦€ Cargo Publish

on:
workflow_call:
inputs:
version:
required: false
type: string

dry-run:
required: true
type: boolean
default: true

jobs:
dry-run:
if: inputs.dry-run
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cargo toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Cargo build
uses: actions-rs/cargo@v1
with:
command: build

- name: Cargo publish dry-run
uses: actions-rs/cargo@v1
with:
command: publish
args: --dry-run

publish:
if: inputs.dry-run != true
runs-on: ubuntu-latest
env:
CARGO_TOKEN: ${{ secrets.CARGO_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cargo toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Cargo release build
uses: actions-rs/cargo@v1
with:
# Allows us to use the git tag version as the package version
command: install
args: cargo-release

- name: Update Cargo.toml version
run: |
cargo release version ${{ inputs.version }} --no-confirm --execute
# Publish and allow dirty since the Cargo.toml version is changed.
- name: Publish package
run: cargo publish --token "$CARGO_TOKEN" --allow-dirty
71 changes: 68 additions & 3 deletions .github/workflows/commit.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
on: [push]
name: πŸ§ͺ Commit

name: Commit CI
on:
pull_request:
push:
branches:
- master

jobs:
check:
Expand Down Expand Up @@ -63,4 +67,65 @@ jobs:
with:
command: test
args: -- --show-output
needs: [check, fmt, clippy]

os-test:
needs: [check, fmt, clippy, test]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
# List of OS versions https://github.com/actions/runner-images
include:
- build: linux-x86
os: ubuntu-22.04
target: x86_64-unknown-linux-musl

- build: linux-i686
os: ubuntu-22.04
target: i686-unknown-linux-musl

- build: linux-aarch64
os: ubuntu-22.04
target: aarch64-unknown-linux-musl

- build: linux-arm
os: ubuntu-22.04
target: arm-unknown-linux-gnueabihf

- build: macos-x86
os: macos-12
target: x86_64-apple-darwin

- build: win-msvc
os: windows-2022
target: x86_64-pc-windows-msvc

- build: win32-msvc
os: windows-2022
target: i686-pc-windows-msvc

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install ${{ matrix.target }} toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.target }}
override: true

- name: Cross Tests
uses: actions-rs/cargo@v1
env:
RUST_BACKTRACE: 1
BUILD_DISABLED: "true" # Disable the "build.rs" file from running
with:
use-cross: true
command: test
args: --target=${{ matrix.target }}

cargo-check:
uses: xsv24/git-kit/.github/workflows/cargo-publish.yml@binary-relase
with:
dry-run: true
182 changes: 141 additions & 41 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,59 +1,159 @@
name: πŸš€ Release

on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
- "[0-9]+.[0-9]+.[0-9]+-pre[0-9]+"

name: Release and publish
env:
BIN_NAME: git-kit

jobs:
build:
github-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
- name: Environment variables
run: |
echo "TAG=$(echo $GITHUB_REF | cut -d '/' -f 3)" >> $GITHUB_ENV
echo "version is: ${{ env.TAG }}"
- name: Create GitHub release
id: release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
command: build
tag_name: ${{ env.TAG }}
release_name: ${{ env.TAG }}
outputs:
upload_url: ${{ steps.release.outputs.upload_url }}
version: ${{ env.TAG }}

cargo:
needs: ["github-release"]
uses: xsv24/git-kit/.github/workflows/cargo-publish.yml@binary-relase
with:
version: ${{ needs.github-release.version }}
dry-run: false

build:
name: Build
runs-on: ${{ matrix.os }}
needs: ["github-release"]
strategy:
fail-fast: true
matrix:
build: [
linux-x86,
linux-i686,
linux-aarch64,
linux-arm,
macos-x86,
macos-arm,
win-msvc,
win32-msvc,
# win-gnu,
]
# List of OS versions https://github.com/actions/runner-images
include:
- build: linux-x86
os: ubuntu-22.04
target: x86_64-unknown-linux-musl

- build: linux-i686
os: ubuntu-22.04
target: i686-unknown-linux-musl

- build: linux-aarch64
os: ubuntu-22.04
target: aarch64-unknown-linux-musl

- build: linux-arm
os: ubuntu-22.04
target: arm-unknown-linux-gnueabihf

- build:
os: ubuntu-22.04
target: x86_64-unknown-freebsd

- build: macos-x86
os: macos-12
target: x86_64-apple-darwin

- build: macos-arm
os: macos-12
target: aarch64-apple-darwin

- build: win-msvc
os: windows-2022
target: x86_64-pc-windows-msvc

- build: win32-msvc
os: windows-2022
target: i686-pc-windows-msvc

# - build: win-gnu
# os: windows-2022
# target: x86_64-pc-windows-gnu

publish-dry:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
- name: Checkout
uses: actions/checkout@v2

- name: Install ${{ matrix.target }} toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: ${{ matrix.target }}
override: true
- uses: actions-rs/cargo@v1

- name: Build release binary
uses: actions-rs/cargo@v1
env:
BUILD_DISABLED: "true" # Disable the "build.rs" file from running
with:
command: publish
args: --dry-run
use-cross: true
command: build
args: --verbose --release --target=${{ matrix.target }}

publish:
runs-on: ubuntu-latest
env:
CARGO_TOKEN: ${{ secrets.CARGO_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
- name: Strip release binary (linux-x86 and macos)
if: matrix.build == 'linux-x86' || matrix.build == 'macos-x86' || matrix.build == 'macos-arm'
run: strip "target/${{ matrix.target }}/release/$BIN_NAME"

- name: Strip release binary (linux-arm)
if: matrix.build == 'linux-arm'
run: |
sudo apt-get install -y binutils-arm-linux-gnueabihf
arm-linux-gnueabihf-strip target/arm-unknown-linux-gnueabihf/release/$BIN_NAME
- name: Build archive
shell: bash
run: |
compressed="git-kit-${{ matrix.target }}"
mkdir $compressed
cp {README.md,LICENSE,templates/conventional.yml,templates/default.yml} "$compressed/"
if [ "${{ matrix.os }}" = "windows-2022" ]; then
cp "target/${{ matrix.target }}/release/$BIN_NAME.exe" "$compressed/"
7z a "$compressed.zip" "$compressed"
echo "ASSET=$compressed.zip" >> $GITHUB_ENV
else
cp "target/${{ matrix.target }}/release/$BIN_NAME" "$compressed/"
tar czf "$compressed.tar.gz" "$compressed"
echo "ASSET=$compressed.tar.gz" >> $GITHUB_ENV
fi
- uses: actions/[email protected]
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
name: bins-${{ matrix.build }}
path: ${{ env.ASSET }}

- name: Upload release archive
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# Allows us to use the git tag version as the package version
command: install
args: cargo-release
- name: Update Cargo.toml version
run: |
TAG_VERSION=$(echo $GITHUB_REF | cut -d '/' -f 3)
cargo release version "$TAG_VERSION" --no-confirm --execute
# Publish and allow dirty since the Cargo.toml version is changed.
- name: Publish package
run: cargo publish --token "$CARGO_TOKEN" --allow-dirty
needs: [build, publish-dry]
upload_url: ${{ needs.github-release.outputs.upload_url }}
asset_path: ${{ env.ASSET }}
asset_name: ${{ env.ASSET }}
asset_content_type: application/octet-stream
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ build = "build.rs"
anyhow = "1.0"
colored = "2"
clap = { version = "3.2.17", features = ["derive"] }
dunce = "1.0.3"
inquire = "0.5.2"
log = "0.4.17"
env_logger = "0.9.3"
Expand All @@ -34,9 +35,11 @@ uuid = { version = "1.1.2", features = [ "v4" ] }

[dev-dependencies]
fake = { version = "2.5.0" }
lazy_static = "1.4.0"

[build-dependencies]
anyhow = "1.0"
directories = { version = "4.0.1" }
log = "0.4.17"
rusqlite = { version = "0.28.0", features = ["bundled"] }
rusqlite_migration = "1.0.1"
5 changes: 5 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[build.env]
passthrough = [
"BUILD_DISABLED",
"RUST_LOG"
]
Loading

0 comments on commit 83416f8

Please sign in to comment.