···11+// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT.
22+33+package tangled
44+55+// schema: sh.tangled.ci.describeWorkflowDefinition
66+77+import (
88+ "context"
99+1010+ "github.com/bluesky-social/indigo/lex/util"
1111+)
1212+1313+const (
1414+ CiDescribeWorkflowDefinitionNSID = "sh.tangled.ci.describeWorkflowDefinition"
1515+)
1616+1717+// CiDescribeWorkflowDefinition_Output is the output of a sh.tangled.ci.describeWorkflowDefinition call.
1818+type CiDescribeWorkflowDefinition_Output struct {
1919+ // derived: Whether the workflow definition is derived from this repository at all. When false, no commit-to-commit comparison is meaningful (e.g. definitions managed externally), and callers should not surface change warnings.
2020+ Derived bool `json:"derived" cborgen:"derived"`
2121+ // hash: Opaque fingerprint of the workflow definition as resolved by the spindle; for git-derived spindles this covers the workflow files at the commit, not their post-compilation expansion. Only equality is defined: identical resolved definitions MUST produce identical hashes for a given spindle deployment, and differing definitions SHOULD produce differing hashes. Absent when derived is false.
2222+ Hash *string `json:"hash,omitempty" cborgen:"hash,omitempty"`
2323+ // workflows: Names or paths of the effective workflow files that produced the hash, for display purposes.
2424+ Workflows []string `json:"workflows,omitempty" cborgen:"workflows,omitempty"`
2525+}
2626+2727+// CiDescribeWorkflowDefinition calls the XRPC method "sh.tangled.ci.describeWorkflowDefinition".
2828+//
2929+// repo: Target repository DID the workflow definition belongs to.
3030+// sha: Commit SHA to resolve the workflow definition at
3131+// sourceRepo: Repository DID to resolve workflow definitions from, if different from the target repo (e.g. a fork for a fork-based pull request).
3232+func CiDescribeWorkflowDefinition(ctx context.Context, c util.LexClient, repo string, sha string, sourceRepo string) (*CiDescribeWorkflowDefinition_Output, error) {
3333+ var out CiDescribeWorkflowDefinition_Output
3434+3535+ params := map[string]interface{}{}
3636+ params["repo"] = repo
3737+ params["sha"] = sha
3838+ if sourceRepo != "" {
3939+ params["sourceRepo"] = sourceRepo
4040+ }
4141+ if err := c.LexDo(ctx, util.Query, "", "sh.tangled.ci.describeWorkflowDefinition", params, nil, &out); err != nil {
4242+ return nil, err
4343+ }
4444+4545+ return &out, nil
4646+}
+62
lexicons/ci/describeWorkflowDefinition.json
···11+{
22+ "lexicon": 1,
33+ "id": "sh.tangled.ci.describeWorkflowDefinition",
44+ "defs": {
55+ "main": {
66+ "type": "query",
77+ "description": "Resolve the workflow definition a pipeline would use at a given commit and return a fingerprint of it.",
88+ "parameters": {
99+ "type": "params",
1010+ "required": ["repo", "sha"],
1111+ "properties": {
1212+ "repo": {
1313+ "type": "string",
1414+ "format": "did",
1515+ "description": "Target repository DID the workflow definition belongs to."
1616+ },
1717+ "sha": {
1818+ "type": "string",
1919+ "minLength": 40,
2020+ "maxLength": 40,
2121+ "description": "Commit SHA to resolve the workflow definition at"
2222+ },
2323+ "sourceRepo": {
2424+ "type": "string",
2525+ "format": "did",
2626+ "description": "Repository DID to resolve workflow definitions from, if different from the target repo"
2727+ }
2828+ }
2929+ },
3030+ "output": {
3131+ "encoding": "application/json",
3232+ "schema": {
3333+ "type": "object",
3434+ "required": ["derived"],
3535+ "properties": {
3636+ "derived": {
3737+ "type": "boolean",
3838+ "description": "Whether the workflow definition is derived from this repository at all. When false, no commit-to-commit comparison is meaningful (e.g. definitions managed externally), and callers should not surface change warnings."
3939+ },
4040+ "hash": {
4141+ "type": "string",
4242+ "description": "Fingerprint of the workflow definition as resolved by the spindle. Absent when derived is false."
4343+ },
4444+ "workflows": {
4545+ "type": "array",
4646+ "items": {
4747+ "type": "string"
4848+ },
4949+ "description": "Names or paths of the effective workflow files that produced the hash."
5050+ }
5151+ }
5252+ }
5353+ },
5454+ "errors": [
5555+ {
5656+ "name": "InvalidRequest",
5757+ "description": "Invalid request parameters"
5858+ }
5959+ ]
6060+ }
6161+ }
6262+}
+34
spindle/fingerprint_test.go
···11+package spindle
22+33+import (
44+ "testing"
55+66+ "github.com/stretchr/testify/assert"
77+88+ "tangled.org/core/workflow"
99+)
1010+1111+func TestFingerprintWorkflowDefinition(t *testing.T) {
1212+ a := workflow.RawWorkflow{Name: "a.yml", Contents: []byte("engine: dummy\n")}
1313+ b := workflow.RawWorkflow{Name: "b.yml", Contents: []byte("engine: nixery\n")}
1414+1515+ // iteration order must not affect the fingerprint
1616+ assert.Equal(t,
1717+ fingerprintWorkflowDefinition(workflow.RawPipeline{a, b}),
1818+ fingerprintWorkflowDefinition(workflow.RawPipeline{b, a}),
1919+ )
2020+2121+ // content and name changes must both change the fingerprint
2222+ base := fingerprintWorkflowDefinition(workflow.RawPipeline{a, b})
2323+ assert.NotEqual(t, base, fingerprintWorkflowDefinition(workflow.RawPipeline{
2424+ {Name: "a.yml", Contents: []byte("engine: nixery\n")}, b,
2525+ }))
2626+ assert.NotEqual(t, base, fingerprintWorkflowDefinition(workflow.RawPipeline{
2727+ {Name: "c.yml", Contents: a.Contents}, b,
2828+ }))
2929+3030+ assert.NotEqual(t,
3131+ fingerprintWorkflowDefinition(nil),
3232+ fingerprintWorkflowDefinition(workflow.RawPipeline{a}),
3333+ )
3434+}