1 Commits

Author SHA1 Message Date
unkinben be28507b92 feat: add zip packaging target and woodpecker release pipeline
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2026-06-22 23:36:03 +10:00
5 changed files with 35 additions and 89 deletions
+21
View File
@@ -0,0 +1,21 @@
when:
- event: tag
steps:
- name: package
image: golang:1.25
commands:
- apt-get update && apt-get install -y zip
- make package VERSION=${CI_COMMIT_TAG}
- name: upload
image: curlimages/curl:latest
secrets: [artifactapi_url, artifactapi_repo]
commands:
- |
VERSION=$(echo ${CI_COMMIT_TAG} | sed 's/^v//')
FILE="terraform-provider-artifactapi_${VERSION}_linux_amd64.zip"
curl -f -X PUT \
"$${ARTIFACTAPI_URL}/api/v2/remotes/$${ARTIFACTAPI_REPO}/files/unkin/artifactapi/$${FILE}" \
-H "Content-Type: application/zip" \
--data-binary @"$${FILE}"
+11 -22
View File
@@ -1,9 +1,11 @@
.PHONY: build install test lint fmt clean tidy patch minor major .PHONY: build install test lint fmt clean tidy package
BINARY := terraform-provider-artifactapi BINARY := terraform-provider-artifactapi
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "0.0.0-dev") VERSION ?= 0.0.1
OS_ARCH := linux_amd64 OS_ARCH := linux_amd64
INSTALL_DIR := ~/.terraform.d/plugins/git.unkin.net/unkin/artifactapi/$(VERSION)/$(OS_ARCH) INSTALL_VERSION := $(shell echo $(VERSION) | sed 's/^v//')
INSTALL_DIR := ~/.terraform.d/plugins/git.unkin.net/unkin/artifactapi/$(INSTALL_VERSION)/$(OS_ARCH)
ZIP := $(BINARY)_$(INSTALL_VERSION)_$(OS_ARCH).zip
GO_VERSION_REQUIRED := 1.23 GO_VERSION_REQUIRED := 1.23
GO_VERSION_ACTUAL := $(shell go version | sed 's/go version go\([0-9]*\.[0-9]*\).*/\1/') GO_VERSION_ACTUAL := $(shell go version | sed 's/go version go\([0-9]*\.[0-9]*\).*/\1/')
@@ -29,26 +31,13 @@ lint: check-go
fmt: check-go fmt: check-go
gofmt -w . gofmt -w .
package: build
cp $(BINARY) $(BINARY)_v$(INSTALL_VERSION)
zip $(ZIP) $(BINARY)_v$(INSTALL_VERSION)
rm $(BINARY)_v$(INSTALL_VERSION)
clean: clean:
rm -f $(BINARY) rm -f $(BINARY) *.zip
tidy: tidy:
go mod tidy go mod tidy
_LATEST := $(shell git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' | head -1)
_BASE := $(if $(_LATEST),$(_LATEST),v0.0.0)
_MAJ := $(shell echo $(_BASE) | sed 's/^v//' | cut -d. -f1)
_MIN := $(shell echo $(_BASE) | sed 's/^v//' | cut -d. -f2)
_PAT := $(shell echo $(_BASE) | sed 's/^v//' | cut -d. -f3)
patch:
@NEW=v$(_MAJ).$(_MIN).$(shell expr $(_PAT) + 1); \
git tag $$NEW && echo "Tagged $$NEW" && git push origin $$NEW
minor:
@NEW=v$(_MAJ).$(shell expr $(_MIN) + 1).0; \
git tag $$NEW && echo "Tagged $$NEW" && git push origin $$NEW
major:
@NEW=v$(shell expr $(_MAJ) + 1).0.0; \
git tag $$NEW && echo "Tagged $$NEW" && git push origin $$NEW
+1 -12
View File
@@ -16,7 +16,7 @@ func listToStrings(ctx context.Context, l types.List) []string {
} }
func stringsToList(ctx context.Context, ss []string) types.List { func stringsToList(ctx context.Context, ss []string) types.List {
if ss == nil { if len(ss) == 0 {
return types.ListNull(types.StringType) return types.ListNull(types.StringType)
} }
elems := make([]types.String, len(ss)) elems := make([]types.String, len(ss))
@@ -26,14 +26,3 @@ func stringsToList(ctx context.Context, ss []string) types.List {
list, _ := types.ListValueFrom(ctx, types.StringType, elems) list, _ := types.ListValueFrom(ctx, types.StringType, elems)
return list return list
} }
// preserveListNullEmptySemantics keeps the prior null/empty distinction when
// the API returns null for a field that was previously an empty list.
// Without this, OpenTofu reports "inconsistent result after apply" because
// the plan/state had [] but the provider returned null.
func preserveListNullEmptySemantics(prior, current types.List) types.List {
if current.IsNull() && !prior.IsNull() && len(prior.Elements()) == 0 {
return prior
}
return current
}
+2 -44
View File
@@ -63,11 +63,8 @@ func TestListToStrings_WithValues(t *testing.T) {
func TestStringsToList_EmptySlice(t *testing.T) { func TestStringsToList_EmptySlice(t *testing.T) {
ctx := context.Background() ctx := context.Background()
result := stringsToList(ctx, []string{}) result := stringsToList(ctx, []string{})
if result.IsNull() { if !result.IsNull() {
t.Fatalf("expected empty list for empty slice, got null") t.Fatalf("expected null list for empty slice, got %v", result)
}
if len(result.Elements()) != 0 {
t.Fatalf("expected 0 elements, got %d", len(result.Elements()))
} }
} }
@@ -106,42 +103,3 @@ func TestStringsToList_SingleValue(t *testing.T) {
t.Fatalf("expected [\"solo\"], got %v", back) t.Fatalf("expected [\"solo\"], got %v", back)
} }
} }
func TestPreserveListNullEmptySemantics(t *testing.T) {
ctx := context.Background()
emptyList, _ := types.ListValueFrom(ctx, types.StringType, []types.String{})
nullList := types.ListNull(types.StringType)
populatedList := stringsToList(ctx, []string{"a"})
t.Run("prior empty + current null → preserves empty", func(t *testing.T) {
result := preserveListNullEmptySemantics(emptyList, nullList)
if result.IsNull() {
t.Fatal("expected empty list, got null")
}
if len(result.Elements()) != 0 {
t.Fatalf("expected 0 elements, got %d", len(result.Elements()))
}
})
t.Run("prior null + current null → stays null", func(t *testing.T) {
result := preserveListNullEmptySemantics(nullList, nullList)
if !result.IsNull() {
t.Fatal("expected null, got non-null")
}
})
t.Run("prior empty + current populated → uses current", func(t *testing.T) {
result := preserveListNullEmptySemantics(emptyList, populatedList)
elems := listToStrings(ctx, result)
if len(elems) != 1 || elems[0] != "a" {
t.Fatalf("expected [a], got %v", elems)
}
})
t.Run("prior populated + current null → stays null", func(t *testing.T) {
result := preserveListNullEmptySemantics(populatedList, nullList)
if !result.IsNull() {
t.Fatal("expected null (prior was populated, not empty — no preservation)")
}
})
}
-11
View File
@@ -181,7 +181,6 @@ func (r *remoteResource) Create(ctx context.Context, req resource.CreateRequest,
} }
state := r.apiToModel(ctx, created) state := r.apiToModel(ctx, created)
reconcileOptionalLists(&plan, &state)
resp.Diagnostics.Append(resp.State.Set(ctx, state)...) resp.Diagnostics.Append(resp.State.Set(ctx, state)...)
} }
@@ -204,7 +203,6 @@ func (r *remoteResource) Read(ctx context.Context, req resource.ReadRequest, res
} }
newState := r.apiToModel(ctx, remote) newState := r.apiToModel(ctx, remote)
reconcileOptionalLists(&state, &newState)
resp.Diagnostics.Append(resp.State.Set(ctx, newState)...) resp.Diagnostics.Append(resp.State.Set(ctx, newState)...)
} }
@@ -225,7 +223,6 @@ func (r *remoteResource) Update(ctx context.Context, req resource.UpdateRequest,
} }
state := r.apiToModel(ctx, updated) state := r.apiToModel(ctx, updated)
reconcileOptionalLists(&plan, &state)
resp.Diagnostics.Append(resp.State.Set(ctx, state)...) resp.Diagnostics.Append(resp.State.Set(ctx, state)...)
} }
@@ -246,14 +243,6 @@ func (r *remoteResource) ImportState(ctx context.Context, req resource.ImportSta
resource.ImportStatePassthroughID(ctx, path.Root("name"), req, resp) resource.ImportStatePassthroughID(ctx, path.Root("name"), req, resp)
} }
func reconcileOptionalLists(prior, current *remoteResourceModel) {
current.Patterns = preserveListNullEmptySemantics(prior.Patterns, current.Patterns)
current.Blocklist = preserveListNullEmptySemantics(prior.Blocklist, current.Blocklist)
current.MutablePatterns = preserveListNullEmptySemantics(prior.MutablePatterns, current.MutablePatterns)
current.ImmutablePatterns = preserveListNullEmptySemantics(prior.ImmutablePatterns, current.ImmutablePatterns)
current.BanTags = preserveListNullEmptySemantics(prior.BanTags, current.BanTags)
}
func (r *remoteResource) modelToAPI(ctx context.Context, m remoteResourceModel) remoteAPI { func (r *remoteResource) modelToAPI(ctx context.Context, m remoteResourceModel) remoteAPI {
api := remoteAPI{ api := remoteAPI{
Name: m.Name.ValueString(), Name: m.Name.ValueString(),