Skip to content

Commit

Permalink
Use nurl for hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
oscar-izval committed Jan 9, 2025
1 parent 8784b92 commit 2591867
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
31 changes: 20 additions & 11 deletions cli/cmd/updateVersions.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ var updateVersionsCmd = &cobra.Command{

func updateVersions(token string, versionsPath string, vendorHashPath string, minVersion *semver.Version, maxVersion *semver.Version) error {
nixPrefetchPath, err := exec.LookPath("nix-prefetch")
nurlPath, err := exec.LookPath("nurl")
if err != nil {
return fmt.Errorf("nix-prefetch not found: %w", err)
}
Expand All @@ -102,7 +103,7 @@ func updateVersions(token string, versionsPath string, vendorHashPath string, mi
log.Printf("Version %s found in file\n", version)
} else {
log.Printf("Computing hashes for %s\n", version)
hash, err := computeHash(nixPrefetchPath, tagName)
hash, err := computeHash(nurlPath, tagName)
if err != nil {
return fmt.Errorf("Unable to compute hash: %w", err)
}
Expand Down Expand Up @@ -177,16 +178,12 @@ func withReleases(token string, f func(release *github.RepositoryRelease) error)
return nil
}

func computeHash(nixPrefetchPath string, tagName string) (string, error) {
hash, err := runNixPrefetch(
nixPrefetchPath,
"fetchFromGitHub",
"--owner",
owner,
"--repo",
repo,
"--rev",
tagName)
func computeHash(nurlPath string, tagName string) (string, error) {
hash, err := runNurl(
nurlPath,
"https://github.com/hashicorp/terraform",
tagName,
"--hash")
if err != nil {
return "", err
}
Expand Down Expand Up @@ -221,6 +218,18 @@ func runNixPrefetch(nixPrefetchPath string, extraArgs ...string) (string, error)
return strings.TrimRight(string(output), "\n"), nil
}

func runNurl(nurlPath string, args ...string) (string, error) {
cmd := exec.Command(nurlPath, args...)
cmd.Stderr = log.Writer()

output, err := cmd.Output()
if err != nil {
return "", err
}

return strings.TrimSpace(string(output)), nil
}

func init() {
rootCmd.AddCommand(updateVersionsCmd)

Expand Down
1 change: 1 addition & 0 deletions cli/devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
packages = [
pkgs.cobra-cli
pkgs.nix-prefetch
pkgs.nurl
];

languages.go.enable = true;
Expand Down
6 changes: 5 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@
"hash": "sha256-KY18YFTKWj366CPTh1MJ9DLamiFUVql3BhuMUzN7zf8=",
"vendorHash": "sha256-AajBuUwOhK0OniRRfCqR89+mA9LnQBkbG3Xge9c0qSQ="
},
"1.10.4": {
"hash": "sha256-wJg/BfKWgDzv9HKOsNaq+l2jG37VbOtmBF+QEhNLQ1k=",
"vendorHash": "sha256-YFsPxDlD7SqHo0x2UQnsJ5jDTp2JXdhEgDvtIpWVQ9o="
},
"1.2.0": {
"hash": "sha256-5um+zS7MVL59SlxchjXdlhBGNdacbQgvg7BRAWnW5XU=",
"vendorHash": "sha256-6x1cv+DKXH2yyMjIA6JY5EkTmWbwH4LBammXKtw2EZo="
Expand Down Expand Up @@ -368,7 +372,7 @@
"latest": {
"1.0": "1.0.11",
"1.1": "1.1.9",
"1.10": "1.10.3",
"1.10": "1.10.4",
"1.2": "1.2.9",
"1.3": "1.3.10",
"1.4": "1.4.7",
Expand Down

0 comments on commit 2591867

Please sign in to comment.