From 5129b96f2f05907647251c0d46880141f9c25578 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 2 Sep 2024 19:40:33 -0700 Subject: [PATCH] Release 0.0.1 (#3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Bump version: 0.0.0 → 0.0.1 - Update changelog - Update changelog contributor credits - Update dependencies - Add release recipes to justfile - Add release workflow - Add package script --- .github/workflows/ci.yaml | 6 +- .github/workflows/release.yaml | 118 +++++++++++++++++++++++++ .gitignore | 1 + CHANGELOG.md | 11 +++ Cargo.lock | 9 +- Cargo.toml | 5 +- README.md | 17 ++++ bin/package | 54 +++++++++++ crates/update-contributors/Cargo.toml | 8 ++ crates/update-contributors/src/main.rs | 40 +++++++++ justfile | 28 +++++- 11 files changed, 288 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/release.yaml create mode 100644 CHANGELOG.md create mode 100755 bin/package create mode 100644 crates/update-contributors/Cargo.toml create mode 100644 crates/update-contributors/src/main.rs diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7b31d96..eb8d447 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,10 +32,10 @@ jobs: - uses: Swatinem/rust-cache@v2 - name: Clippy - run: cargo clippy --all-targets + run: cargo clippy --workspace --all-targets - name: Format - run: cargo fmt -- --check + run: cargo fmt --all -- --check - name: Check for Forbidden Words run: | @@ -64,4 +64,4 @@ jobs: - uses: Swatinem/rust-cache@v2 - name: Test - run: cargo test + run: cargo test --workspace diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..431e5ef --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,118 @@ +name: Release + +permissions: + contents: write + +on: + push: + tags: + - '*' + +defaults: + run: + shell: bash + +jobs: + release: + strategy: + matrix: + target: + - aarch64-apple-darwin + - aarch64-pc-windows-msvc + - aarch64-unknown-linux-musl + - arm-unknown-linux-musleabihf + - armv7-unknown-linux-musleabihf + - x86_64-apple-darwin + - x86_64-pc-windows-msvc + - x86_64-unknown-linux-musl + include: + - target: aarch64-apple-darwin + os: macos-latest + target_rustflags: '' + - target: aarch64-pc-windows-msvc + os: windows-latest + target_rustflags: '' + - target: aarch64-unknown-linux-musl + os: ubuntu-latest + target_rustflags: '--codegen linker=aarch64-linux-gnu-gcc' + - target: arm-unknown-linux-musleabihf + os: ubuntu-latest + target_rustflags: '--codegen linker=arm-linux-gnueabihf-gcc' + - target: armv7-unknown-linux-musleabihf + os: ubuntu-latest + target_rustflags: '--codegen linker=arm-linux-gnueabihf-gcc' + - target: x86_64-apple-darwin + os: macos-latest + target_rustflags: '' + - target: x86_64-pc-windows-msvc + os: windows-latest + - target: x86_64-unknown-linux-musl + os: ubuntu-latest + target_rustflags: '' + + runs-on: ${{matrix.os}} + + steps: + - uses: actions/checkout@v4 + + - name: Install AArch64 Toolchain + if: ${{ matrix.target == 'aarch64-unknown-linux-musl' }} + run: | + sudo apt-get update + sudo apt-get install gcc-aarch64-linux-gnu libc6-dev-i386 + + - name: Install ARM Toolchain + if: ${{ matrix.target == 'arm-unknown-linux-musleabihf' || matrix.target == 'armv7-unknown-linux-musleabihf' }} + run: | + sudo apt-get update + sudo apt-get install gcc-arm-linux-gnueabihf + + - name: Install AArch64 Toolchain (Windows) + if: ${{ matrix.target == 'aarch64-pc-windows-msvc' }} + run: | + rustup target add aarch64-pc-windows-msvc + + - name: Release Type + id: release-type + run: | + if [[ ${{ github.ref }} =~ ^refs/tags/[0-9]+[.][0-9]+[.][0-9]+$ ]]; then + echo ::set-output name=value::release + else + echo ::set-output name=value::prerelease + fi + + - name: Package + id: package + env: + TARGET: ${{ matrix.target }} + REF: ${{ github.ref }} + OS: ${{ matrix.os }} + TARGET_RUSTFLAGS: ${{ matrix.target_rustflags }} + run: ./bin/package + shell: bash + + - name: Publish Archive + uses: softprops/action-gh-release@v2.0.8 + if: ${{ startsWith(github.ref, 'refs/tags/') }} + with: + draft: false + files: | + ${{ steps.package.outputs.archive }} + ${{ steps.package.outputs.archive }}.sha256sum + prerelease: ${{ steps.release-type.outputs.value == 'prerelease' }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish Changelog + uses: softprops/action-gh-release@v2.0.8 + if: >- + ${{ + startsWith(github.ref, 'refs/tags/') + && matrix.target == 'x86_64-unknown-linux-musl' + }} + with: + draft: false + files: CHANGELOG.md + prerelease: ${{ steps.ref-type.outputs.value != 'release' }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index ea8c4bf..787aa48 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +/tmp diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..328a73b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +Changelog +========= + +[0.0.1](https://github.com/casey/filepack/releases/tag/0.0.1) - 2024-09-02 +-------------------------------------------------------------------------- + +### Added +- Add create and verify subcommands ([#2](https://github.com/casey/filepack/pull/2) by [casey](https://github.com/casey)) + +### Misc +- Initialize rust binary ([#1](https://github.com/casey/filepack/pull/1) by [casey](https://github.com/casey)) diff --git a/Cargo.lock b/Cargo.lock index 995be93..4a77102 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -273,7 +273,7 @@ checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" [[package]] name = "filepack" -version = "0.0.0" +version = "0.0.1" dependencies = [ "assert_cmd", "assert_fs", @@ -605,6 +605,13 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "update-contributors" +version = "0.0.0" +dependencies = [ + "regex", +] + [[package]] name = "utf8parse" version = "0.2.2" diff --git a/Cargo.toml b/Cargo.toml index 8b02fa3..c698a46 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "filepack" -version = "0.0.0" +version = "0.0.1" authors = ["Casey Rodarmor "] autotests = false description = "🗄️ file verification utility" @@ -30,6 +30,9 @@ pedantic = { level = "deny", priority = -1 } result-large-err = "allow" wildcard_imports = "allow" +[workspace] +members = [".", "crates/*"] + [[test]] name = "integration" path = "tests/lib.rs" diff --git a/README.md b/README.md index 775aef7..af903c0 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,20 @@ in a manifest file named `filepack.json`. Files can later be verified against the hashes saved in the manifest to protect against accidental or malicious corruption, as long as the manifest has not been tampered with. + +New Releases +------------ + +New releases of `filepack` are made frequently so that users quickly get access to +new features. + +Release commit messages use the following template: + +``` +Release x.y.z + +- Bump version: x.y.z → x.y.z +- Update changelog +- Update changelog contributor credits +- Update dependencies +``` diff --git a/bin/package b/bin/package new file mode 100755 index 0000000..becd56b --- /dev/null +++ b/bin/package @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +set -euxo pipefail + +VERSION=${REF#"refs/tags/"} +DIST=`pwd`/dist + +echo "Packaging filepack $VERSION for $TARGET..." + +test -f Cargo.lock || cargo generate-lockfile + +echo "Installing rust toolchain for $TARGET..." +rustup target add $TARGET + +if [[ $TARGET == aarch64-unknown-linux-musl ]]; then + export CC=aarch64-linux-gnu-gcc +fi + +echo "Building filepack..." +RUSTFLAGS="--deny warnings --codegen target-feature=+crt-static $TARGET_RUSTFLAGS" \ + cargo build --bin filepack --target $TARGET --release +EXECUTABLE=target/$TARGET/release/filepack + +if [[ $OS == windows-latest ]]; then + EXECUTABLE=$EXECUTABLE.exe +fi + +echo "Copying release files..." +mkdir dist +cp -r \ + $EXECUTABLE \ + Cargo.lock \ + Cargo.toml \ + LICENSE \ + CONTRIBUTING \ + README.md \ + $DIST + +cd $DIST +echo "Creating release archive..." +case $OS in + ubuntu-latest | macos-latest) + ARCHIVE=$DIST/filepack-$VERSION-$TARGET.tar.gz + tar czf $ARCHIVE * + echo "archive=$ARCHIVE" >> $GITHUB_OUTPUT + shasum -a 256 $ARCHIVE > $ARCHIVE.sha256sum + ;; + windows-latest) + ARCHIVE=$DIST/filepack-$VERSION-$TARGET.zip + 7z a $ARCHIVE * + echo "archive=`pwd -W`/filepack-$VERSION-$TARGET.zip" >> $GITHUB_OUTPUT + sha256sum $ARCHIVE > $ARCHIVE.sha256sum + ;; +esac diff --git a/crates/update-contributors/Cargo.toml b/crates/update-contributors/Cargo.toml new file mode 100644 index 0000000..b9bd769 --- /dev/null +++ b/crates/update-contributors/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "update-contributors" +version = "0.0.0" +edition = "2021" +publish = false + +[dependencies] +regex = "1.5.4" diff --git a/crates/update-contributors/src/main.rs b/crates/update-contributors/src/main.rs new file mode 100644 index 0000000..3cd9702 --- /dev/null +++ b/crates/update-contributors/src/main.rs @@ -0,0 +1,40 @@ +use { + regex::{Captures, Regex}, + std::{fs, process::Command, str}, +}; + +fn author(pr: u64) -> String { + eprintln!("#{pr}"); + let output = Command::new("sh") + .args([ + "-c", + &format!("gh pr view {pr} --json author | jq -r .author.login"), + ]) + .output() + .unwrap(); + + assert!( + output.status.success(), + "{}", + String::from_utf8_lossy(&output.stderr) + ); + + str::from_utf8(&output.stdout).unwrap().trim().to_owned() +} + +fn main() { + fs::write( + "CHANGELOG.md", + &*Regex::new(r"\(#(\d+)( by @[a-z]+)?\)") + .unwrap() + .replace_all( + &fs::read_to_string("CHANGELOG.md").unwrap(), + |captures: &Captures| { + let pr = captures[1].parse().unwrap(); + let contributor = author(pr); + format!("([#{pr}](https://github.com/casey/filepack/pull/{pr}) by [{contributor}](https://github.com/{contributor}))") + }, + ), + ) + .unwrap(); +} diff --git a/justfile b/justfile index c220eba..d084e11 100644 --- a/justfile +++ b/justfile @@ -2,19 +2,39 @@ watch +args='test': cargo watch --clear --exec '{{ args }}' ci: lint - cargo test + cargo test --workspace lint: - cargo clippy --all-targets -- --deny warnings + cargo clippy --workspace --all-targets -- --deny warnings ./bin/forbid cargo fmt --all -- --check outdated: - cargo outdated --root-deps-only + cargo outdated --workspace --root-deps-only unused: - cargo +nightly udeps + cargo +nightly udeps --workspace coverage: cargo llvm-cov --html open target/llvm-cov/html/index.html + +update-changelog: + echo >> CHANGELOG.md + git log --pretty='format:- %s' >> CHANGELOG.md + +update-contributors: + cargo run --release --package update-contributors + +publish: + #!/usr/bin/env bash + set -euxo pipefail + rm -rf tmp/release + git clone git@github.com:casey/filepack.git tmp/release + cd tmp/release + VERSION=`sed -En 's/version[[:space:]]*=[[:space:]]*"([^"]+)"/\1/p' Cargo.toml | head -1` + git tag -a $VERSION -m "Release $VERSION" + git push origin $VERSION + cargo publish + cd ../.. + rm -rf tmp/release