Skip to content

Commit

Permalink
ci: Fix the update script (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
oscar-izval authored Feb 14, 2025
1 parent cb096e4 commit 49bd7c1
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install Nix
uses: cachix/install-nix-action@v30
with:
nix_path: nixpkgs=channel:nixos-24.05-small
nix_path: nixpkgs=channel:nixos-24.11-small
- name: Install devenv
run: |
nix profile install --accept-flake-config nixpkgs#devenv
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ concurrency:

jobs:
update:
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -21,7 +21,7 @@ jobs:
- name: Install Nix
uses: cachix/install-nix-action@v30
with:
nix_path: nixpkgs=channel:nixos-24.05-small
nix_path: nixpkgs=channel:nixos-24.11-small
- name: Install devenv
run: |
nix profile install --accept-flake-config nixpkgs#devenv
Expand Down
42 changes: 29 additions & 13 deletions cli/cmd/updateVersions.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ func updateVersions(token string, versionsPath string, vendorHashPath string, mi
return fmt.Errorf("nix-prefetch not found: %w", err)
}

nixBinaryPath, err := exec.LookPath("nix")
if err != nil {
return fmt.Errorf("nix not found: %w", err)
}

versions, err := readVersions(versionsPath)
if err != nil {
return err
Expand All @@ -102,7 +107,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(nixBinaryPath, tagName)
if err != nil {
return fmt.Errorf("Unable to compute hash: %w", err)
}
Expand Down Expand Up @@ -177,20 +182,31 @@ 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(nixBinaryPath string, tagName string) (string, error) {
cmd := exec.Command(
nixBinaryPath, "flake", "prefetch",
"--extra-experimental-features", "nix-command flakes",
"--json", fmt.Sprintf("github:%s/%s/%s", owner, repo, tagName),
)

// Redirect stderr to the standard logger
cmd.Stderr = log.Writer()

// Get the output
output, err := cmd.Output()
if err != nil {
return "", err
return "", fmt.Errorf("command execution failed: %w", err)
}

// Parse JSON output to get hash
var result struct {
Hash string `json:"hash"`
}
if err := json.Unmarshal(output, &result); err != nil {
return "", fmt.Errorf("failed to parse JSON output: %w", err)
}
return hash, nil

return result.Hash, nil
}

func computeVendorHash(nixPrefetchPath string, vendorHashFile string, version *semver.Version, hash string) (string, error) {
Expand Down
18 changes: 9 additions & 9 deletions cli/devenv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"devenv": {
"locked": {
"dir": "src/modules",
"lastModified": 1732585607,
"lastModified": 1739444039,
"owner": "cachix",
"repo": "devenv",
"rev": "a520f05c40ebecaf5e17064b27e28ba8e70c49fb",
"rev": "1235cd13f47df6ad19c8a183c6eabc1facb7c399",
"type": "github"
},
"original": {
Expand Down Expand Up @@ -74,16 +74,16 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1716977621,
"owner": "cachix",
"repo": "devenv-nixpkgs",
"rev": "4267e705586473d3e5c8d50299e71503f16a6fb6",
"lastModified": 1739461644,
"owner": "nixos",
"repo": "nixpkgs",
"rev": "97a719c9f0a07923c957cf51b20b329f9fb9d43f",
"type": "github"
},
"original": {
"owner": "cachix",
"ref": "rolling",
"repo": "devenv-nixpkgs",
"owner": "nixos",
"ref": "nixos-24.11-small",
"repo": "nixpkgs",
"type": "github"
}
},
Expand Down
2 changes: 1 addition & 1 deletion cli/devenv.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
inputs:
nixpkgs:
url: github:cachix/devenv-nixpkgs/rolling
url: github:nixos/nixpkgs/nixos-24.11-small
83 changes: 35 additions & 48 deletions devenv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"devenv": {
"locked": {
"dir": "src/modules",
"lastModified": 1732585607,
"lastModified": 1739444039,
"owner": "cachix",
"repo": "devenv",
"rev": "a520f05c40ebecaf5e17064b27e28ba8e70c49fb",
"rev": "1235cd13f47df6ad19c8a183c6eabc1facb7c399",
"type": "github"
},
"original": {
Expand All @@ -19,10 +19,10 @@
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1732722421,
"lastModified": 1733328505,
"owner": "edolstra",
"repo": "flake-compat",
"rev": "9ed2ac151eada2306ca8c418ebd97807bb08f6ac",
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
"type": "github"
},
"original": {
Expand All @@ -31,10 +31,31 @@
"type": "github"
}
},
"git-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1737465171,
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "9364dc02281ce2d37a1f55b6e51f7c0f65a75f17",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "git-hooks.nix",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"git-hooks",
"nixpkgs"
]
},
Expand All @@ -53,61 +74,27 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1716977621,
"owner": "cachix",
"repo": "devenv-nixpkgs",
"rev": "4267e705586473d3e5c8d50299e71503f16a6fb6",
"type": "github"
},
"original": {
"owner": "cachix",
"ref": "rolling",
"repo": "devenv-nixpkgs",
"type": "github"
}
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1732632634,
"owner": "NixOS",
"lastModified": 1739461644,
"owner": "nixos",
"repo": "nixpkgs",
"rev": "6f6076c37180ea3a916f84928cf3a714c5207a30",
"rev": "97a719c9f0a07923c957cf51b20b329f9fb9d43f",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.05",
"owner": "nixos",
"ref": "nixos-24.11-small",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1732021966,
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "3308484d1a443fc5bc92012435d79e80458fe43c",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"devenv": "devenv",
"git-hooks": "git-hooks",
"nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks"
"pre-commit-hooks": [
"git-hooks"
]
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion devenv.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
inputs:
nixpkgs:
url: github:cachix/devenv-nixpkgs/rolling
url: github:nixos/nixpkgs/nixos-24.11-small

0 comments on commit 49bd7c1

Please sign in to comment.