From dc909e20ad0ea0d4afd95b53a428a1161839a756 Mon Sep 17 00:00:00 2001 From: sevki Date: Sun, 10 Nov 2024 01:30:00 +0000 Subject: [PATCH] feat: add as ref support --- .github/workflows/publish.yml | 18 ----------- .github/workflows/release-please.yml | 45 +++++++++++++++++++++++----- .github/workflows/rust.yml | 2 +- Cargo.lock | 20 ++++++------- src/lib.rs | 13 ++++++-- 5 files changed, 60 insertions(+), 38 deletions(-) delete mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index c8f9836..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Publish Crate -on: - push: - tags: - - '*' - -jobs: - create-release: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - uses: katyo/publish-crates@v2 - with: - registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index d19edf3..5385c3f 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -1,18 +1,49 @@ -name: Release Please - -on: - push: - branches: - - main +name: Release Please🙏! permissions: contents: write pull-requests: write +on: + push: + branches: + - main jobs: release-please: runs-on: ubuntu-latest steps: - - uses: google-github-actions/release-please-action@v4 + - uses: googleapis/release-please-action@v4 + id: release with: + config-file: release-please-config.json + # optional. customize path to .release-please-manifest.json + manifest-file: .release-please-manifest.json + target-branch: ${{ github.ref_name }} release-type: rust + - uses: actions/checkout@v4 + - name: tag major and minor versions + if: ${{ steps.release.outputs.release_created }} + run: | + git config user.name github-actions[bot] + git config user.email 41898282+github-actions[bot]@users.noreply.github.com + git remote add gh-token "https://${{ secrets.GITHUB_TOKEN }}@github.com/google-github-actions/release-please-action.git" + git tag -d v${{ steps.release.outputs.major }} || true + git tag -d v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true + git push origin :v${{ steps.release.outputs.major }} || true + git push origin :v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true + git tag -a v${{ steps.release.outputs.major }} -m "Release v${{ steps.release.outputs.major }}" + git tag -a v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} -m "Release v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}" + git push origin v${{ steps.release.outputs.major }} + git push origin v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} + - name: checkout rs + uses: actions-rs/toolchain@v1 + if: ${{ steps.release.outputs.release_created }} + with: + toolchain: stable + override: true + + - name: publish to crates.io + if: ${{ steps.release.outputs.release_created }} + uses: katyo/publish-crates@v2 + with: + registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 464d816..804df2b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -18,4 +18,4 @@ jobs: - name: Build run: cargo build --verbose - name: Run tests - run: cargo test --verbose + run: cargo test --verbose --all-features diff --git a/Cargo.lock b/Cargo.lock index 26e3003..8f580ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -246,9 +246,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.36" +version = "1.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baee610e9452a8f6f0a1b6194ec09ff9e2d85dea54432acdae41aa0761c95d70" +checksum = "40545c26d092346d8a8dab71ee48e7685a7a9cba76e634790c215b41a4a7b4cf" dependencies = [ "jobserver", "libc", @@ -499,9 +499,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" +checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" [[package]] name = "fastvlq" @@ -941,9 +941,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jetstream_derive" -version = "6.0.0" +version = "6.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ca131815a3997c4fdab189d39190549146a5085d47d9170d167af27acf60e45" +checksum = "6a025ff541282664925d3393d525a9b5fe7166fd19d618c25e63974d6bb0e4f3" dependencies = [ "convert_case", "paste", @@ -955,9 +955,9 @@ dependencies = [ [[package]] name = "jetstream_wireformat" -version = "6.0.0" +version = "6.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39de40a2f04a9f15c0d3facf619fc982b4017f9d8b13795d5bd342680bac66e0" +checksum = "92732e4869ef2604aa0f9427b80a6545857e80c001959849ef7f7c1201ebf0cb" dependencies = [ "bytes", "futures", @@ -1654,9 +1654,9 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.13.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" +checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" dependencies = [ "cfg-if", "fastrand", diff --git a/src/lib.rs b/src/lib.rs index 711f4f5..b299eb6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -540,6 +540,15 @@ impl jetstream_wireformat::WireFormat for OkId { } } +impl std::convert::AsRef<[u8]> for OkId { + fn as_ref(&self) -> &[u8] { + let fmtd = self.to_string(); + let bytes = fmtd.as_bytes(); + // SAFETY: the bytes are from a string, which is guaranteed to be valid utf8 + unsafe { std::slice::from_raw_parts(bytes.as_ptr(), bytes.len()) } + } +} + #[cfg(test)] mod okid_tests { @@ -786,8 +795,8 @@ mod okid_tests { let chunk = Chunk(1, binary_id); let chunk_map = ChunkMap(vec![chunk]); let file = File(binary_id, chunk_map); - let mut byts = file.to_bytes(); - let new_file = File::from_bytes(&mut byts).unwrap(); + let byts = file.to_bytes(); + let new_file = File::from_bytes(&byts).unwrap(); let mut _reader = std::io::Cursor::new(byts); assert_eq!(file, new_file);