From e870b964971bde038fe548b66fa859a959fa0044 Mon Sep 17 00:00:00 2001 From: azzamsa Date: Sat, 22 Jul 2023 11:13:31 +0700 Subject: [PATCH] refactor: new workflow --- .github/workflows/ci.yaml | 11 +++- .github/workflows/release.yaml | 91 +++++++++++++++++++++++------ Cargo.lock | 7 --- Cargo.toml | 7 +++ clippy.toml | 2 +- docs/dev/releasing.md | 15 +---- justfile | 104 ++++++++++++++++++++++++--------- scripts/compress-assets.sh | 12 ---- scripts/prepare-assets.sh | 15 ----- scripts/release.sh | 30 ---------- 10 files changed, 166 insertions(+), 128 deletions(-) mode change 100644 => 100755 justfile delete mode 100755 scripts/compress-assets.sh delete mode 100755 scripts/prepare-assets.sh delete mode 100755 scripts/release.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d6da9cc..4520fdf 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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] @@ -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 @@ -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 @@ -77,6 +80,8 @@ jobs: with: target: ${{ matrix.target }} + - uses: Swatinem/rust-cache@v2 + - name: Show version information shell: bash run: | diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f81a9c5..3dcb7ce 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -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 @@ -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 @@ -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 diff --git a/Cargo.lock b/Cargo.lock index d2dfecb..8629627 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -139,12 +139,6 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be0fdd54b507df8f22012890aadd099979befdba27713c767993f8380112ca7c" -[[package]] -name = "cargo-husky" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b02b629252fe8ef6460461409564e2c21d0c8e77e0944f3d189ff06c4e932ad" - [[package]] name = "cc" version = "1.0.79" @@ -402,7 +396,6 @@ version = "0.3.0" dependencies = [ "assert_cmd", "assert_fs", - "cargo-husky", "clap 4.1.8", "full_moon", "miette", diff --git a/Cargo.toml b/Cargo.toml index 4c49be9..01643dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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}}"] diff --git a/clippy.toml b/clippy.toml index 1877592..1645c19 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1 @@ -msrv = "1.68.0" +msrv = "1.70.0" diff --git a/docs/dev/releasing.md b/docs/dev/releasing.md index fcf04f8..3895a07 100644 --- a/docs/dev/releasing.md +++ b/docs/dev/releasing.md @@ -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`. 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 `. Such as `just release-check minor`. +- If everything is okay, Run `just release `. diff --git a/justfile b/justfile old mode 100644 new mode 100755 index 7e216eb..a2c3ef6 --- a/justfile +++ b/justfile @@ -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 @@ -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: @@ -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 diff --git a/scripts/compress-assets.sh b/scripts/compress-assets.sh deleted file mode 100755 index 686c140..0000000 --- a/scripts/compress-assets.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -OS="$1" -TARGET="$2" -RELEASE_VERSION="$3" - -if [ "$OS" = "windows-2022" ]; then - 7z a -tzip "gelatyx-$RELEASE_VERSION-$TARGET.zip" gelatyx-"$RELEASE_VERSION"/ -else - tar -czvf gelatyx-"$RELEASE_VERSION"-"$TARGET".tar.gz gelatyx-"$RELEASE_VERSION"/ - shasum -a 512 gelatyx-"$RELEASE_VERSION"-"$TARGET".tar.gz >gelatyx-"$RELEASE_VERSION"-"$TARGET".tar.gz.sha512 -fi diff --git a/scripts/prepare-assets.sh b/scripts/prepare-assets.sh deleted file mode 100755 index b2675d3..0000000 --- a/scripts/prepare-assets.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash - -OS="$1" -TARGET="$2" -RELEASE_VERSION="$3" - -TARGET_DIR=gelatyx-"$RELEASE_VERSION"/ - -mkdir "$TARGET_DIR" - -bin="gelatyx" -if [ "$OS" = "windows-2022" ]; then - bin="gelatyx.exe" -fi -cp "target/$TARGET/release/$bin" "$TARGET_DIR" diff --git a/scripts/release.sh b/scripts/release.sh deleted file mode 100755 index bcf866f..0000000 --- a/scripts/release.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash - -untracked_files=$(git ls-files . --exclude-standard --others) - -# check for untracked files -if [ -n "$untracked_files" ]; then - echo "warn: Please stash or remove the untracked files" - exit 1 -fi - -# if tag is not passed -if [ -z "$1" ]; then - echo "warn: Please provide a tag" - exit 1 -fi - -# takes the tag as an argument (e.g. v0.1.0) -# update the version -new_version=${1#v} # strip the `v` prefix -cargo set-version "$new_version" - -# update the changelog -git-cliff --tag "$1" --config configs/cliff.toml >CHANGELOG.md -# format newly added changelog file -just fmt - -git add --all && git commit --message="$1" -git show -git tag --sign --annotate "$1" --message="$1" --message="For details, see the CHANGELOG.md" -git tag --verify "$1"