github: check new kernel commit
This commit is contained in:
parent
9133a3a809
commit
9412a29536
2 changed files with 48 additions and 25 deletions
12
.github/workflows/cron.yml
vendored
12
.github/workflows/cron.yml
vendored
|
@ -1,4 +1,4 @@
|
|||
name: Auto-update firmware
|
||||
name: Auto-update kernel
|
||||
|
||||
on:
|
||||
push:
|
||||
|
@ -13,8 +13,6 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
|
@ -23,13 +21,13 @@ jobs:
|
|||
|
||||
- name: Check latest kernel version from https://archive.raspberrypi.org/debian/
|
||||
id: check
|
||||
run: echo "::set-output name=version::$(go run ./cmd/check-update/main.go)"
|
||||
run: echo "::set-output name=sha::$(go run ./cmd/check-update/main.go)"
|
||||
|
||||
- name: Fetch latest kernel
|
||||
if: steps.check.outputs.version != ''
|
||||
run: echo "checkout ${{steps.check.outputs.version}}"
|
||||
if: steps.check.outputs.sha != ''
|
||||
run: echo "checkout ${{steps.check.outputs.sha}}"
|
||||
|
||||
- name: Commit the new kernel
|
||||
uses: stefanzweifel/git-auto-commit-action@v4
|
||||
with:
|
||||
commit_message: kernel ${{steps.check.outputs.version}}
|
||||
commit_message: kernel ${{steps.check.outputs.sha}}
|
||||
|
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
|
@ -51,40 +52,64 @@ func run() error {
|
|||
|
||||
log.Println("latest version:", tagName)
|
||||
|
||||
tags, err := gitTags("linux-sources")
|
||||
latestSha, err := githubCommitSha(tagName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, tag := range tags {
|
||||
if tagName == tag {
|
||||
log.Println("already up to date")
|
||||
return nil
|
||||
}
|
||||
log.Println("latest commit:", latestSha)
|
||||
|
||||
currentSha, err := submoduleSha("linux-sources")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Println("outdated tag", tags)
|
||||
fmt.Println(tagName)
|
||||
log.Println("submodule commit:", currentSha)
|
||||
|
||||
if latestSha == currentSha {
|
||||
log.Println("already up to date")
|
||||
return nil
|
||||
}
|
||||
fmt.Println(latestSha)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func gitTags(folder string) ([]string, error) {
|
||||
current, err := os.Getwd()
|
||||
func githubCommitSha(tagName string) (string, error) {
|
||||
req, err := http.NewRequest("GET", "https://api.github.com/repos/raspberrypi/linux/git/ref/tags/"+tagName, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
defer os.Chdir(current)
|
||||
req.Header.Add("Accept", "application/vnd.github.v3+json")
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
err = os.Chdir(folder)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
type githubResponse struct {
|
||||
Message string `json:"message"`
|
||||
Object struct {
|
||||
Sha string `json:"sha"`
|
||||
} `json:"object"`
|
||||
}
|
||||
cmd := exec.Command("git", "tag", "--points-at", "HEAD")
|
||||
var gr githubResponse
|
||||
err = json.NewDecoder(resp.Body).Decode(&gr)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if gr.Object.Sha == "" {
|
||||
return "", errors.New("could not get sha: " + gr.Message)
|
||||
}
|
||||
return gr.Object.Sha, nil
|
||||
}
|
||||
|
||||
func submoduleSha(submodule string) (string, error) {
|
||||
cmd := exec.Command("git", "rev-parse", "HEAD:"+submodule)
|
||||
cmd.Stderr = os.Stderr
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
return strings.Split(strings.TrimSpace(string(out)), "\n"), nil
|
||||
return strings.TrimSpace(string(out)), nil
|
||||
}
|
||||
|
||||
func scanOnlineTextFile(url string, stopScanning func(string) bool) error {
|
||||
|
|
Loading…
Reference in a new issue