-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #263 from budimanjojo/extensions
feat(validate): validate supported extensions properly
- Loading branch information
Showing
7 changed files
with
935 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
name: Update Extensions schema | ||
on: | ||
workflow_dispatch: {} | ||
schedule: | ||
- cron: "0 0 * * *" | ||
jobs: | ||
update-json-schema: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: stable | ||
- uses: actions/checkout@v4 | ||
- run: | | ||
cd hack/version-schema-gen | ||
go run main.go ../../pkg/config/schemas/extensions-version-schema.json | ||
- name: Generate token | ||
uses: tibdex/github-app-token@v2 | ||
id: generate-token | ||
with: | ||
app_id: "${{ secrets.BOT_APP_ID }}" | ||
private_key: "${{ secrets.BOT_APP_PRIVATE_KEY }}" | ||
|
||
- name: Create Pull Request | ||
uses: peter-evans/create-pull-request@v5 | ||
id: cpr | ||
with: | ||
token: "${{ steps.generate-token.outputs.token }}" | ||
title: "chore(schema): update extensions-version-schema.yaml JSON schema" | ||
commit-message: "chore(schema): update extensions-version-schema.yaml JSON schema" | ||
delete-branch: true | ||
committer: budimanjojo-bot <111944664+budimanjojo-bot[bot]@users.noreply.github.com> | ||
author: budimanjojo-bot <111944664+budimanjojo-bot[bot]@users.noreply.github.com> | ||
|
||
- name: Automerge | ||
if: steps.cpr.outputs.pull-request-operation == 'created' | ||
uses: peter-evans/enable-pull-request-automerge@v3 | ||
with: | ||
token: "${{ steps.generate-token.outputs.token }}" | ||
pull-request-number: "${{ steps.cpr.outputs.pull-request-number }}" | ||
merge-method: squash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module version-schema-gen | ||
|
||
go 1.21.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"flag" | ||
"io" | ||
"log" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"sort" | ||
) | ||
|
||
var ( | ||
factoryUrl = "https://factory.talos.dev" | ||
defaultExtensions = []string{ | ||
"siderolabs/amd-ucode", | ||
"siderolabs/bnx2-bnx2x", | ||
"siderolabs/drbd", | ||
"siderolabs/gasket-driver", | ||
"siderolabs/gvisor", | ||
"siderolabs/hello-world-service", | ||
"siderolabs/i915-ucode", | ||
"siderolabs/intel-ucode", | ||
"siderolabs/iscsi-tools", | ||
"siderolabs/nut-client", | ||
"siderolabs/nvidia-container-toolkit", | ||
"siderolabs/nvidia-fabricmanager", | ||
"siderolabs/nvidia-open-gpu-kernel-modules", | ||
"siderolabs/qemu-guest-agent", | ||
"siderolabs/tailscale", | ||
"siderolabs/thunderbolt", | ||
"siderolabs/usb-modem-drivers", | ||
"siderolabs/zfs", | ||
"siderolabs/nonfree-kmod-nvidia", | ||
} | ||
) | ||
|
||
type Version struct { | ||
Name string | ||
} | ||
|
||
func getVersions() []string { | ||
url := factoryUrl + "/versions" | ||
response, err := http.Get(url) | ||
if err != nil { | ||
log.Fatalf("Error doing GET request to %s: %s", url, err) | ||
} | ||
defer response.Body.Close() | ||
|
||
if response.StatusCode != 200 { | ||
log.Fatalf("%s returned %s", url, response.Status) | ||
} | ||
|
||
body, err := io.ReadAll(response.Body) | ||
if err != nil { | ||
log.Fatalf("Error reading response body from %s: %s", url, err) | ||
} | ||
|
||
var versions []string | ||
|
||
if err := json.Unmarshal(body, &versions); err != nil { | ||
log.Fatalf("Error unmarshalling JSON: %s", err) | ||
} | ||
|
||
sort.Strings(versions) | ||
|
||
return versions | ||
} | ||
|
||
func getExtensions(versions []string) map[string][]string { | ||
result := make(map[string][]string) | ||
result["default"] = defaultExtensions | ||
for _, version := range versions { | ||
url := factoryUrl + "/version/" + version + "/extensions/official" | ||
response, err := http.Get(url) | ||
if err != nil { | ||
log.Fatalf("Error doing GET request to %s, %s", url, err) | ||
} | ||
defer response.Body.Close() | ||
|
||
if response.StatusCode == http.StatusInternalServerError { | ||
result[version] = defaultExtensions | ||
continue | ||
} | ||
|
||
body, err := io.ReadAll(response.Body) | ||
if err != nil { | ||
log.Fatalf("Error reading response body from %s, %s", url, err) | ||
} | ||
|
||
var r []Version | ||
|
||
if err := json.Unmarshal(body, &r); err != nil { | ||
log.Fatalf("Error unmarshalling JSON: %s %s", body, err) | ||
} | ||
|
||
for _, a := range r { | ||
result[version] = append(result[version], a.Name) | ||
} | ||
|
||
} | ||
return result | ||
} | ||
|
||
func main() { | ||
flag.Parse() | ||
if flag.NArg() == 0 { | ||
log.Fatalf("no output file") | ||
} | ||
|
||
if _, err := os.Stat(filepath.Dir(flag.Arg(0))); os.IsNotExist(err) { | ||
log.Fatalf("%s", err) | ||
} | ||
|
||
versions := getVersions() | ||
result := getExtensions(versions) | ||
|
||
final, err := json.MarshalIndent(result, "", " ") | ||
if err != nil { | ||
log.Fatalf("%s", err) | ||
} | ||
|
||
if err := os.WriteFile(flag.Arg(0), final, 0o755); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.