Skip to content

Commit f94b4e1

Browse files
fix: nightly release
1 parent a87b697 commit f94b4e1

2 files changed

Lines changed: 61 additions & 4 deletions

File tree

.github/workflows/nightly.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,16 @@ jobs:
8383
git push --delete origin nightly || true
8484
shell: bash
8585

86+
- name: Write commit SHA
87+
run: echo -n "${{ github.sha }}" > commit.txt
88+
8689
- name: Create nightly release
8790
uses: softprops/action-gh-release@v2
8891
with:
8992
tag_name: nightly
9093
name: "nightly (${{ env.RELEASE_DATE }})"
9194
prerelease: true
9295
body: "Automated nightly build from the latest commit on main."
93-
files: createos-*
96+
files: |
97+
createos-*
98+
commit.txt

cmd/upgrade/upgrade.go

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,15 @@ func runUpgrade() error {
6464
}
6565

6666
if version.Channel == "nightly" {
67-
// Nightly: ISO date string comparison is sufficient
68-
if release.TagName == version.Version {
69-
pterm.Success.Println("Already up to date.")
67+
remoteCommit, err := fetchNightlyCommit(release)
68+
if err != nil {
69+
return fmt.Errorf("could not check nightly commit: %w", err)
70+
}
71+
if remoteCommit == version.Commit {
72+
pterm.Success.Printf("Already up to date (commit: %s).\n", shortSHA(version.Commit))
7073
return nil
7174
}
75+
pterm.Info.Printf("New nightly available: %s → %s\n", shortSHA(version.Commit), shortSHA(remoteCommit))
7276
} else {
7377
cmp := semver.Compare(version.Version, release.TagName)
7478
switch {
@@ -238,6 +242,54 @@ func downloadToTemp(rawURL string) (string, error) {
238242
return tmp.Name(), nil
239243
}
240244

245+
func fetchNightlyCommit(release *githubRelease) (string, error) {
246+
commitURL := ""
247+
for _, a := range release.Assets {
248+
if a.Name == "commit.txt" {
249+
commitURL = a.BrowserDownloadURL
250+
break
251+
}
252+
}
253+
if commitURL == "" {
254+
return "", fmt.Errorf("commit.txt not found in nightly release assets")
255+
}
256+
if err := validateDownloadURL(commitURL); err != nil {
257+
return "", err
258+
}
259+
260+
ctx, cancel := context.WithTimeout(context.Background(), apiTimeout)
261+
defer cancel()
262+
263+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, commitURL, nil)
264+
if err != nil {
265+
return "", err
266+
}
267+
268+
resp, err := httpClient.Do(req)
269+
if err != nil {
270+
return "", err
271+
}
272+
defer resp.Body.Close() //nolint:errcheck
273+
274+
if resp.StatusCode != http.StatusOK {
275+
return "", fmt.Errorf("commit.txt download returned %d", resp.StatusCode)
276+
}
277+
278+
data, err := io.ReadAll(io.LimitReader(resp.Body, 128))
279+
if err != nil {
280+
return "", err
281+
}
282+
283+
return strings.TrimSpace(string(data)), nil
284+
}
285+
286+
func shortSHA(sha string) string {
287+
if len(sha) >= 7 {
288+
return sha[:7]
289+
}
290+
return sha
291+
}
292+
241293
func fetchChecksum(rawURL string) (string, error) {
242294
ctx, cancel := context.WithTimeout(context.Background(), apiTimeout)
243295
defer cancel()

0 commit comments

Comments
 (0)