features
features copied to clipboard
github-cli: simplify logic for detecting available gh releases
This change relies on git ls-remote --tags --sort=version:refname
to sort git versions in a semver-compatible mode and alleviate the need to scan for version numbers manually. The new approach selects at most two latest releases that match VERSION and installs the first .deb
that was successfully downloaded from a GitHub CLI release.
This also removes support for installing a specific version number with apt-get install gh=VERSION
, since the GitHub CLI package repository does not retain older gh versions and only allows installing the latest one.
Finally, this removes version-selecting tests that only tested an implementation that was entirely contained within tests.
Bonuses:
- Only install curl, apt-transport-https, dirmngr, gnupg2 when needed (the default installDirectlyFromGitHubRelease mode does not need them).
- Ensure
apt-get update
runs at most once. - Remove the side-effect of
/var/lib/apt/lists
being wiped out when the github-cli feature is activated. - Add ability to export bash functions for testing:
TEST_EXPORT=find_version_from_git_tags ./src/github-cli/install.sh
- Errors are printed to stderr.
Followup to https://github.com/devcontainers/features/pull/310
/cc @samruddhikhandale: I thought I'd take a stab at reducing the size of the implementation so that the github-cli feature is easier to maintain over time. I hope this can be useful! 🙇
Looking at the CI failure: it looks like the git version on Bionic is too old to support the --sort=version:refname
option. I'll update the PR to achieve semantic version sorting differently than relying on this git feature.
Hi @mislav 👋
This PR would be super useful and will improve the current Feature. Let me know if I could somehow help to push it through. thanks!
@samruddhikhandale Thanks; I intend to finish this PR soon by addressing review comments.
- [ ] Address case where git is old (Bionic)
- [ ] Restore apt-get cleanup step (for consistency with other features in this repo)
- [ ] Add more scenarios to tests
- [ ] Remove TEST_EXPORT hack (since we will be using scenarios for integration testing)
Thanks for all your guidance @samruddhikhandale, but I'm going to close this because it's no longer needed. In GitHub CLI we've just changed our deployment process so that release assets are published at the same time as the git tag itself. Therefore, there isn't a period of time anymore where a git tag exists but the assets do not exist, so there is no need for a fallback mechanism to select the previous git tag.
Nice, that's awesome. Thank you for the update!