diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6b8710a --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.git diff --git a/Dockerfile b/Dockerfile index 97fc567..cfa7fd7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ WORKDIR /app COPY go.mod go.sum /app/ RUN go mod download -COPY *.go /app/ +COPY . /app/ RUN go build -o app . FROM docker.io/alpine:3.22 diff --git a/github.go b/github.go index 75635b7..dbec0e3 100644 --- a/github.go +++ b/github.go @@ -6,11 +6,11 @@ import ( "encoding/json" "fmt" "io" - "mime" "mime/multipart" "net/http" "os" - "strings" + + "code.geekeey.de/actions/sdk" ) type ApiClient interface { @@ -43,24 +43,6 @@ func NewGitHub(client ApiClient) *GitHub { return &GitHub{client: client} } -func HasContentType(r *http.Response, mimetype string) bool { - contentType := r.Header.Get("content-type") - if contentType == "" { - return mimetype == "application/octet-stream" - } - - for _, v := range strings.Split(contentType, ",") { - t, _, err := mime.ParseMediaType(v) - if err != nil { - break - } - if t == mimetype { - return true - } - } - return false -} - type GitTag struct { Commit struct { Created string `json:"created,omitempty"` @@ -87,7 +69,7 @@ func (gh *GitHub) GetGitTagInfo(repository, tag string, ctx context.Context) (*G return nil, err } defer res.Body.Close() - if !HasContentType(res, "application/json") { + if !sdk.HasContentType(res, "application/json") { return nil, fmt.Errorf("content-type: %q should be %q", res.Header.Get("content-type"), "application/json") } @@ -161,7 +143,7 @@ func (gh *GitHub) CreateRelease(creq *CreateReleaseRequest, ctx context.Context) return nil, err } defer res.Body.Close() - if !HasContentType(res, "application/json") { + if !sdk.HasContentType(res, "application/json") { return nil, fmt.Errorf("content-type: %q should be %q", res.Header.Get("content-type"), "application/json") } @@ -264,7 +246,7 @@ func (gh *GitHub) CreateReleaseArtifact(creq *CreateReleaseArtifactRequest, ctx return nil, err } defer res.Body.Close() - if !HasContentType(res, "application/json") { + if !sdk.HasContentType(res, "application/json") { return nil, fmt.Errorf("content-type: %q should be %q", res.Header.Get("content-type"), "application/json") } diff --git a/go.mod b/go.mod index 540a83f..6bdc712 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module code.geekeey.de/actions/release go 1.23.2 -require code.geekeey.de/actions/sdk v1.2.0 +require code.geekeey.de/actions/sdk v1.5.0 diff --git a/go.sum b/go.sum index 6a21fc7..b25cf65 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,2 @@ -code.geekeey.de/actions/sdk v1.2.0 h1:qQvOdTBtZVpR1xATNnApeiW78y34Jh83OjsQg1ajPjA= -code.geekeey.de/actions/sdk v1.2.0/go.mod h1:7iIOi3YUmdDe2BCz9s59wK1t0Ckec34e664q+TOreiE= +code.geekeey.de/actions/sdk v1.5.0 h1:7Ly8QsBniiwDVbv2Gm14l28+ccK1Z9fVUqsPHw9lSMg= +code.geekeey.de/actions/sdk v1.5.0/go.mod h1:7iIOi3YUmdDe2BCz9s59wK1t0Ckec34e664q+TOreiE= diff --git a/main.go b/main.go index 7a4ba84..897c0b4 100644 --- a/main.go +++ b/main.go @@ -39,8 +39,6 @@ type ReleaseAction struct { } func (action *ReleaseAction) setup() error { - var err error - 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 /") @@ -69,17 +67,19 @@ func (action *ReleaseAction) setup() error { // draft might be a bool constant or a regex which determins if it is // a draft by matching against the input version - action.draft, err = pattern("draft") + draft, err := pattern("draft") if err != nil { return fmt.Errorf("input 'draft': is not a bool or a valid regex") } + action.draft = draft // prerelease might be a bool constant or a regex which determins if it is // a prelease by matching against the input version - action.prerelease, err = pattern("prerelease") + prerelease, err := pattern("prerelease") if err != nil { return fmt.Errorf("input 'prerelease': is not a bool or a valid regex") } + action.prerelease = prerelease action.label = action.GetInput("label") action.notes = action.GetInput("notes")