Skip to content

Commit

Permalink
refactor: new workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
azzamsa committed Jul 22, 2023
1 parent c088095 commit 7b4ef4e
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 58 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CI

env:
MIN_SUPPORTED_RUST_VERSION: "1.66.0"
MIN_SUPPORTED_RUST_VERSION: "1.70.0"

on: [push, pull_request]

Expand Down Expand Up @@ -49,12 +49,11 @@ jobs:

- uses: Swatinem/rust-cache@v2

- name: Install latest nextest release
uses: taiki-e/install-action@nextest

- name: Install latest just release
uses: taiki-e/install-action@just

- uses: taiki-e/install-action@nextest

- name: Prepare config
run: |
mkdir -p tests/.config/bilal
Expand Down Expand Up @@ -86,10 +85,7 @@ jobs:
with:
target: ${{ matrix.target }}

- name: Rust cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.os }}-${{ matrix.target }}
- uses: Swatinem/rust-cache@v2

- name: Show version information
shell: bash
Expand All @@ -108,5 +104,10 @@ jobs:
sudo apt-get install -y --no-install-recommends \
--allow-unauthenticated musl-tools
- name: Rust cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.os }}-${{ matrix.target }}

- name: Build
run: cargo build --release --locked --target ${{ matrix.target }}
28 changes: 14 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'v*'

env:
BIN_NAME: bilal
APP_NAME: tin

jobs:
create-github-release:
Expand Down Expand Up @@ -36,7 +36,7 @@ jobs:
id: git-cliff
with:
config: configs/cliff.toml
args: -vv --strip header --current
args: -vv --strip header --current
env:
OUTPUT: CHANGELOG.md.tmp

Expand All @@ -46,11 +46,11 @@ jobs:
- name: Release
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.GH_TOKEN }}
name: "v${{ env.RELEASE_VERSION }}"
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') }}
generate_release_notes: true
body_path: "${{ steps.git-cliff.outputs.changelog }}"
token: ${{ secrets.GH_TOKEN }}

publish:
name: Publish
Expand All @@ -59,12 +59,12 @@ jobs:
fail-fast: false
matrix:
include:
- { build: linux-gnu, os: ubuntu-22.04, target: x86_64-unknown-linux-gnu }
- { build: linux-musl, os: ubuntu-22.04, target: x86_64-unknown-linux-musl }
- { build: win-gnu, os: windows-2022, target: x86_64-pc-windows-gnu }
- { build: win-msvc, os: windows-2022, target: x86_64-pc-windows-msvc }
- { build: win32-msvc, os: windows-2022, target: i686-pc-windows-msvc }
- { build: macos, os: macos-12 , target: x86_64-apple-darwin }
- { build: linux-gnu, os: ubuntu-22.04, target: x86_64-unknown-linux-gnu }
- { build: linux-musl, os: ubuntu-22.04, target: x86_64-unknown-linux-musl }
- { build: win-gnu, os: windows-2022, target: x86_64-pc-windows-gnu }
- { build: win-msvc, os: windows-2022, target: x86_64-pc-windows-msvc }
- { build: win32-msvc, os: windows-2022, target: i686-pc-windows-msvc }
- { build: macos, os: macos-12, target: x86_64-apple-darwin }

steps:
- name: Checkout
Expand Down Expand Up @@ -95,19 +95,19 @@ jobs:
shell: bash
run: |
outdir="./target/release"
staging="${{ env.BIN_NAME }}-${{ env.RELEASE_VERSION }}-${{ matrix.target }}"
staging="${{ env.APP_NAME }}-${{ env.RELEASE_VERSION }}-${{ matrix.target }}"
mkdir -p "$staging"/{complete,doc}
mkdir -p "$staging"/doc
cp -r {README.md,LICENSE*} "$staging/"
cp -r {CHANGELOG.md,docs/*} "$staging/doc/"
if [ "${{ matrix.os }}" = "windows-2019" ]; then
cp "target/${{ matrix.target }}/release/${{ env.BIN_NAME }}.exe" "$staging/"
if [[ "${{ matrix.os }}" =~ ^windows-.*$ ]]; then
cp "target/${{ matrix.target }}/release/${{ env.APP_NAME }}.exe" "$staging/"
cd "$staging"
7z a "../$staging.zip" .
echo "ASSET=$staging.zip" >> $GITHUB_ENV
else
cp "target/${{ matrix.target }}/release/${{ env.BIN_NAME }}" "$staging/"
cp "target/${{ matrix.target }}/release/${{ env.APP_NAME }}" "$staging/"
tar czf "$staging.tar.gz" -C "$staging" .
echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV
fi
Expand Down
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ bin-dir = "{ bin }{ binary-ext }"
pkg-fmt = "tgz"

[package.metadata.release]
tag-message = "For details, see the CHANGELOG.md"
sign-commit = true
sign-tag = true
tag-message = "v{{version}}"
pre-release-commit-message = "v{{version}}"
pre-release-hook = ["just", "_prepare-release", "{{version}}"]
pre-release-hook = ["just", "_release-prepare", "{{version}}"]
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.66.0"
msrv = "1.70.0"
23 changes: 13 additions & 10 deletions configs/cliff.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# configuration file for git-cliff (0.1.0)

[changelog]
# changelog header
header = """
# Changelog
All notable changes to this project will be documented in this file.\n
"""
# template for the changelog body
Expand All @@ -19,14 +16,20 @@ body = """
### {{ group | striptags | trim | upper_first }}
{% for commit in commits %}
{%- if commit.scope -%}
- **{{commit.scope}}:** {{ commit.message | upper_first }} ([{{ commit.id | truncate(length=7, end="") }}]({{ commit.id }}))
- **{{ commit.scope }}:** {{ commit.message | upper_first }} ([{{ commit.id | truncate(length=7, end="") }}](https://github.com/azzamsa/bilal/commit/{{ commit.id }}))
{% if commit.breaking -%}
{% raw %} {% endraw %}- **BREAKING!** ⚠️ : {{commit.breaking_description}}
{% raw %} {% endraw %}- **BREAKING!** ⚠️ : {{ commit.breaking_description }}
{% endif -%}
{% if commit.body -%}
{% raw %}\n{% endraw %}{% raw %} {% endraw %}{{ commit.body | indent(width=4) }}{% raw %}\n{% endraw %}
{% endif -%}
{% else -%}
- {{ commit.message | upper_first }} ([{{ commit.id | truncate(length=7, end="") }}]({{ commit.id }}))
- {{ commit.message | upper_first }} ([{{ commit.id | truncate(length=7, end="") }}](https://github.com/azzamsa/bilal/commit/{{ commit.id }}))
{% if commit.breaking -%}
{% raw %} {% endraw %}- **BREAKING!** ⚠️ : {{commit.breaking_description}}
{% raw %} {% endraw %}- **BREAKING!** ⚠️ : {{ commit.breaking_description }}
{% endif -%}
{% if commit.body -%}
{% raw %}\n{% endraw %}{% raw %} {% endraw %}{{ commit.body | indent(width=4) }}{% raw %}\n{% endraw %}
{% endif -%}
{% endif -%}
{% endfor -%}
Expand All @@ -44,9 +47,9 @@ footer = """"""
conventional_commits = true
# regex for parsing and grouping commits
commit_parsers = [
{ message = "^feat*", group = "<!-- 1 -->Features" },
{ message = "^fix*", group = "<!-- 2 -->Bug fixes" },
{ message = "^perf*", group = "<!-- 3 -->Performance" },
{ message = "^feat*", group = "<!-- 0 -->Features" },
{ message = "^fix*", group = "<!-- 1 -->Bug fixes" },
{ message = "^perf*", group = "<!-- 2 -->Performance" },
]
# filter out the commits that are not matched by commit parsers
filter_commits = true
Expand Down
75 changes: 52 additions & 23 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ _default:
just --list --unsorted

# Setup the repository.
setup:
setup: _areyousure
just _cargo-install 'cargo-edit cargo-nextest cargo-outdated cargo-watch dprint git-cliff spacer'

# Setup the development tools.
_setup-dev:
cargo install --locked cargo-nextest git-cliff cargo-watch dprint cargo-edit cargo-outdated spacer
# Tasks to make the code-base comply with the rules. Mostly used in git hooks.
comply: _doc-check fmt lint test

# Check if the repository comply with the rules and ready to be pushed.
check: fmt-check lint test

# Develop the app.
dev:
Expand All @@ -28,40 +31,34 @@ fmt-check:
cargo fmt --all -- --check
dprint check --config configs/dprint.json

# Lint the docstring.
_lint_doc:
cargo doc --all-features --no-deps

# Lint the codebase.
lint:
cargo clippy

# Test the codebase.
test:
test: test-unit
cargo test --doc
cargo nextest run

# Tasks to make the code-base comply with the rules. Mostly used in git hooks.
comply: fmt lint _lint_doc test

# Check if the repository comply with the rules and ready to be pushed.
check: fmt-check lint test

# Open documentation.
doc:
cargo doc --open
# Test unit tests only
test-unit:
cargo nextest run --lib

# Create a new release. Example `cargo-release release minor --tag-name v0.2.0`
release level:
cargo-release release {{ level }} --execute

# Make sure the repo is ready for release
_release-check level:
release-check level:
just up
cargo-release release {{ level }}

# Lint the docstring.
_doc-check:
cargo doc --all-features --no-deps

# Release hooks
_prepare-release version:
_release-prepare version:
git-cliff --config configs/cliff.toml --output CHANGELOG.md --tag {{ version }}
just fmt

Expand All @@ -70,19 +67,51 @@ _prepare-release version:
up arg="":
#!/usr/bin/env bash
if [ "{{ arg }}" = "--write" ]; then
cargo upgrade
cargo update
cargo upgrade && cargo update
else
cargo outdated --root-deps-only
fi;

[windows]
up arg="":
#!powershell.exe
if ( "{{ arg }}" -eq "--write") {
if ( "tool" -eq "--write") {
cargo upgrade
cargo update
}
else {
cargo outdated --root-deps-only
}

#
# Helper
#

[unix]
_cargo-install tool:
#!/usr/bin/env bash
if command -v cargo-binstall >/dev/null 2>&1; then
echo "cargo-binstall..."
cargo binstall --no-confirm --no-symlinks {{ tool }}
else
echo "Building from source"
cargo install --locked {{ tool }}
fi

[unix]
_areyousure:
#!/usr/bin/env bash
echo -e "This command will alter your system. ⚠️
You are advised to run in inside containerized environment.
Such as [toolbx](https://containertoolbx.org/).
If you are unsure. Run the installation commands manually.
Take a look at the 'setup' recipe in the Justfile.\n"

read -p "Are you sure you want to proceed? (Y/n) " response;
if [[ $response =~ ^[Yy] ]]; then
echo "Continue!";
else
echo "Cancelled!";
exit 1;
fi

0 comments on commit 7b4ef4e

Please sign in to comment.