Skip to content

Commit

Permalink
refactor: apply review
Browse files Browse the repository at this point in the history
 rename get_crate_version to get_crate_latest_version
  • Loading branch information
kazuk committed May 17, 2022
1 parent c7d5162 commit 15adc1c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Expand Up @@ -86,7 +86,7 @@ jobs:
# load helper script
source .github/workflows/scripts/crates.io-script.bash
# get latest version from crates.io
echo "::set-output name=cargo-deny_version::$(get_crate_version cargo-deny)"
echo "::set-output name=cargo-deny_version::$(get_crate_latest_version cargo-deny)"
# add other dependencies versions here
- name: Install Rust ${{ matrix.rust }}
Expand Down Expand Up @@ -121,7 +121,7 @@ jobs:
key: ${{env.CACHE_RESET_KEY}}-${{ runner.os }}-${{ matrix.rust }}-cargo-deny-${{ steps.dep-versions.outputs.cargo-deny_version }}

- name: Install cargo-deny
if: ${{ steps.cache-cargo-deny.outputs.cache-hit == false && matrix.rust == 'stable' }}
if: ${{ steps.cache-cargo-deny.outputs.cache-hit == false && matrix.rust == 'stable'}}
run: |
cargo install cargo-deny
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/scripts/crates.io-script.bash
@@ -1,5 +1,13 @@
function get_crate_version() {

# function: get_crate_latest_version
# arg#1: crate name
# returns: latest version number on crates.io
#
# this calls crates.io REST api via curl, that listing all versions of specified crate.
# `jq` query filter for not yanked and extract version number.
# sort semver and takes last one.
function get_crate_latest_version() {
curl -L https://crates.io/api/v1/crates/$1/versions | jq -r '.versions[] | select( .yanked == false) | .num' | sort --version-sort | tail -n 1
}

export -f get_crate_version
export -f get_crate_latest_version

0 comments on commit 15adc1c

Please sign in to comment.