From 855f95f7a276e374459b0c3ee63d909ad663c36f Mon Sep 17 00:00:00 2001 From: oliverpool Date: Wed, 22 May 2024 10:09:32 +0200 Subject: [PATCH 1/4] test: sourcehut_builds trigger (cherry picked from commit 7b47cb43c13b495d61cc577dfc8f6050d1f9d0d2) --- services/webhook/sourcehut/builds_test.go | 19 +++++++++++++----- .../01/16b5e2279b70e5f5b98240e8896331248f4463 | Bin 54 -> 0 bytes .../56/f276169b9766f805e5198fe7fb6698153fdb03 | 1 - .../99/fb389b232e5497f0dcdb1c1065eac1d10d3794 | Bin 0 -> 57 bytes .../a5/4082fdb8e55055382725f10a81bb4dc2b13029 | 4 ++++ .../b0/404943256a1f5a50c3726f4378756b4c1e5704 | Bin 0 -> 160 bytes .../bd/d74dba3f34542e480d56c2a91c9e2463180d3c | Bin 130 -> 0 bytes .../c2/30778a03511f546f532e79c8c14917c260e750 | Bin 84 -> 0 bytes .../c9/fa8be8c6f230e9529f8e546a3e6a354cbaf313 | Bin 56 -> 0 bytes .../cb/80b2628b69c86b6baea464e5f9fc28405fde4b | 1 - .../testdata/repo.git/refs/heads/main | 2 +- 11 files changed, 19 insertions(+), 8 deletions(-) delete mode 100644 services/webhook/sourcehut/testdata/repo.git/objects/01/16b5e2279b70e5f5b98240e8896331248f4463 delete mode 100644 services/webhook/sourcehut/testdata/repo.git/objects/56/f276169b9766f805e5198fe7fb6698153fdb03 create mode 100644 services/webhook/sourcehut/testdata/repo.git/objects/99/fb389b232e5497f0dcdb1c1065eac1d10d3794 create mode 100644 services/webhook/sourcehut/testdata/repo.git/objects/a5/4082fdb8e55055382725f10a81bb4dc2b13029 create mode 100644 services/webhook/sourcehut/testdata/repo.git/objects/b0/404943256a1f5a50c3726f4378756b4c1e5704 delete mode 100644 services/webhook/sourcehut/testdata/repo.git/objects/bd/d74dba3f34542e480d56c2a91c9e2463180d3c delete mode 100644 services/webhook/sourcehut/testdata/repo.git/objects/c2/30778a03511f546f532e79c8c14917c260e750 delete mode 100644 services/webhook/sourcehut/testdata/repo.git/objects/c9/fa8be8c6f230e9529f8e546a3e6a354cbaf313 delete mode 100644 services/webhook/sourcehut/testdata/repo.git/objects/cb/80b2628b69c86b6baea464e5f9fc28405fde4b diff --git a/services/webhook/sourcehut/builds_test.go b/services/webhook/sourcehut/builds_test.go index 9ab018df72..3818568f78 100644 --- a/services/webhook/sourcehut/builds_test.go +++ b/services/webhook/sourcehut/builds_test.go @@ -175,7 +175,7 @@ environment: p := &api.PushPayload{ Ref: "refs/heads/main", HeadCommit: &api.PayloadCommit{ - ID: "69b217caa89166a02b8cd368b64fb83a44720e14", + ID: "b0404943256a1f5a50c3726f4378756b4c1e5704", Message: "replace simple with complex", }, Repo: repo, @@ -187,15 +187,22 @@ environment: pl, err := pc.Push(p) require.NoError(t, err) - assert.Equal(t, buildsVariables{ - Manifest: `image: archlinux + assert.Equal(t, `image: archlinux packages: - nodejs - npm - rsync sources: - - http://localhost:3000/testdata/repo.git#69b217caa89166a02b8cd368b64fb83a44720e14 + - http://localhost:3000/testdata/repo.git#b0404943256a1f5a50c3726f4378756b4c1e5704 tasks: [] +triggers: + - condition: failure + action: email + to: Jim Jimson + # report back the status + - condition: always + action: webhook + url: https://hook.example.org environment: BUILD_SUBMITTER: forgejo BUILD_SUBMITTER_URL: https://example.forgejo.org/ @@ -203,7 +210,9 @@ environment: deploy: synapse@synapse-bt.org secrets: - 7ebab768-e5e4-4c9d-ba57-ec41a72c5665 -`, +`, 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 c06eb842befe81109993560ca4832df776981b41..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 zcmV-60LlM&0V^p=O;s?qU@$Z=Ff%bxD9+3+$Vt_!%*|mqWKiD494H@>AFNk-;-IJa Mp@ioF08HTz`Z}E#b^rhX 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 0000000000000000000000000000000000000000..43dd8855100f4bdd80f4b317cab81831fef3c5a0 GIT binary patch literal 57 zcmV-90LK4#0V^p=O;s>4U@$Z=Ff%bxNY2kK$Vsixt4z$zVOZ+W^moV8fKUr{)sI|_ PyL}IBG|&V9h1U_+m5LcT literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..a2cff639dcae5bff557b668be4c8ef35dfcd7fab GIT binary patch literal 160 zcmV;R0AK%j0gaAZ3PK?eK>KzT{s%FmbA3QWTN!n{36&SI*588`(C2}3;N*V0wW*Dv z-5er1#+q!1$yg%`MPH%hk}xB{u^_%Sbi=zeWa8C&mHeO%i-f4IpwY?aHQj*~`@&bkFC>OB|$mA{8m{%;quzgBT6 OdXBcPGSmxv?ME%KQc1f2 literal 0 HcmV?d00001 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 639f5c4784986454b8ae9dbd63253cd964128acc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 130 zcmV-|0Db>>0hNtQ3IZ_@1zqP9y%(fA|A2@q?~%-OG-8ZoB6xg9J%PJdi>f!ZTFU@( zelt2VAdyXmrF0=VWRpz_UTS3TgH?*8_E~GIM0}1*>u_rQ%-06{{2NDp#rnAMZpFiz kB}v99jj%1eb qjMSW*d@F?-unH6BhiZ6XT* 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 291f0a422cd47a15406fcc943090863e297f0ce2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 56 zcmV-80LTA$0V^p=O;s?qWH2-^Ff%bxNY2kK$VsixtH{k^xb&b+r@LYLF7LZVQ*spC Orw3kUUjP7qI}#?9i5IB= 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 From 287253ff7d99f1aa90135b0bb1f84fee99f3723b Mon Sep 17 00:00:00 2001 From: oliverpool Date: Wed, 22 May 2024 10:09:58 +0200 Subject: [PATCH 2/4] fix: sourcehut_builds preserve unused fields Fix #3820 (cherry picked from commit c9f38e2813aaad818db29204a1b1b728fcf488ca) --- services/webhook/sourcehut/builds.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/services/webhook/sourcehut/builds.go b/services/webhook/sourcehut/builds.go index 1561b9e6e6..9836d5e623 100644 --- a/services/webhook/sourcehut/builds.go +++ b/services/webhook/sourcehut/builds.go @@ -270,18 +270,18 @@ func (pc sourcehutConvertor) buildManifest(repo *api.Repository, commitID, gitRe } defer r.Close() 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"` + Image yaml.Node `yaml:"image"` + Arch yaml.Node `yaml:"arch,omitempty"` + Packages yaml.Node `yaml:"packages,omitempty"` + Repositories yaml.Node `yaml:"repositories,omitempty"` + Artifacts yaml.Node `yaml:"artifacts,omitempty"` + Shell yaml.Node `yaml:"shell,omitempty"` + Sources []string `yaml:"sources"` + Tasks yaml.Node `yaml:"tasks"` + Triggers yaml.Node `yaml:"triggers,omitempty"` + Environment map[string]string `yaml:"environment"` + Secrets yaml.Node `yaml:"secrets,omitempty"` + Oauth yaml.Node `yaml:"oauth,omitempty"` } if err := yaml.NewDecoder(r).Decode(&manifest); err != nil { msg := fmt.Sprintf("could not decode manifest %q", pc.meta.ManifestPath) From 1c99c289f6ee0a2e8e3a7bddea2845e8683c1653 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Wed, 22 May 2024 10:42:16 +0200 Subject: [PATCH 3/4] refactor: sourcehut_builds ignore unused fields (cherry picked from commit 1f6f909b2e2b2f1502a9e148828ecfb16b3029bf) --- services/webhook/sourcehut/builds.go | 18 ++---- services/webhook/sourcehut/builds_test.go | 73 ++++++++++++----------- 2 files changed, 45 insertions(+), 46 deletions(-) diff --git a/services/webhook/sourcehut/builds.go b/services/webhook/sourcehut/builds.go index 9836d5e623..1cb6d41bd8 100644 --- a/services/webhook/sourcehut/builds.go +++ b/services/webhook/sourcehut/builds.go @@ -269,19 +269,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 yaml.Node `yaml:"image"` - Arch yaml.Node `yaml:"arch,omitempty"` - Packages yaml.Node `yaml:"packages,omitempty"` - Repositories yaml.Node `yaml:"repositories,omitempty"` - Artifacts yaml.Node `yaml:"artifacts,omitempty"` - Shell yaml.Node `yaml:"shell,omitempty"` - Sources []string `yaml:"sources"` - Tasks yaml.Node `yaml:"tasks"` - Triggers yaml.Node `yaml:"triggers,omitempty"` - Environment map[string]string `yaml:"environment"` - Secrets yaml.Node `yaml:"secrets,omitempty"` - Oauth yaml.Node `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 3818568f78..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, @@ -187,13 +192,20 @@ environment: pl, err := pc.Push(p) require.NoError(t, err) - assert.Equal(t, `image: archlinux + 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 -sources: - - http://localhost:3000/testdata/repo.git#b0404943256a1f5a50c3726f4378756b4c1e5704 +secrets: + - 7ebab768-e5e4-4c9d-ba57-ec41a72c5665 tasks: [] triggers: - condition: failure @@ -203,13 +215,6 @@ triggers: - condition: always action: webhook url: https://hook.example.org -environment: - BUILD_SUBMITTER: forgejo - BUILD_SUBMITTER_URL: https://example.forgejo.org/ - GIT_REF: refs/heads/main - deploy: synapse@synapse-bt.org -secrets: - - 7ebab768-e5e4-4c9d-ba57-ec41a72c5665 `, pl.Variables.Manifest) assert.Equal(t, buildsVariables{ Manifest: pl.Variables.Manifest, // the manifest correctness is checked above, for nicer diff on error From 2459145150d5d9295ad922a22a6a9cc90c3b1d78 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Wed, 22 May 2024 12:59:41 +0200 Subject: [PATCH 4/4] add release-notes (cherry picked from commit 0e479f350206475f2a81fa4c0aac7d35fcfa8c01) --- release-notes/8.0.0/fix/3864.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 release-notes/8.0.0/fix/3864.md 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