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 3268707 commit e870b96
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 128 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CI

env:
MIN_SUPPORTED_RUST_VERSION: "1.68.0"
MIN_SUPPORTED_RUST_VERSION: "1.70.0"

on: [push, pull_request]

Expand All @@ -18,6 +18,8 @@ jobs:
with:
components: clippy, rustfmt

- uses: Swatinem/rust-cache@v2

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

Expand Down Expand Up @@ -45,12 +47,13 @@ jobs:
with:
toolchain: ${{ env.MIN_SUPPORTED_RUST_VERSION }}

- name: Install latest nextest release
uses: taiki-e/install-action@nextest
- uses: Swatinem/rust-cache@v2

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

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

- name: Run tests
run: just test

Expand All @@ -77,6 +80,8 @@ jobs:
with:
target: ${{ matrix.target }}

- uses: Swatinem/rust-cache@v2

- name: Show version information
shell: bash
run: |
Expand Down
91 changes: 72 additions & 19 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,55 @@ on:
tags:
- 'v*'

env:
APP_NAME: gelatyx

jobs:
create-github-release:
name: Create GitHub Release
runs-on: ubuntu-22.04
steps:

- name: Checkout
uses: actions/checkout@v3
with:
# it is a must!
fetch-depth: 0

- name: Set the release version
shell: bash
run: |
echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV
echo ${{ env.RELEASE_VERSION }}
- name: Checkout current tag
shell: bash
run: |
git checkout v${{ env.RELEASE_VERSION }}
- name: Generate a changelog
uses: orhun/git-cliff-action@v2
id: git-cliff
with:
config: configs/cliff.toml
args: -vv --strip header --current
env:
OUTPUT: CHANGELOG.md.tmp

- name: Print the changelog
run: cat "${{ steps.git-cliff.outputs.changelog }}"

- 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 }}"

publish:
name: Publish for ${{ matrix.build }}
name: Publish
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -25,12 +71,9 @@ jobs:
uses: actions/checkout@v3

- name: Set the release version
shell: bash
run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV

- name: Show release version
shell: bash
run: |
echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV
echo ${{ env.RELEASE_VERSION }}
- name: Install musl-tools
Expand All @@ -48,22 +91,32 @@ jobs:
- name: Build
run: cargo build --release --locked --target ${{ matrix.target }}

- name: Prepare release assets
- name: Build archive
shell: bash
run: |
./scripts/prepare-assets.sh ${{ matrix.os }} ${{ matrix.target }} ${{ env.RELEASE_VERSION }}
outdir="./target/release"
staging="${{ env.APP_NAME }}-${{ env.RELEASE_VERSION }}-${{ matrix.target }}"
- name: Create release artifacts
shell: bash
run: |
./scripts/compress-assets.sh ${{ matrix.os }} ${{ matrix.target }} ${{ env.RELEASE_VERSION }}
mkdir -p "$staging"/{complete,doc}
cp -r {README.md,LICENSE*} "$staging/"
cp -r {CHANGELOG.md,docs/*} "$staging/doc/"
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.APP_NAME }}" "$staging/"
tar czf "$staging.tar.gz" -C "$staging" .
echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV
fi
- name: Upload the release
uses: svenstaro/upload-release-action@v2
- name: Release
uses: softprops/action-gh-release@v1
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: gelatyx-${{ env.RELEASE_VERSION }}-${{ matrix.target }}*
file_glob: true
overwrite: true
tag: ${{ github.ref }}
release_name: "v${{ env.RELEASE_VERSION }}"
token: ${{ secrets.GH_TOKEN }}
name: "v${{ env.RELEASE_VERSION }}"
files: ${{ env.ASSET }}
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') }}
generate_release_notes: false
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,10 @@ predicates = "2.1"
pkg-url = "{ repo }/releases/download/v{ version }/{ name }-{ version}-{ target }.tar.gz"
bin-dir = "{ bin }{ binary-ext }"
pkg-fmt = "tgz"

[package.metadata.release]
sign-commit = true
sign-tag = true
tag-message = "v{{version}}"
pre-release-commit-message = "v{{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.68.0"
msrv = "1.70.0"
15 changes: 2 additions & 13 deletions docs/dev/releasing.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
## Release Checklist

- Ensure local `master` is up to date to `origin/master`.
- Run `just up` to check outdated dependencies. Run `just up --write` and review dependency updates.
Commit updated `Cargo` files.
- Run `just check`. To make sure that everything is ok.
- Run the release task `just release v<major.minor.path>`. Such `just release v0.1.7`.
- **Push the release commit to GitHub**, NOT including the tag. (But do not publish a new version of gelatyx to crates.io yet.)
- Once CI for `master` finishes successfully, **push the version tag**.
(Trying to do this in one step seems to result in GitHub Actions not seeing the tag
push and thus not run the release workflow.)
- Wait for CI to finish creating the release. If the release build fails, then
delete the tag from GitHub, make fixes, re-tag, delete the release, and push.
- Copy the relevant section of the CHANGELOG.md to the tagged release notes.
- Run `cargo publish`.
- Run `just release-check <level>`. Such as `just release-check minor`.
- If everything is okay, Run `just release <level>`.
104 changes: 76 additions & 28 deletions justfile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env -S just --justfile

shebang := if os() == 'windows' { 'powershell.exe' } else { '/usr/bin/sh' }

alias d := dev
alias t := test

Expand All @@ -10,16 +8,18 @@ _default:
just --list --unsorted

# Setup the repository.
setup:
git cliff --version || cargo install --locked git-cliff
cargo nextest --version || cargo install --locked cargo-nextest
cargo-set-version --help || cargo install --locked cargo-edit
cargo watch --version || cargo install --locked cargo-watch
dprint --version || cargo install --locked dprint
setup: _areyousure
just _cargo-install 'cargo-edit cargo-nextest cargo-outdated cargo-watch dprint git-cliff 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:
cargo watch -x 'clippy --all-targets --all-features'
cargo watch -x 'clippy --all-targets --all-features' | spacer

# Format the codebase.
fmt:
Expand All @@ -31,39 +31,87 @@ 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
# Test unit tests only
test-unit:
cargo nextest run --lib

# Check if the repository comply with the rules and ready to be pushed.
check: fmt-check lint test
# Create a new release. Example `cargo-release release minor --tag-name v0.2.0`
release level:
cargo-release release {{ level }} --execute

# Open documentation.
doc:
cargo doc --open
# Make sure the repo is ready for release
release-check level:
just up
cargo-release release {{ level }}

# Create a new release. Example `just release v2.2.0`
release version:
bash scripts/release.sh {{ version }}
# Lint the docstring.
_doc-check:
cargo doc --all-features --no-deps

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

# Check dependencies health. Pass `--write` to uppgrade dependencies.
[unix]
up arg="":
#!{{ shebang }}
#!/usr/bin/env bash
if [ "{{ arg }}" = "--write" ]; then
cargo upgrade
cargo update
cargo upgrade && cargo update
else
cargo outdated
cargo outdated --root-deps-only
fi;

[windows]
up arg="":
#!powershell.exe
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
12 changes: 0 additions & 12 deletions scripts/compress-assets.sh

This file was deleted.

15 changes: 0 additions & 15 deletions scripts/prepare-assets.sh

This file was deleted.

0 comments on commit e870b96

Please sign in to comment.