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

Fix tag checkouts #120

Merged
merged 4 commits into from
Oct 12, 2024
Merged

Fix tag checkouts #120

merged 4 commits into from
Oct 12, 2024

Conversation

Johennes
Copy link
Collaborator

@Johennes Johennes commented Oct 9, 2024

Unfortunately dealing with tags and branches in shallow clones turned out more involved than I thought. This change uses git ls-remote to determine the SHA of a branch or tag without fetching the entire history.

In case it helps, I've used the following (dumb) script to test my changes:

#!/usr/bin/env bash

set -e

ubrn=./bin/cli

function clean_up {
  rm -rf rust_modules
}

function announce {
  echo "[TEST] $1"
}

rc=0

function assert_eq {
  if [[ $1 == $2 ]]; then
    echo "✅ OK"
  else
    echo "❌ FAILURE: '$1' != '$2'"
    rc=1
  fi
}

clean_up

announce "checkout with default"
"$ubrn" checkout https://github.com/actions/checkout
pushd rust_modules/checkout
assert_eq $(git ls-remote --heads origin | grep refs/heads/main | cut -f1) $(git rev-parse HEAD)
popd

clean_up

announce "checkout with branch"
"$ubrn" checkout https://github.com/actions/checkout --branch releases/v1
pushd rust_modules/checkout
assert_eq $(git ls-remote --heads origin | grep refs/heads/releases/v1 | cut -f1) $(git rev-parse HEAD)
popd

clean_up

announce "checkout with tag"
"$ubrn" checkout https://github.com/actions/checkout --branch v4.0.0
pushd rust_modules/checkout
assert_eq $(git ls-remote --tags origin | grep refs/tags/v4.0.0 | cut -f1) $(git rev-parse HEAD)
popd

clean_up

announce "checkout with sha"
"$ubrn" checkout https://github.com/actions/checkout --branch c533a0a4cfc4962971818edcfac47a2899e69799
pushd rust_modules/checkout
assert_eq c533a0a4cfc4962971818edcfac47a2899e69799 $(git rev-parse HEAD)
popd

clean_up

announce "update checkout from sha to sha"
"$ubrn" checkout https://github.com/actions/checkout --branch c533a0a4cfc4962971818edcfac47a2899e69799
"$ubrn" checkout https://github.com/actions/checkout --branch 2d7d9f7ff5b310f983d059b68785b3c74d8b8edd
pushd rust_modules/checkout
assert_eq 2d7d9f7ff5b310f983d059b68785b3c74d8b8edd $(git rev-parse HEAD)
popd

clean_up

announce "update checkout from tag to sha"
"$ubrn" checkout https://github.com/actions/checkout --branch v4.0.0
"$ubrn" checkout https://github.com/actions/checkout --branch 2d7d9f7ff5b310f983d059b68785b3c74d8b8edd
pushd rust_modules/checkout
assert_eq 2d7d9f7ff5b310f983d059b68785b3c74d8b8edd $(git rev-parse HEAD)
popd

clean_up

exit $rc

Fixes: #118

@jhugman
Copy link
Owner

jhugman commented Oct 11, 2024

I love this test!

I'm aware that it might not run on CI, but do you think it would be worth putting it in the scripts directory?

@jhugman jhugman self-requested a review October 11, 2024 10:27
Copy link
Owner

@jhugman jhugman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks just fine to me, and the tests! pass!. Thank you so much for that test file!

I have added one suggestion, and ✅ approved this. Thank you @Johennes !

crates/ubrn_cli/src/repo.rs Outdated Show resolved Hide resolved
@Johennes
Copy link
Collaborator Author

I love this test!

I'm aware that it might not run on CI, but do you think it would be worth putting it in the scripts directory?

I wasn't sure how soon your testing project would land, so I didn't add it to the PR in an attempt not to interfere with that. If it's not around the corner, I can definitely add the script to the folder. I can also add it to the integration tests in the GitHub workflow. I believe GitHub acts upon shell exit codes, so it might even run as is.

@Johennes Johennes requested a review from jhugman October 11, 2024 14:16
@jhugman jhugman merged commit 2c0c8c9 into jhugman:main Oct 12, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Updating a tag checkout is broken
2 participants