terraform-provider-stackitp.../generator/cmd/publish/shasums.go
Marcel S. Henselin 5958474f9a
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 4s
CI Workflow / Test readiness for publishing provider (pull_request) Failing after 14s
CI Workflow / CI run build and linting (pull_request) Failing after 10s
CI Workflow / Code coverage report (pull_request) Has been skipped
CI Workflow / CI run tests (pull_request) Failing after 57s
fix: code cleanup
2026-03-02 10:32:58 +01:00

39 lines
880 B
Go

package publish
import (
"log/slog"
"path"
"regexp"
)
func (p *Provider) GetShaSums() (ShaSums, error) {
return GetShaSumContents(p.DistPath, p.RepoName, p.Version)
}
type ShaSums []ShaSum
type ShaSum struct {
Sum string
Path string
}
func GetShaSumContents(distPath, repoName, version string) (ShaSums, error) {
shaSumFileName := repoName + "_" + version + "_SHA256SUMS"
shaSumPath := path.Join(distPath, shaSumFileName)
shaSumLine, err := ReadFile(shaSumPath)
if err != nil {
return nil, err
}
regEx := regexp.MustCompile(`([0-9a-fA-F]+)\s+(.+)`)
shaSums := ShaSums{}
for _, line := range shaSumLine {
matches := regEx.FindAllStringSubmatch(line, -1)
if len(matches) < 1 {
slog.Warn("unable to parse SHA sum line", "line", line)
continue
}
shaSums = append(shaSums, ShaSum{Sum: matches[0][1], Path: matches[0][2]})
}
return shaSums, nil
}