diff --git a/app/cli/cmd/apply.go b/app/cli/cmd/apply.go index a1d1d0504..e8443cd9e 100644 --- a/app/cli/cmd/apply.go +++ b/app/cli/cmd/apply.go @@ -40,9 +40,9 @@ Supports multi-document YAML files. Each document must have a 'kind' field.`, } for _, r := range results { - status := "applied" - if r.Unchanged { - status = "unchanged" + status := "unchanged" + if r.Changed { + status = "applied" } logger.Info().Msgf("%s/%s %s", r.Kind, r.Name, status) } diff --git a/app/cli/cmd/workflow_contract_apply.go b/app/cli/cmd/workflow_contract_apply.go index 70614d43b..2fc60f5bb 100644 --- a/app/cli/cmd/workflow_contract_apply.go +++ b/app/cli/cmd/workflow_contract_apply.go @@ -1,5 +1,5 @@ // -// Copyright 2025 The Chainloop Authors. +// Copyright 2025-2026 The Chainloop Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -48,14 +48,14 @@ or update it if it already exists.`, desc = &description } - res, unchanged, err := action.NewWorkflowContractApply(ActionOpts).Run(cmd.Context(), contractName, contractPath, desc, projectName) + res, changed, err := action.NewWorkflowContractApply(ActionOpts).Run(cmd.Context(), contractName, contractPath, desc, projectName) if err != nil { return err } - status := "applied" - if unchanged { - status = "unchanged" + status := "unchanged" + if changed { + status = "applied" } logger.Info().Msgf("Contract/%s %s", contractName, status) return output.EncodeOutput(flagOutputFormat, res, contractItemTableOutput) diff --git a/app/cli/pkg/action/apply.go b/app/cli/pkg/action/apply.go index 022c31146..dd5977e53 100644 --- a/app/cli/pkg/action/apply.go +++ b/app/cli/pkg/action/apply.go @@ -36,9 +36,9 @@ const ( // ApplyResult holds the outcome of a successfully applied resource document type ApplyResult struct { - Kind string - Name string - Unchanged bool + Kind string + Name string + Changed bool } // YAMLDoc holds a parsed YAML document with its kind and raw bytes @@ -70,11 +70,11 @@ func (a *Apply) Run(ctx context.Context, path string) ([]*ApplyResult, error) { for _, doc := range docs { switch doc.Kind { case KindContract: - unchanged, err := ApplyContractFromRawData(ctx, a.cfg.CPConnection, doc.RawData) + changed, err := ApplyContractFromRawData(ctx, a.cfg.CPConnection, doc.RawData) if err != nil { return results, fmt.Errorf("%s/%s: %w", doc.Kind, doc.Name, err) } - results = append(results, &ApplyResult{Kind: doc.Kind, Name: doc.Name, Unchanged: unchanged}) + results = append(results, &ApplyResult{Kind: doc.Kind, Name: doc.Name, Changed: changed}) default: return results, fmt.Errorf("unsupported kind %q", doc.Kind) } @@ -124,7 +124,7 @@ func ApplyContractFromRawData(ctx context.Context, conn *grpc.ClientConn, rawDat return false, fmt.Errorf("failed to apply contract: %w", err) } - return resp.GetUnchanged(), nil + return resp.GetChanged(), nil } // CollectYAMLFiles returns YAML file paths from the given path. diff --git a/app/cli/pkg/action/workflow_contract_apply.go b/app/cli/pkg/action/workflow_contract_apply.go index a86ae8389..764556769 100644 --- a/app/cli/pkg/action/workflow_contract_apply.go +++ b/app/cli/pkg/action/workflow_contract_apply.go @@ -1,5 +1,5 @@ // -// Copyright 2025 The Chainloop Authors. +// Copyright 2025-2026 The Chainloop Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -64,9 +64,9 @@ func (action *WorkflowContractApply) Run(ctx context.Context, contractName strin return nil, false, fmt.Errorf("failed to update existing contract '%s': %w", contractName, err) } - unchanged := prevRevision == res.Result.GetRevision().GetRevision() + changed := prevRevision != res.Result.GetRevision().GetRevision() - return pbWorkflowContractItemToAction(res.Result.Contract), unchanged, nil + return pbWorkflowContractItemToAction(res.Result.Contract), changed, nil } // Contract doesn't exist, perform create @@ -87,5 +87,5 @@ func (action *WorkflowContractApply) Run(ctx context.Context, contractName strin return nil, false, fmt.Errorf("failed to create new contract '%s': %w", contractName, err) } - return pbWorkflowContractItemToAction(res.Result), false, nil + return pbWorkflowContractItemToAction(res.Result), true, nil } diff --git a/app/controlplane/api/controlplane/v1/workflow_contract.pb.go b/app/controlplane/api/controlplane/v1/workflow_contract.pb.go index c69e06870..67177e354 100644 --- a/app/controlplane/api/controlplane/v1/workflow_contract.pb.go +++ b/app/controlplane/api/controlplane/v1/workflow_contract.pb.go @@ -560,8 +560,12 @@ func (x *WorkflowContractServiceApplyRequest) GetRawSchema() []byte { type WorkflowContractServiceApplyResponse struct { state protoimpl.MessageState `protogen:"open.v1"` Result *WorkflowContractItem `protobuf:"bytes,1,opt,name=result,proto3" json:"result,omitempty"` - // Whether the resource was unchanged - Unchanged bool `protobuf:"varint,2,opt,name=unchanged,proto3" json:"unchanged,omitempty"` + // Deprecated: use changed instead + // + // Deprecated: Marked as deprecated in controlplane/v1/workflow_contract.proto. + Unchanged bool `protobuf:"varint,2,opt,name=unchanged,proto3" json:"unchanged,omitempty"` + // Whether the resource was changed + Changed bool `protobuf:"varint,3,opt,name=changed,proto3" json:"changed,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -603,6 +607,7 @@ func (x *WorkflowContractServiceApplyResponse) GetResult() *WorkflowContractItem return nil } +// Deprecated: Marked as deprecated in controlplane/v1/workflow_contract.proto. func (x *WorkflowContractServiceApplyResponse) GetUnchanged() bool { if x != nil { return x.Unchanged @@ -610,6 +615,13 @@ func (x *WorkflowContractServiceApplyResponse) GetUnchanged() bool { return false } +func (x *WorkflowContractServiceApplyResponse) GetChanged() bool { + if x != nil { + return x.Changed + } + return false +} + type WorkflowContractServiceUpdateResponse_Result struct { state protoimpl.MessageState `protogen:"open.v1"` Contract *WorkflowContractItem `protobuf:"bytes,1,opt,name=contract,proto3" json:"contract,omitempty"` @@ -757,10 +769,11 @@ const file_controlplane_v1_workflow_contract_proto_rawDesc = "" + "%WorkflowContractServiceDeleteResponse\"D\n" + "#WorkflowContractServiceApplyRequest\x12\x1d\n" + "\n" + - "raw_schema\x18\x01 \x01(\fR\trawSchema\"\x83\x01\n" + + "raw_schema\x18\x01 \x01(\fR\trawSchema\"\xa1\x01\n" + "$WorkflowContractServiceApplyResponse\x12=\n" + - "\x06result\x18\x01 \x01(\v2%.controlplane.v1.WorkflowContractItemR\x06result\x12\x1c\n" + - "\tunchanged\x18\x02 \x01(\bR\tunchanged2\xec\x05\n" + + "\x06result\x18\x01 \x01(\v2%.controlplane.v1.WorkflowContractItemR\x06result\x12 \n" + + "\tunchanged\x18\x02 \x01(\bB\x02\x18\x01R\tunchanged\x12\x18\n" + + "\achanged\x18\x03 \x01(\bR\achanged2\xec\x05\n" + "\x17WorkflowContractService\x12q\n" + "\x04List\x123.controlplane.v1.WorkflowContractServiceListRequest\x1a4.controlplane.v1.WorkflowContractServiceListResponse\x12w\n" + "\x06Create\x125.controlplane.v1.WorkflowContractServiceCreateRequest\x1a6.controlplane.v1.WorkflowContractServiceCreateResponse\x12w\n" + diff --git a/app/controlplane/api/controlplane/v1/workflow_contract.proto b/app/controlplane/api/controlplane/v1/workflow_contract.proto index 36f37c027..e5a9f42b2 100644 --- a/app/controlplane/api/controlplane/v1/workflow_contract.proto +++ b/app/controlplane/api/controlplane/v1/workflow_contract.proto @@ -123,6 +123,8 @@ message WorkflowContractServiceApplyRequest { message WorkflowContractServiceApplyResponse { WorkflowContractItem result = 1; - // Whether the resource was unchanged - bool unchanged = 2; + // Deprecated: use changed instead + bool unchanged = 2 [deprecated = true]; + // Whether the resource was changed + bool changed = 3; } diff --git a/app/controlplane/api/gen/frontend/controlplane/v1/workflow_contract.ts b/app/controlplane/api/gen/frontend/controlplane/v1/workflow_contract.ts index ef5fbd321..bef4b4026 100644 --- a/app/controlplane/api/gen/frontend/controlplane/v1/workflow_contract.ts +++ b/app/controlplane/api/gen/frontend/controlplane/v1/workflow_contract.ts @@ -73,8 +73,14 @@ export interface WorkflowContractServiceApplyRequest { export interface WorkflowContractServiceApplyResponse { result?: WorkflowContractItem; - /** Whether the resource was unchanged */ + /** + * Deprecated: use changed instead + * + * @deprecated + */ unchanged: boolean; + /** Whether the resource was changed */ + changed: boolean; } function createBaseWorkflowContractServiceListRequest(): WorkflowContractServiceListRequest { @@ -992,7 +998,7 @@ export const WorkflowContractServiceApplyRequest = { }; function createBaseWorkflowContractServiceApplyResponse(): WorkflowContractServiceApplyResponse { - return { result: undefined, unchanged: false }; + return { result: undefined, unchanged: false, changed: false }; } export const WorkflowContractServiceApplyResponse = { @@ -1003,6 +1009,9 @@ export const WorkflowContractServiceApplyResponse = { if (message.unchanged === true) { writer.uint32(16).bool(message.unchanged); } + if (message.changed === true) { + writer.uint32(24).bool(message.changed); + } return writer; }, @@ -1027,6 +1036,13 @@ export const WorkflowContractServiceApplyResponse = { message.unchanged = reader.bool(); continue; + case 3: + if (tag !== 24) { + break; + } + + message.changed = reader.bool(); + continue; } if ((tag & 7) === 4 || tag === 0) { break; @@ -1040,6 +1056,7 @@ export const WorkflowContractServiceApplyResponse = { return { result: isSet(object.result) ? WorkflowContractItem.fromJSON(object.result) : undefined, unchanged: isSet(object.unchanged) ? Boolean(object.unchanged) : false, + changed: isSet(object.changed) ? Boolean(object.changed) : false, }; }, @@ -1048,6 +1065,7 @@ export const WorkflowContractServiceApplyResponse = { message.result !== undefined && (obj.result = message.result ? WorkflowContractItem.toJSON(message.result) : undefined); message.unchanged !== undefined && (obj.unchanged = message.unchanged); + message.changed !== undefined && (obj.changed = message.changed); return obj; }, @@ -1065,6 +1083,7 @@ export const WorkflowContractServiceApplyResponse = { ? WorkflowContractItem.fromPartial(object.result) : undefined; message.unchanged = object.unchanged ?? false; + message.changed = object.changed ?? false; return message; }, }; diff --git a/app/controlplane/api/gen/jsonschema/controlplane.v1.WorkflowContractServiceApplyResponse.jsonschema.json b/app/controlplane/api/gen/jsonschema/controlplane.v1.WorkflowContractServiceApplyResponse.jsonschema.json index bd89a7702..8a8849ae0 100644 --- a/app/controlplane/api/gen/jsonschema/controlplane.v1.WorkflowContractServiceApplyResponse.jsonschema.json +++ b/app/controlplane/api/gen/jsonschema/controlplane.v1.WorkflowContractServiceApplyResponse.jsonschema.json @@ -3,11 +3,15 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "additionalProperties": false, "properties": { + "changed": { + "description": "Whether the resource was changed", + "type": "boolean" + }, "result": { "$ref": "controlplane.v1.WorkflowContractItem.jsonschema.json" }, "unchanged": { - "description": "Whether the resource was unchanged", + "description": "Deprecated: use changed instead", "type": "boolean" } }, diff --git a/app/controlplane/api/gen/jsonschema/controlplane.v1.WorkflowContractServiceApplyResponse.schema.json b/app/controlplane/api/gen/jsonschema/controlplane.v1.WorkflowContractServiceApplyResponse.schema.json index 25a2e806b..bff86e520 100644 --- a/app/controlplane/api/gen/jsonschema/controlplane.v1.WorkflowContractServiceApplyResponse.schema.json +++ b/app/controlplane/api/gen/jsonschema/controlplane.v1.WorkflowContractServiceApplyResponse.schema.json @@ -3,11 +3,15 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "additionalProperties": false, "properties": { + "changed": { + "description": "Whether the resource was changed", + "type": "boolean" + }, "result": { "$ref": "controlplane.v1.WorkflowContractItem.schema.json" }, "unchanged": { - "description": "Whether the resource was unchanged", + "description": "Deprecated: use changed instead", "type": "boolean" } }, diff --git a/app/controlplane/internal/service/workflowcontract.go b/app/controlplane/internal/service/workflowcontract.go index c3c7bdca7..b0f9f9596 100644 --- a/app/controlplane/internal/service/workflowcontract.go +++ b/app/controlplane/internal/service/workflowcontract.go @@ -1,5 +1,5 @@ // -// Copyright 2024-2025 The Chainloop Authors. +// Copyright 2024-2026 The Chainloop Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -276,8 +276,8 @@ func (s *WorkflowContractService) Apply(ctx context.Context, req *pb.WorkflowCon } return &pb.WorkflowContractServiceApplyResponse{ - Result: bizWorkFlowContractToPb(schemaWithVersion.Contract), - Unchanged: schemaWithVersion.Unchanged, + Result: bizWorkFlowContractToPb(schemaWithVersion.Contract), + Changed: schemaWithVersion.Changed, }, nil } @@ -304,7 +304,7 @@ func (s *WorkflowContractService) Apply(ctx context.Context, req *pb.WorkflowCon return nil, handleUseCaseErr(err, s.log) } - return &pb.WorkflowContractServiceApplyResponse{Result: bizWorkFlowContractToPb(schema)}, nil + return &pb.WorkflowContractServiceApplyResponse{Result: bizWorkFlowContractToPb(schema), Changed: true}, nil } func (s *WorkflowContractService) Delete(ctx context.Context, req *pb.WorkflowContractServiceDeleteRequest) (*pb.WorkflowContractServiceDeleteResponse, error) { diff --git a/app/controlplane/pkg/biz/workflowcontract.go b/app/controlplane/pkg/biz/workflowcontract.go index e3a9ab0ad..e538cf37c 100644 --- a/app/controlplane/pkg/biz/workflowcontract.go +++ b/app/controlplane/pkg/biz/workflowcontract.go @@ -90,9 +90,9 @@ func (c *Contract) isV1Schema() bool { } type WorkflowContractWithVersion struct { - Contract *WorkflowContract - Version *WorkflowContractVersion - Unchanged bool + Contract *WorkflowContract + Version *WorkflowContractVersion + Changed bool } type WorkflowContractRepo interface { @@ -426,15 +426,15 @@ func (uc *WorkflowContractUseCase) Update(ctx context.Context, orgID, name strin } // Check if the revisions have changed - unchanged := wfContractPreUpdate.LatestRevision == c.Version.Revision - if !unchanged { + changed := wfContractPreUpdate.LatestRevision != c.Version.Revision + if changed { eventPayload.NewRevision = &c.Version.Revision eventPayload.NewRevisionID = &c.Version.ID } uc.auditorUC.Dispatch(ctx, eventPayload, &orgUUID) - c.Unchanged = unchanged + c.Changed = changed return c, nil }