Skip to content

Commit

Permalink
build: new approach
Browse files Browse the repository at this point in the history
  • Loading branch information
azzamsa committed Jun 22, 2023
1 parent 95329b5 commit a168547
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 120 deletions.
2 changes: 0 additions & 2 deletions .cargo-husky/hooks/pre-commit

This file was deleted.

14 changes: 9 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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,6 +47,8 @@ jobs:
with:
toolchain: ${{ env.MIN_SUPPORTED_RUST_VERSION }}

- uses: Swatinem/rust-cache@v2

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

Expand Down Expand Up @@ -82,6 +86,11 @@ jobs:
with:
target: ${{ matrix.target }}

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

- name: Show version information
shell: bash
run: |
Expand All @@ -99,10 +108,5 @@ 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 }}
91 changes: 72 additions & 19 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,55 @@ on:
tags:
- 'v*'

env:
BIN_NAME: bilal

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:
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 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.BIN_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-2019" ]; then
cp "target/${{ matrix.target }}/release/${{ env.BIN_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/"
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: bilal-${{ 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: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ version = "0.3.17"
features = ["formatting", "local-offset"]

[dev-dependencies]
cargo-husky = { version = "1", features = ["user-hooks"] }

assert_cmd = "2.0"
predicates = "2.1"

[package.metadata.binstall]
pkg-url = "{ repo }/releases/download/v{ version }/{ name }-{ version}-{ target }.tar.gz"
bin-dir = "{ bin }{ binary-ext }"
pkg-fmt = "tgz"

[package.metadata.release]
tag-message = "For details, see the CHANGELOG.md"
pre-release-commit-message = "v{{version}}"
pre-release-hook = ["just", "_prepare-release", "{{version}}"]
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 bilal 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>`.
49 changes: 34 additions & 15 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 @@ -11,15 +9,14 @@ _default:

# 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 the development tools.
_setup-dev:
cargo install --locked cargo-nextest git-cliff cargo-watch dprint cargo-edit cargo-outdated spacer

# 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 Down Expand Up @@ -54,16 +51,38 @@ check: fmt-check lint test
doc:
cargo doc --open

# Create a new release. Example `just release v2.2.0`
release version:
bash scripts/release.sh {{ version }}
# 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:
just up
cargo-release release {{ level }}

# Release hooks
_prepare-release 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 ( "{{ arg }}" -eq "--write") {
cargo upgrade
cargo update
}
else {
cargo outdated --root-deps-only
}
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.

30 changes: 0 additions & 30 deletions scripts/release.sh

This file was deleted.

0 comments on commit a168547

Please sign in to comment.