chore: update to latest sdk (no release yet!)

This commit is contained in:
Louis Seubert 2024-11-01 23:58:56 +01:00
commit b3bdf90f13
Signed by: louis9902
GPG key ID: 4B9DB28F826553BD
5 changed files with 20 additions and 47 deletions

31
main.go
View file

@ -26,7 +26,7 @@ func main() {
type ReleaseAction struct {
*sdk.Action
repository Repository
repository string
version string
draft bool
@ -38,26 +38,13 @@ type ReleaseAction struct {
artifacts []string
}
type Repository []string
func NewRepository(r string) (Repository, error) {
split := strings.Split(string(r), "/")
if len(split) != 2 {
return nil, fmt.Errorf("repository must be in the format '<owner>/<repo>'")
}
return split, nil
}
func (r Repository) Owner() string { return r[0] }
func (r Repository) Repo() string { return r[1] }
func (action *ReleaseAction) setup() error {
var err error
r, err := NewRepository(action.GetInput("repository"))
if err != nil {
return fmt.Errorf("input 'repository': %s", err)
action.repository = action.GetInput("repository")
if ok, err := regexp.MatchString(`^(\w+)/(\w+)$`, action.repository); !ok || err != nil {
return fmt.Errorf("input 'repository': is empty or does not match <onwer>/<repo>")
}
action.repository = r
action.version = action.GetInput("version")
if len(action.version) == 0 {
@ -122,7 +109,7 @@ func (action *ReleaseAction) run(ctx context.Context) error {
// only get the commit info when we are missing a name or a text
if len(action.label) == 0 || len(action.notes) == 0 {
action.Debugf("Getting git tag information from repository")
tag, err := github.GetGitTagInfo(action.repository.Owner(), action.repository.Repo(), action.version, ctx)
tag, err := github.GetGitTagInfo(action.repository, action.version, ctx)
if err != nil {
return err
}
@ -136,13 +123,12 @@ func (action *ReleaseAction) run(ctx context.Context) error {
action.Debugf("Creating release %s", action.version)
release, err := github.CreateRelease(&CreateReleaseRequest{
Owner: action.repository.Owner(),
Repo: action.repository.Repo(),
Repository: action.repository,
TagName: action.version,
Name: action.label,
Body: action.notes,
Draft: action.draft,
PreRelease: action.prerelease,
TagName: action.version,
}, ctx)
if err != nil {
return fmt.Errorf("cannot create release for %s: %s", action.version, err)
@ -160,9 +146,8 @@ func (action *ReleaseAction) run(ctx context.Context) error {
return
}
a, err := github.CreateReleaseArtifact(&CreateReleaseArtifactRequest{
Repository: action.repository,
Id: release.Id,
Owner: action.repository.Owner(),
Repo: action.repository.Repo(),
Name: f.Name(), // unused?
Attachment: f,
}, ctx)