diff --git a/.goreleaser.yaml b/.goreleaser.yaml index a8ae6c1..05cdbbe 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -29,6 +29,8 @@ checksum: name_template: 'checksums.txt' snapshot: name_template: "{{ incpatch .Version }}-next" +universal_binaries: + - name_template: "{{.ProjectName}}_MacOS_{{.Version}}" changelog: sort: asc filters: diff --git a/pkg/api/api.go b/pkg/api/api.go index 9e8c41d..77a45ae 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -226,6 +226,12 @@ func (api *api) module(ctx context.Context, module string, version vcs.Version) api.semc <- struct{}{} defer func() { <-api.semc }() + return api.store(ctx, module, version) +} + +func (api *api) store(ctx context.Context, module string, version vcs.Version) ([]byte, time.Time, error) { + api.log("api.store", "module", module, "version", version.String()) + timestamp, err := api.vcs(ctx, module).Timestamp(ctx, version) if err != nil { return nil, time.Time{}, err @@ -303,9 +309,11 @@ func (api *api) mod(w http.ResponseWriter, r *http.Request, module, version stri } } } + w.Write([]byte(fmt.Sprintf("module %s\n", module))) + return } } - w.Write([]byte(fmt.Sprintf("module %s\n", module))) + http.Error(w, err.Error(), http.StatusBadRequest) } func (api *api) zip(w http.ResponseWriter, r *http.Request, module, version string) { @@ -353,10 +361,21 @@ func (api *api) tag(w http.ResponseWriter, r *http.Request, module, version stri return } + // wait for semaphore + api.semc <- struct{}{} + defer func() { <-api.semc }() + err = taggable.Tag(r.Context(), vcs.Version(version), req.Short) if err != nil { api.log("api.tag", "module", module, "version", version, "error", err) http.Error(w, err.Error(), http.StatusBadRequest) return } + + _, _, err = api.store(r.Context(), module, vcs.Version(version)) + if err != nil { + api.log("api.tag", "module", module, "version", version, "error", err) + http.Error(w, err.Error(), http.StatusBadRequest) + return + } } diff --git a/pkg/vcs/tags.go b/pkg/vcs/tags.go index 899b172..8923049 100644 --- a/pkg/vcs/tags.go +++ b/pkg/vcs/tags.go @@ -82,6 +82,7 @@ func (v *taggableVCS) Tag(ctx context.Context, semVer Version, short string) err if versionExists(remoteVersions, semVer) { return fmt.Errorf("remote version %s already exists for module %s", semVer, v.module) } + v.wrapped.log("taggableVCS.Tag", "version", semVer, "short", short) return v.storage.Tag(v.module, semVer, short) } @@ -92,7 +93,10 @@ func (v *taggableVCS) List(ctx context.Context) ([]Version, error) { } tags := v.storage.tags(v.module) // Remote versions win. - return appendEphemeralVersion(remoteVersions, tags...), nil + allVersions := appendEphemeralVersion(remoteVersions, tags...) + // TODO(bilus): BUG - tag version 1.0.0 and then 0.1.0 - 0.1.0 is the "latest". + // sort.Slice(allVersions, func(i, j) bool { return allVersions[i].Before(allVersions[j]) }) + return allVersions, nil } func appendEphemeralVersion(versions []Version, tags ...ephemeralTag) []Version {