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

[WIP] Use nurl to fix update script #103

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Build

on:
pull_request:
branches: [main]
# pull_request:
# branches: [main]
push:
branches: [main]

Expand All @@ -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
- name: Install devenv
run: |
nix profile install --accept-flake-config nixpkgs#devenv
Expand Down
39 changes: 20 additions & 19 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name: Update

on:
push:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"
Expand All @@ -17,11 +18,11 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: main
ref: oi/fix-update-ci
- 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
- name: Install devenv
run: |
nix profile install --accept-flake-config nixpkgs#devenv
Expand All @@ -34,22 +35,22 @@ jobs:
env:
CLI_GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
working-directory: cli
- name: Create pull request
uses: peter-evans/create-pull-request@v7
with:
author: GitHub <[email protected]>
commit-message: Update Terraform versions
title: "feat: Update Terraform versions"
body: |
Automatically created pull-request to update Terraform versions.
# - name: Create pull request
# uses: peter-evans/create-pull-request@v7
# with:
# author: GitHub <[email protected]>
# commit-message: Update Terraform versions
# title: "feat: Update Terraform versions"
# body: |
# Automatically created pull-request to update Terraform versions.

This is the result of configuring a CLI_GITHUB_TOKEN in `.env` and running:
# This is the result of configuring a CLI_GITHUB_TOKEN in `.env` and running:

```
cli update-versions
```
delete-branch: true
reviewers: |
oscar-izval
sestrella
token: ${{ secrets.BOT_TOKEN }}
# ```
# cli update-versions
# ```
# delete-branch: true
# reviewers: |
# oscar-izval
# sestrella
# token: ${{ secrets.BOT_TOKEN }}
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,
fmt.Sprintf("https://github.com/%s/%s", owner, repo),
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
40 changes: 12 additions & 28 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": 1736426010,
"owner": "cachix",
"repo": "devenv",
"rev": "a520f05c40ebecaf5e17064b27e28ba8e70c49fb",
"rev": "1c384bc4be3ee571511fbbc6fdc94fe47d60f6cf",
"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 Down Expand Up @@ -53,30 +53,15 @@
},
"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": 1736200483,
"owner": "nixos",
"repo": "nixpkgs",
"rev": "6f6076c37180ea3a916f84928cf3a714c5207a30",
"rev": "3f0a8ac25fb674611b98089ca3a5dd6480175751",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.05",
"owner": "nixos",
"ref": "nixos-24.11",
"repo": "nixpkgs",
"type": "github"
}
Expand All @@ -87,14 +72,13 @@
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
]
},
"locked": {
"lastModified": 1732021966,
"lastModified": 1735882644,
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "3308484d1a443fc5bc92012435d79e80458fe43c",
"rev": "a5a961387e75ae44cc20f0a57ae463da5e959656",
"type": "github"
},
"original": {
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
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
40 changes: 12 additions & 28 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": 1736426010,
"owner": "cachix",
"repo": "devenv",
"rev": "a520f05c40ebecaf5e17064b27e28ba8e70c49fb",
"rev": "1c384bc4be3ee571511fbbc6fdc94fe47d60f6cf",
"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 Down Expand Up @@ -53,30 +53,15 @@
},
"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": 1736200483,
"owner": "nixos",
"repo": "nixpkgs",
"rev": "6f6076c37180ea3a916f84928cf3a714c5207a30",
"rev": "3f0a8ac25fb674611b98089ca3a5dd6480175751",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.05",
"owner": "nixos",
"ref": "nixos-24.11",
"repo": "nixpkgs",
"type": "github"
}
Expand All @@ -87,14 +72,13 @@
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
]
},
"locked": {
"lastModified": 1732021966,
"lastModified": 1735882644,
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "3308484d1a443fc5bc92012435d79e80458fe43c",
"rev": "a5a961387e75ae44cc20f0a57ae463da5e959656",
"type": "github"
},
"original": {
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
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
Loading