diff --git a/release-notes/8.0.0/fix/3864.md b/release-notes/8.0.0/fix/3864.md new file mode 100644 index 0000000000..af0a50baa0 --- /dev/null +++ b/release-notes/8.0.0/fix/3864.md @@ -0,0 +1 @@ +SourceHut Builds webhook would fail when the `triggers` field was used. \ No newline at end of file diff --git a/services/webhook/sourcehut/builds.go b/services/webhook/sourcehut/builds.go index e7501110a2..7b7ace15bb 100644 --- a/services/webhook/sourcehut/builds.go +++ b/services/webhook/sourcehut/builds.go @@ -264,19 +264,13 @@ func (pc sourcehutConvertor) buildManifest(repo *api.Repository, commitID, gitRe return []byte(msg), fmt.Errorf(msg+": %w", err) } defer r.Close() + + // reference: https://man.sr.ht/builds.sr.ht/manifest.md var manifest struct { - Image string `yaml:"image"` - Arch string `yaml:"arch,omitempty"` - Packages []string `yaml:"packages,omitempty"` - Repositories map[string]string `yaml:"repositories,omitempty"` - Artifacts []string `yaml:"artifacts,omitempty"` - Shell bool `yaml:"shell,omitempty"` - Sources []string `yaml:"sources"` - Tasks []map[string]string `yaml:"tasks"` - Triggers []string `yaml:"triggers,omitempty"` - Environment map[string]string `yaml:"environment"` - Secrets []string `yaml:"secrets,omitempty"` - Oauth string `yaml:"oauth,omitempty"` + Sources []string `yaml:"sources"` + Environment map[string]string `yaml:"environment"` + + Rest map[string]yaml.Node `yaml:",inline"` } if err := yaml.NewDecoder(r).Decode(&manifest); err != nil { msg := fmt.Sprintf("could not decode manifest %q", pc.meta.ManifestPath) diff --git a/services/webhook/sourcehut/builds_test.go b/services/webhook/sourcehut/builds_test.go index 9ab018df72..64c6081076 100644 --- a/services/webhook/sourcehut/builds_test.go +++ b/services/webhook/sourcehut/builds_test.go @@ -69,19 +69,21 @@ func TestSourcehutBuildsPayload(t *testing.T) { pc.meta.ManifestPath = "simple.yml" pl, err := pc.Create(p) require.NoError(t, err) - assert.Equal(t, buildsVariables{ - Manifest: `image: alpine/edge -sources: + + assert.Equal(t, `sources: - http://localhost:3000/testdata/repo.git#58771003157b81abc6bf41df0c5db4147a3e3c83 -tasks: - - say-hello: | - echo hello - - say-world: echo world environment: BUILD_SUBMITTER: forgejo BUILD_SUBMITTER_URL: https://example.forgejo.org/ GIT_REF: refs/heads/test -`, +image: alpine/edge +tasks: + - say-hello: | + echo hello + - say-world: echo world +`, pl.Variables.Manifest) + assert.Equal(t, buildsVariables{ + Manifest: pl.Variables.Manifest, // the manifest correctness is checked above, for nicer diff on error Note: "branch test created", Tags: []string{"testdata/repo", "branch/test", "simple.yml"}, Secrets: true, @@ -100,19 +102,21 @@ environment: pc.meta.ManifestPath = "simple.yml" pl, err := pc.Create(p) require.NoError(t, err) - assert.Equal(t, buildsVariables{ - Manifest: `image: alpine/edge -sources: + + assert.Equal(t, `sources: - http://localhost:3000/testdata/repo.git#58771003157b81abc6bf41df0c5db4147a3e3c83 -tasks: - - say-hello: | - echo hello - - say-world: echo world environment: BUILD_SUBMITTER: forgejo BUILD_SUBMITTER_URL: https://example.forgejo.org/ GIT_REF: refs/tags/v1.0.0 -`, +image: alpine/edge +tasks: + - say-hello: | + echo hello + - say-world: echo world +`, pl.Variables.Manifest) + assert.Equal(t, buildsVariables{ + Manifest: pl.Variables.Manifest, // the manifest correctness is checked above, for nicer diff on error Note: "tag v1.0.0 created", Tags: []string{"testdata/repo", "tag/v1.0.0", "simple.yml"}, Secrets: true, @@ -151,19 +155,20 @@ environment: pl, err := pc.Push(p) require.NoError(t, err) - assert.Equal(t, buildsVariables{ - Manifest: `image: alpine/edge -sources: + assert.Equal(t, `sources: - http://localhost:3000/testdata/repo.git#58771003157b81abc6bf41df0c5db4147a3e3c83 -tasks: - - say-hello: | - echo hello - - say-world: echo world environment: BUILD_SUBMITTER: forgejo BUILD_SUBMITTER_URL: https://example.forgejo.org/ GIT_REF: refs/heads/main -`, +image: alpine/edge +tasks: + - say-hello: | + echo hello + - say-world: echo world +`, pl.Variables.Manifest) + assert.Equal(t, buildsVariables{ + Manifest: pl.Variables.Manifest, // the manifest correctness is checked above, for nicer diff on error Note: "add simple", Tags: []string{"testdata/repo", "branch/main", "simple.yml"}, Secrets: true, @@ -175,7 +180,7 @@ environment: p := &api.PushPayload{ Ref: "refs/heads/main", HeadCommit: &api.PayloadCommit{ - ID: "69b217caa89166a02b8cd368b64fb83a44720e14", + ID: "b0404943256a1f5a50c3726f4378756b4c1e5704", Message: "replace simple with complex", }, Repo: repo, @@ -187,23 +192,32 @@ environment: pl, err := pc.Push(p) require.NoError(t, err) - assert.Equal(t, buildsVariables{ - Manifest: `image: archlinux -packages: - - nodejs - - npm - - rsync -sources: - - http://localhost:3000/testdata/repo.git#69b217caa89166a02b8cd368b64fb83a44720e14 -tasks: [] + assert.Equal(t, `sources: + - http://localhost:3000/testdata/repo.git#b0404943256a1f5a50c3726f4378756b4c1e5704 environment: BUILD_SUBMITTER: forgejo BUILD_SUBMITTER_URL: https://example.forgejo.org/ GIT_REF: refs/heads/main deploy: synapse@synapse-bt.org +image: archlinux +packages: + - nodejs + - npm + - rsync secrets: - 7ebab768-e5e4-4c9d-ba57-ec41a72c5665 -`, +tasks: [] +triggers: + - condition: failure + action: email + to: Jim Jimson + # report back the status + - condition: always + action: webhook + url: https://hook.example.org +`, pl.Variables.Manifest) + assert.Equal(t, buildsVariables{ + Manifest: pl.Variables.Manifest, // the manifest correctness is checked above, for nicer diff on error Note: "replace simple with complex", Tags: []string{"testdata/repo", "branch/main", "complex.yaml"}, Secrets: false, diff --git a/services/webhook/sourcehut/testdata/repo.git/objects/01/16b5e2279b70e5f5b98240e8896331248f4463 b/services/webhook/sourcehut/testdata/repo.git/objects/01/16b5e2279b70e5f5b98240e8896331248f4463 deleted file mode 100644 index c06eb842be..0000000000 Binary files a/services/webhook/sourcehut/testdata/repo.git/objects/01/16b5e2279b70e5f5b98240e8896331248f4463 and /dev/null differ diff --git a/services/webhook/sourcehut/testdata/repo.git/objects/56/f276169b9766f805e5198fe7fb6698153fdb03 b/services/webhook/sourcehut/testdata/repo.git/objects/56/f276169b9766f805e5198fe7fb6698153fdb03 deleted file mode 100644 index dca1d23ce9..0000000000 --- a/services/webhook/sourcehut/testdata/repo.git/objects/56/f276169b9766f805e5198fe7fb6698153fdb03 +++ /dev/null @@ -1 +0,0 @@ -xNKj0ZxBɶzQ[FQ?"=A3Ѳmk#*@L3&)'D$#Β 搊Ѽ,#/8OvzIN<u'[;J~{#'e;.x輋#[K[kyASq\DAkƵ؝~PkVO \ No newline at end of file diff --git a/services/webhook/sourcehut/testdata/repo.git/objects/99/fb389b232e5497f0dcdb1c1065eac1d10d3794 b/services/webhook/sourcehut/testdata/repo.git/objects/99/fb389b232e5497f0dcdb1c1065eac1d10d3794 new file mode 100644 index 0000000000..43dd885510 Binary files /dev/null and b/services/webhook/sourcehut/testdata/repo.git/objects/99/fb389b232e5497f0dcdb1c1065eac1d10d3794 differ diff --git a/services/webhook/sourcehut/testdata/repo.git/objects/a5/4082fdb8e55055382725f10a81bb4dc2b13029 b/services/webhook/sourcehut/testdata/repo.git/objects/a5/4082fdb8e55055382725f10a81bb4dc2b13029 new file mode 100644 index 0000000000..071f79e851 --- /dev/null +++ b/services/webhook/sourcehut/testdata/repo.git/objects/a5/4082fdb8e55055382725f10a81bb4dc2b13029 @@ -0,0 +1,4 @@ +xUn0 wk +l4z0 %fm~@Dc<(ŝ% m]NjDR +A閌9Xxu{;Nȅ4(Gy:QO?/9 lh|0cΌl8*$?dԻ**>7ȖXomUJItmKqrh8>)ҺڋF,77,8 {:0zZfya) +5 ʴ狉7ΑLܯ)z yivoQ78J}臤 \ No newline at end of file diff --git a/services/webhook/sourcehut/testdata/repo.git/objects/b0/404943256a1f5a50c3726f4378756b4c1e5704 b/services/webhook/sourcehut/testdata/repo.git/objects/b0/404943256a1f5a50c3726f4378756b4c1e5704 new file mode 100644 index 0000000000..a2cff639dc Binary files /dev/null and b/services/webhook/sourcehut/testdata/repo.git/objects/b0/404943256a1f5a50c3726f4378756b4c1e5704 differ diff --git a/services/webhook/sourcehut/testdata/repo.git/objects/bd/d74dba3f34542e480d56c2a91c9e2463180d3c b/services/webhook/sourcehut/testdata/repo.git/objects/bd/d74dba3f34542e480d56c2a91c9e2463180d3c deleted file mode 100644 index 639f5c4784..0000000000 Binary files a/services/webhook/sourcehut/testdata/repo.git/objects/bd/d74dba3f34542e480d56c2a91c9e2463180d3c and /dev/null differ diff --git a/services/webhook/sourcehut/testdata/repo.git/objects/c2/30778a03511f546f532e79c8c14917c260e750 b/services/webhook/sourcehut/testdata/repo.git/objects/c2/30778a03511f546f532e79c8c14917c260e750 deleted file mode 100644 index 4a952fb0b2..0000000000 Binary files a/services/webhook/sourcehut/testdata/repo.git/objects/c2/30778a03511f546f532e79c8c14917c260e750 and /dev/null differ diff --git a/services/webhook/sourcehut/testdata/repo.git/objects/c9/fa8be8c6f230e9529f8e546a3e6a354cbaf313 b/services/webhook/sourcehut/testdata/repo.git/objects/c9/fa8be8c6f230e9529f8e546a3e6a354cbaf313 deleted file mode 100644 index 291f0a422c..0000000000 Binary files a/services/webhook/sourcehut/testdata/repo.git/objects/c9/fa8be8c6f230e9529f8e546a3e6a354cbaf313 and /dev/null differ diff --git a/services/webhook/sourcehut/testdata/repo.git/objects/cb/80b2628b69c86b6baea464e5f9fc28405fde4b b/services/webhook/sourcehut/testdata/repo.git/objects/cb/80b2628b69c86b6baea464e5f9fc28405fde4b deleted file mode 100644 index 891ace4651..0000000000 --- a/services/webhook/sourcehut/testdata/repo.git/objects/cb/80b2628b69c86b6baea464e5f9fc28405fde4b +++ /dev/null @@ -1 +0,0 @@ -x=Kn0 D)`k@Pd{P2-AQ] YIesmKoD)8p gg44lFQF9˜V,[UΤ`~[iVڕ 4+(0Y)$"ԠlZ-e5wԦʸNY?V4&tC9=a ,P \ No newline at end of file diff --git a/services/webhook/sourcehut/testdata/repo.git/refs/heads/main b/services/webhook/sourcehut/testdata/repo.git/refs/heads/main index 4e693a7464..a7ab41949f 100644 --- a/services/webhook/sourcehut/testdata/repo.git/refs/heads/main +++ b/services/webhook/sourcehut/testdata/repo.git/refs/heads/main @@ -1 +1 @@ -69b217caa89166a02b8cd368b64fb83a44720e14 +b0404943256a1f5a50c3726f4378756b4c1e5704