Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Refactor version comparison logic in check_versions job #307

Closed
joshlf opened this issue Sep 2, 2023 · 0 comments · Fixed by #581
Closed

[CI] Refactor version comparison logic in check_versions job #307

joshlf opened this issue Sep 2, 2023 · 0 comments · Fixed by #581
Labels
compatibility-nonbreaking Changes that are (likely to be) non-breaking experience-medium This issue is of medium difficulty, and requires some experience help wanted Extra attention is needed

Comments

@joshlf
Copy link
Member

joshlf commented Sep 2, 2023

In CI, we have the following job:

check_versions:
needs: generate_cache
runs-on: ubuntu-latest
name: Check crate versions match
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- uses: actions/cache@v3
with:
path: |
~/.cargo/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
# Make sure that both crates are at the same version, and that zerocopy
# depends exactly upon the current version of zerocopy-derive. See
# `INTERNAL.md` for an explanation of why we do this.
- name: Check crate versions match
run: |
set -eo pipefail
# Usage: version <crate-name>
function version {
cargo metadata --format-version 1 | jq -r ".packages[] | select(.name == \"$1\").version"
}
ver_zerocopy=$(version zerocopy)
ver_zerocopy_derive=$(version zerocopy-derive)
# The non-dev dependency version (`.kind == null` filters out the dev
# dependency, and `.target == null` filters out the targeted version).
zerocopy_derive_dep_ver=$(cargo metadata --format-version 1 \
| jq -r ".packages[] | select(.name == \"zerocopy\").dependencies[] | select((.name == \"zerocopy-derive\") and .kind == null and .target == null).req")
# The non-dev dependency, targeted version.
zerocopy_derive_targeted_ver=$(cargo metadata --format-version 1 \
| jq -r ".packages[] | select(.name == \"zerocopy\").dependencies[] | select((.name == \"zerocopy-derive\") and .kind == null and .target == \"cfg(any())\").req")
# The dev dependency version (`.kind == \"dev\"` selects only the dev
# dependency).
zerocopy_derive_dev_dep_ver=$(cargo metadata --format-version 1 \
| jq -r ".packages[] | select(.name == \"zerocopy\").dependencies[] | select((.name == \"zerocopy-derive\") and .kind == \"dev\").req")
if [[ "$ver_zerocopy" == "$ver_zerocopy_derive" ]]; then
echo "Same crate version ($ver_zerocopy) found for zerocopy and zerocopy-derive." | tee -a $GITHUB_STEP_SUMMARY
else
echo "Different crate versions found for zerocopy ($ver_zerocopy) and zerocopy-derive ($ver_zerocopy_derive)." \
| tee -a $GITHUB_STEP_SUMMARY >&2
exit 1
fi
# Note the leading `=` sign - the dependency needs to be an exact one.
if [[ "=$ver_zerocopy_derive" == "$zerocopy_derive_dep_ver" ]]; then
echo "zerocopy depends upon same version of zerocopy-derive in-tree ($zerocopy_derive_dep_ver)." | tee -a $GITHUB_STEP_SUMMARY
else
echo "zerocopy depends upon different version of zerocopy-derive ($zerocopy_derive_dep_ver) than the one in-tree ($ver_zerocopy_derive)." \
| tee -a $GITHUB_STEP_SUMMARY >&2
exit 1
fi
if [[ "=$ver_zerocopy_derive" == "$zerocopy_derive_dev_dep_ver" ]]; then
echo "In dev mode, zerocopy depends upon same version of zerocopy-derive in-tree ($zerocopy_derive_dev_dep_ver)." | tee -a $GITHUB_STEP_SUMMARY
else
echo "In dev mode, zerocopy depends upon different version of zerocopy-derive ($zerocopy_derive_dev_dep_ver) than the one in-tree ($ver_zerocopy_derive)." \
| tee -a $GITHUB_STEP_SUMMARY >&2
exit 1
fi
if [[ "$zerocopy_derive_dep_ver" == "$zerocopy_derive_targeted_ver" ]]; then
echo "Same crate version ($zerocopy_derive_dep_ver) found for optional and targeted zerocopy-derive dependency." \
| tee -a $GITHUB_STEP_SUMMARY
else
echo "Different crate versions found for optional ($zerocopy_derive_dep_ver) and targeted ($zerocopy_derive_targeted_ver) dependency." \
| tee -a $GITHUB_STEP_SUMMARY >&2
exit 1
fi

Over time, it has grown to contain a lot of duplicated code. The task for this issue is to deduplicate where it makes sense to do so using whatever techniques are appropriate (e.g., bash functions, etc).

@joshlf joshlf added help wanted Extra attention is needed experience-medium This issue is of medium difficulty, and requires some experience compatibility-nonbreaking Changes that are (likely to be) non-breaking labels Sep 2, 2023
@joshlf joshlf changed the title Refactor version comparison logic in check_versions CI job [CI] Refactor version comparison logic in check_versions job Sep 6, 2023
joshlf added a commit that referenced this issue Nov 1, 2023
Deduplicate some logic.

Closes #307
github-merge-queue bot pushed a commit that referenced this issue Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility-nonbreaking Changes that are (likely to be) non-breaking experience-medium This issue is of medium difficulty, and requires some experience help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant