chore: update to latest sdk (no release yet!)
This commit is contained in:
parent
259af57371
commit
f82408ed4f
5 changed files with 20 additions and 45 deletions
|
@ -1,4 +1,4 @@
|
||||||
FROM docker.io/golang:1.23-alpine3.20 AS compile
|
FROM docker.io/golang:1.24-alpine AS compile
|
||||||
|
|
||||||
ENV CGO_ENABLED=0
|
ENV CGO_ENABLED=0
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ RUN go mod download
|
||||||
COPY *.go /app/
|
COPY *.go /app/
|
||||||
RUN go build -o app .
|
RUN go build -o app .
|
||||||
|
|
||||||
FROM docker.io/alpine:3.20
|
FROM docker.io/alpine:3.22
|
||||||
|
|
||||||
WORKDIR /
|
WORKDIR /
|
||||||
|
|
||||||
|
|
18
github.go
18
github.go
|
@ -43,10 +43,6 @@ func NewGitHub(client ApiClient) *GitHub {
|
||||||
return &GitHub{client: client}
|
return &GitHub{client: client}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine whether the request `content-type` includes a
|
|
||||||
// server-acceptable mime-type
|
|
||||||
//
|
|
||||||
// Failure should yield an HTTP 415 (`http.StatusUnsupportedMediaType`)
|
|
||||||
func HasContentType(r *http.Response, mimetype string) bool {
|
func HasContentType(r *http.Response, mimetype string) bool {
|
||||||
contentType := r.Header.Get("Content-type")
|
contentType := r.Header.Get("Content-type")
|
||||||
if contentType == "" {
|
if contentType == "" {
|
||||||
|
@ -78,8 +74,8 @@ type GitTag struct {
|
||||||
ZipballURL string `json:"zipball_url,omitempty"`
|
ZipballURL string `json:"zipball_url,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gh *GitHub) GetGitTagInfo(owner, repo, tag string, ctx context.Context) (*GitTag, error) {
|
func (gh *GitHub) GetGitTagInfo(repository, tag string, ctx context.Context) (*GitTag, error) {
|
||||||
url := fmt.Sprintf("/repos/%s/%s/tags/%s", owner, repo, tag)
|
url := fmt.Sprintf("/repos/%s/tags/%s", repository, tag)
|
||||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -117,8 +113,7 @@ func (gh *GitHub) GetGitTagInfo(owner, repo, tag string, ctx context.Context) (*
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateReleaseRequest struct {
|
type CreateReleaseRequest struct {
|
||||||
Owner string `json:"-"`
|
Repository string `json:"-"`
|
||||||
Repo string `json:"-"`
|
|
||||||
|
|
||||||
Body string `json:"body,omitempty"`
|
Body string `json:"body,omitempty"`
|
||||||
Draft bool `json:"draft,omitempty"`
|
Draft bool `json:"draft,omitempty"`
|
||||||
|
@ -153,7 +148,7 @@ func (gh *GitHub) CreateRelease(creq *CreateReleaseRequest, ctx context.Context)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
url := fmt.Sprintf("/repos/%s/%s/releases", creq.Owner, creq.Repo)
|
url := fmt.Sprintf("/repos/%s/releases", creq.Repository)
|
||||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, &b)
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, &b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -206,8 +201,7 @@ func (gh *GitHub) CreateRelease(creq *CreateReleaseRequest, ctx context.Context)
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateReleaseArtifactRequest struct {
|
type CreateReleaseArtifactRequest struct {
|
||||||
Owner string `json:"-"`
|
Repository string `json:"-"`
|
||||||
Repo string `json:"-"`
|
|
||||||
|
|
||||||
Id int64 `json:"-"`
|
Id int64 `json:"-"`
|
||||||
|
|
||||||
|
@ -257,7 +251,7 @@ func (gh *GitHub) CreateReleaseArtifact(creq *CreateReleaseArtifactRequest, ctx
|
||||||
|
|
||||||
w.Close()
|
w.Close()
|
||||||
|
|
||||||
url := fmt.Sprintf("/repos/%s/%s/releases/%d/assets", creq.Owner, creq.Repo, creq.Id)
|
url := fmt.Sprintf("/repos/%s/releases/%d/assets", creq.Repository, creq.Id)
|
||||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, &b)
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, &b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -2,4 +2,4 @@ module git.geekeey.de/actions/release
|
||||||
|
|
||||||
go 1.23.2
|
go 1.23.2
|
||||||
|
|
||||||
require git.geekeey.de/actions/sdk v1.0.1
|
require git.geekeey.de/actions/sdk v1.1.0
|
||||||
|
|
8
go.sum
8
go.sum
|
@ -1,6 +1,2 @@
|
||||||
git.geekeey.de/actions/sdk v0.0.0-20241020125724-76a93c0d8cec h1:auq6X3d0N25UPSyjuvRDh55W4sgAsSaeDGdWOS6AG6g=
|
git.geekeey.de/actions/sdk v1.1.0 h1:VrtMWo7hi3T4yQ4FL6P1XQkSeCA5Rl3UsSmBKITotLY=
|
||||||
git.geekeey.de/actions/sdk v0.0.0-20241020125724-76a93c0d8cec/go.mod h1:pBcHd6afsvseZF9hSc2A0b6+MldC/Ch6CSDaVlWMAmA=
|
git.geekeey.de/actions/sdk v1.1.0/go.mod h1:pBcHd6afsvseZF9hSc2A0b6+MldC/Ch6CSDaVlWMAmA=
|
||||||
git.geekeey.de/actions/sdk v1.0.0 h1:vVEPz6ndFJt4iqtJhhFuf7XA3bf2gasZJ3f8gb94o5g=
|
|
||||||
git.geekeey.de/actions/sdk v1.0.0/go.mod h1:pBcHd6afsvseZF9hSc2A0b6+MldC/Ch6CSDaVlWMAmA=
|
|
||||||
git.geekeey.de/actions/sdk v1.0.1 h1:fecr+IILPgKFoMaQDtSvkBbaFfudOlf+2KdMVKcFA1M=
|
|
||||||
git.geekeey.de/actions/sdk v1.0.1/go.mod h1:pBcHd6afsvseZF9hSc2A0b6+MldC/Ch6CSDaVlWMAmA=
|
|
||||||
|
|
31
main.go
31
main.go
|
@ -26,7 +26,7 @@ func main() {
|
||||||
|
|
||||||
type ReleaseAction struct {
|
type ReleaseAction struct {
|
||||||
*sdk.Action
|
*sdk.Action
|
||||||
repository Repository
|
repository string
|
||||||
version string
|
version string
|
||||||
|
|
||||||
draft bool
|
draft bool
|
||||||
|
@ -38,26 +38,13 @@ type ReleaseAction struct {
|
||||||
artifacts []string
|
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 {
|
func (action *ReleaseAction) setup() error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
r, err := NewRepository(action.GetInput("repository"))
|
action.repository = action.GetInput("repository")
|
||||||
if err != nil {
|
if ok, err := regexp.MatchString(`^(\w+)/(\w+)$`, action.repository); !ok || err != nil {
|
||||||
return fmt.Errorf("input 'repository': %s", err)
|
return fmt.Errorf("input 'repository': is empty or does not match <onwer>/<repo>")
|
||||||
}
|
}
|
||||||
action.repository = r
|
|
||||||
|
|
||||||
action.version = action.GetInput("version")
|
action.version = action.GetInput("version")
|
||||||
if len(action.version) == 0 {
|
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
|
// only get the commit info when we are missing a name or a text
|
||||||
if len(action.label) == 0 || len(action.notes) == 0 {
|
if len(action.label) == 0 || len(action.notes) == 0 {
|
||||||
action.Debugf("Getting git tag information from repository")
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -136,13 +123,12 @@ func (action *ReleaseAction) run(ctx context.Context) error {
|
||||||
|
|
||||||
action.Debugf("Creating release %s", action.version)
|
action.Debugf("Creating release %s", action.version)
|
||||||
release, err := github.CreateRelease(&CreateReleaseRequest{
|
release, err := github.CreateRelease(&CreateReleaseRequest{
|
||||||
Owner: action.repository.Owner(),
|
Repository: action.repository,
|
||||||
Repo: action.repository.Repo(),
|
TagName: action.version,
|
||||||
Name: action.label,
|
Name: action.label,
|
||||||
Body: action.notes,
|
Body: action.notes,
|
||||||
Draft: action.draft,
|
Draft: action.draft,
|
||||||
PreRelease: action.prerelease,
|
PreRelease: action.prerelease,
|
||||||
TagName: action.version,
|
|
||||||
}, ctx)
|
}, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot create release for %s: %s", action.version, err)
|
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
|
return
|
||||||
}
|
}
|
||||||
a, err := github.CreateReleaseArtifact(&CreateReleaseArtifactRequest{
|
a, err := github.CreateReleaseArtifact(&CreateReleaseArtifactRequest{
|
||||||
|
Repository: action.repository,
|
||||||
Id: release.Id,
|
Id: release.Id,
|
||||||
Owner: action.repository.Owner(),
|
|
||||||
Repo: action.repository.Repo(),
|
|
||||||
Name: f.Name(), // unused?
|
Name: f.Name(), // unused?
|
||||||
Attachment: f,
|
Attachment: f,
|
||||||
}, ctx)
|
}, ctx)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue