Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for release event (Github, Gitea, Gitlab) #764

Closed
wants to merge 52 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
341c81e
Auto commit @ 2022-02-08T17:03:18Z
Feb 8, 2022
adcae0b
Auto commit @ 2022-02-08T17:18:38Z
Feb 8, 2022
bb4b36a
Auto commit @ 2022-02-08T17:21:36Z
Feb 8, 2022
8ffb392
Merge branch 'master' into github_release_event
LamaAni Feb 8, 2022
571b5d7
Auto commit @ 2022-02-08T19:56:55Z
Feb 8, 2022
1fbd411
Auto commit @ 2022-02-08T20:02:45Z
Feb 8, 2022
3536eb0
Auto commit @ 2022-02-08T21:47:49Z
Feb 8, 2022
c1a4680
Auto commit @ 2022-02-08T21:55:25Z
Feb 8, 2022
b175b8f
Merge branch 'master' into github_release_event
LamaAni Feb 9, 2022
01e8638
Merge branch 'github_release_event' of github.com:LamaAni/woodpecker …
Feb 9, 2022
679d977
Merge remote-tracking branch 'public/master' into github_release_event
Feb 9, 2022
351a429
Auto commit @ 2022-02-10T00:03:02Z
Feb 10, 2022
ac63f6a
Auto commit @ 2022-02-10T00:03:25Z
Feb 10, 2022
af5e7f5
Auto commit @ 2022-02-10T00:16:25Z
Feb 10, 2022
7b8d1fc
Auto commit @ 2022-02-10T00:31:53Z
Feb 10, 2022
ac1e5bc
Auto commit @ 2022-02-10T00:33:54Z
Feb 10, 2022
e834b8b
Merge branch 'master' into github_release_event
LamaAni Feb 10, 2022
5348a1c
Merge remote-tracking branch 'public/master'
Feb 16, 2022
6d8e019
Auto commit @ 2022-02-16T18:09:27Z
Feb 16, 2022
5651ff4
Merge branch 'master' into github_release_event
LamaAni Feb 22, 2022
b01ddf4
Merge remote-tracking branch 'public/master'
Feb 22, 2022
64ebd6e
Auto commit @ 2022-02-22T16:15:12Z
Feb 22, 2022
a9300b7
Merge branch 'master' into github_release_event
LamaAni Feb 23, 2022
e5ad2f5
Merge branch 'master' of github.com:LamaAni/woodpecker
Feb 28, 2022
e38919c
Auto commit @ 2022-02-28T21:24:15Z
Feb 28, 2022
aa73b3e
Merge remote-tracking branch 'public/master'
Feb 28, 2022
4570698
Auto commit @ 2022-02-28T23:02:48Z
Feb 28, 2022
f653e00
Merge branch 'master' into github_release_event
Mar 1, 2022
ed931fe
Merge remote-tracking branch 'public/master' into github_release_event
Mar 1, 2022
b73998f
Merge branch 'github_release_event' of github.com:LamaAni/woodpecker …
Mar 1, 2022
cc69a92
Auto commit @ 2022-03-01T17:19:33Z
Mar 1, 2022
6965a38
Auto commit @ 2022-03-01T17:52:50Z
Mar 1, 2022
8a95a0b
Auto commit @ 2022-03-01T18:00:16Z
Mar 1, 2022
c89ea87
Merge remote-tracking branch 'public/master' into github_release_event
Mar 1, 2022
04c5a0d
Auto commit @ 2022-03-02T00:11:36Z
Mar 2, 2022
2abcd3c
Auto commit @ 2022-03-02T00:38:27Z
Mar 2, 2022
58853d4
Auto commit @ 2022-03-02T17:02:32Z
Mar 2, 2022
8482b4e
Merge remote-tracking branch 'public/master' into github_release_event
Mar 2, 2022
9a2764d
Auto commit @ 2022-03-02T17:03:45Z
Mar 2, 2022
b71ef60
Auto commit @ 2022-03-02T17:15:14Z
Mar 2, 2022
4ab3cbb
Merge branch 'master' into github_release_event
LamaAni Mar 2, 2022
e8336cb
Auto commit @ 2022-03-02T18:47:06Z
Mar 2, 2022
aeba27d
Auto commit @ 2022-03-03T00:30:46Z
Mar 3, 2022
cfd70e5
Auto commit @ 2022-03-03T00:31:15Z
Mar 3, 2022
973b318
Auto commit @ 2022-03-03T02:22:25Z
Mar 3, 2022
2064e66
Merge branch 'master' into github_release_event
LamaAni Mar 3, 2022
17676a9
Update docs/docs/30-administration/11-vcs/10-overview.md
LamaAni Mar 3, 2022
dd401c8
Update server/remote/gitea/helper.go
LamaAni Mar 3, 2022
cfc2d83
Update server/remote/gitea/helper.go
6543 Mar 3, 2022
a14146a
Merge branch 'master' into github_release_event
6543 May 17, 2022
05a4463
Merge branch 'master' into github_release_event
6543 May 30, 2022
9a823b2
Merge branch 'master' into github_release_event
6543 Aug 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/secret/secret_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,6 @@ func secretCreate(c *cli.Context) error {
var defaultSecretEvents = []string{
woodpecker.EventPush,
woodpecker.EventTag,
woodpecker.EventRelease,
woodpecker.EventDeploy,
}
6 changes: 6 additions & 0 deletions cmd/server/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ var flags = []cli.Flag{
Name: "github-skip-verify",
Usage: "github skip ssl verification",
},
&cli.StringFlag{
anbraten marked this conversation as resolved.
Show resolved Hide resolved
EnvVars: []string{"WOODPECKER_GITHUB_RELEASE_ACTIONS"},
Name: "github-release-actions",
Usage: "On which actions to trigger a release pipeline",
Value: "prereleased, released",
},
Comment on lines +274 to +279
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of limiting here I would suggest to inject an environment variable to each step CI_RELEASE_TYPE=draft,pre-release,release

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And adding some filter to the when options would be good too.

Copy link
Member

@anbraten anbraten Sep 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this could be pretty simple by introducing #312

//
// Gogs
//
Expand Down
17 changes: 12 additions & 5 deletions cmd/server/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"net/url"
"os"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -276,13 +277,19 @@ func setupGitlab(c *cli.Context) (remote.Remote, error) {

// helper function to setup the GitHub remote from the CLI arguments.
func setupGithub(c *cli.Context) (remote.Remote, error) {
releaseActions := regexp.
MustCompile(`[\s,]+`).
Split(c.String("github-release-actions"), -1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use c.Strings


opts := github.Opts{
URL: c.String("github-server"),
Client: c.String("github-client"),
Secret: c.String("github-secret"),
SkipVerify: c.Bool("github-skip-verify"),
MergeRef: c.Bool("github-merge-ref"),
URL: c.String("github-server"),
Client: c.String("github-client"),
Secret: c.String("github-secret"),
SkipVerify: c.Bool("github-skip-verify"),
MergeRef: c.Bool("github-merge-ref"),
ReleaseActions: releaseActions,
}

log.Trace().Msgf("Remote (github) opts: %#v", opts)
return github.New(opts)
}
Expand Down
1 change: 1 addition & 0 deletions docs/docs/30-administration/11-forges/10-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
| Event: Tag | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: | :x: |
| Event: Pull-Request | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: |
| Event: Deploy | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :x: |
| Event: Release | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: |
| OAuth | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| [Multi pipeline](/docs/usage/multi-pipeline) | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :x: |
| [when.path filter](/docs/usage/pipeline-syntax#path) | :white_check_mark: | :white_check_mark:¹ | :white_check_mark: | :x: | :x: | :x: | :x: |
Expand Down
14 changes: 14 additions & 0 deletions docs/docs/30-administration/11-forges/20-github.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,55 @@ Please use this screenshot for reference:
This is a full list of configuration options. Please note that many of these options use default configuration values that should work for the majority of installations.

### `WOODPECKER_GITHUB`

> Default: `false`

Enables the GitHub driver.

### `WOODPECKER_GITHUB_URL`

> Default: `https://github.com`

Configures the GitHub server address.

### `WOODPECKER_GITHUB_CLIENT`

> Default: empty

Configures the GitHub OAuth client id. This is used to authorize access.

### `WOODPECKER_GITHUB_CLIENT_FILE`

> Default: empty

Read the value for `WOODPECKER_GITHUB_CLIENT` from the specified filepath

### `WOODPECKER_GITHUB_SECRET`

> Default: empty

Configures the GitHub OAuth client secret. This is used to authorize access.

### `WOODPECKER_GITHUB_SECRET_FILE`

> Default: empty

Read the value for `WOODPECKER_GITHUB_SECRET` from the specified filepath

### `WOODPECKER_GITHUB_MERGE_REF`

> Default: `true`

TODO

### `WOODPECKER_GITHUB_SKIP_VERIFY`

> Default: `false`

Configure if SSL verification should be skipped.

### `WOODPECKER_GITHUB_RELEASE_ACTIONS`

> Default: `released, prereleased`

The actions to allow on release (trigger), comma seperated.
11 changes: 6 additions & 5 deletions pipeline/frontend/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (

// Event types corresponding to scm hooks.
const (
EventPush = "push"
EventPull = "pull_request"
EventTag = "tag"
EventDeploy = "deployment"
EventPush = "push"
EventPull = "pull_request"
EventTag = "tag"
EventDeploy = "deployment"
EventRelease = "release"
)

type (
Expand Down Expand Up @@ -187,7 +188,7 @@ func (m *Metadata) Environ() map[string]string {

"CI_SYSTEM_ARCH": m.Sys.Platform, // TODO: remove after next version
}
if m.Curr.Event == EventTag {
if m.Curr.Event == EventTag || m.Curr.Event == EventRelease {
params["CI_COMMIT_TAG"] = strings.TrimPrefix(m.Curr.Commit.Ref, "refs/tags/")
}
if m.Curr.Event == EventPull {
Expand Down
6 changes: 5 additions & 1 deletion server/api/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ func PostHook(c *gin.Context) {
// wrapped in square brackets appear in the commit message
skipMatch := skipRe.FindString(tmpBuild.Message)
if len(skipMatch) > 0 {
msg := fmt.Sprintf("ignoring hook: %s found in %s", skipMatch, tmpBuild.Commit)
ref := tmpBuild.Commit
if len(ref) == 0 {
ref = tmpBuild.Ref
}
msg := fmt.Sprintf("ignoring hook: %s found in %s", skipMatch, ref)
log.Debug().Msg(msg)
c.String(http.StatusNoContent, msg)
return
Expand Down
11 changes: 6 additions & 5 deletions server/model/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ package model
type WebhookEvent string

const (
EventPush WebhookEvent = "push"
EventPull WebhookEvent = "pull_request"
EventTag WebhookEvent = "tag"
EventDeploy WebhookEvent = "deployment"
EventPush WebhookEvent = "push"
EventPull WebhookEvent = "pull_request"
EventTag WebhookEvent = "tag"
EventDeploy WebhookEvent = "deployment"
EventRelease WebhookEvent = "release"
)

func ValidateWebhookEvent(s WebhookEvent) bool {
switch s {
case EventPush, EventPull, EventTag, EventDeploy:
case EventPush, EventPull, EventTag, EventDeploy, EventRelease:
return true
default:
return false
Expand Down
76 changes: 76 additions & 0 deletions server/remote/gitea/fixtures/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,79 @@ const HookPullRequest = `{
"avatar_url": "https://secure.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87"
}
}`

const HookRelease = `
{
"action": "published",
"release": {
"id": 48,
"tag_name": "0.0.5",
"target_commitish": "main",
"name": "Version 0.0.5",
"body": "",
"url": "https://git.xxx/api/v1/repos/anbraten/demo/releases/48",
"html_url": "https://git.xxx/anbraten/demo/releases/tag/0.0.5",
"tarball_url": "https://git.xxx/anbraten/demo/archive/0.0.5.tar.gz",
"zipball_url": "https://git.xxx/anbraten/demo/archive/0.0.5.zip",
"draft": false,
"prerelease": false,
"created_at": "2022-02-09T20:23:05Z",
"published_at": "2022-02-09T20:23:05Z",
"author": {"id":1,"login":"anbraten","full_name":"Anton Bracke","email":"anbraten@noreply.xxx","avatar_url":"https://git.xxx/user/avatar/anbraten/-1","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2018-03-21T10:04:48Z","restricted":false,"active":false,"prohibit_login":false,"location":"world","website":"https://xxx","description":"","visibility":"public","followers_count":1,"following_count":1,"starred_repos_count":1,"username":"anbraten"},
"assets": []
},
"repository": {
"id": 77,
"owner": {"id":1,"login":"anbraten","full_name":"Anton Bracke","email":"anbraten@noreply.xxx","avatar_url":"https://git.xxx/user/avatar/anbraten/-1","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2018-03-21T10:04:48Z","restricted":false,"active":false,"prohibit_login":false,"location":"world","website":"https://xxx","description":"","visibility":"public","followers_count":1,"following_count":1,"starred_repos_count":1,"username":"anbraten"},
"name": "demo",
"full_name": "anbraten/demo",
"description": "",
"empty": false,
"private": true,
"fork": false,
"template": false,
"parent": null,
"mirror": false,
"size": 59,
"html_url": "https://git.xxx/anbraten/demo",
"ssh_url": "ssh://git@git.xxx:22/anbraten/demo.git",
"clone_url": "https://git.xxx/anbraten/demo.git",
"original_url": "",
"website": "",
"stars_count": 0,
"forks_count": 1,
"watchers_count": 1,
"open_issues_count": 2,
"open_pr_counter": 2,
"release_counter": 4,
"default_branch": "main",
"archived": false,
"created_at": "2021-08-30T20:54:13Z",
"updated_at": "2022-01-09T01:29:23Z",
"permissions": {
"admin": true,
"push": true,
"pull": true
},
"has_issues": true,
"internal_tracker": {
"enable_time_tracker": true,
"allow_only_contributors_to_track_time": true,
"enable_issue_dependencies": true
},
"has_wiki": false,
"has_pull_requests": true,
"has_projects": true,
"ignore_whitespace_conflicts": false,
"allow_merge_commits": true,
"allow_rebase": true,
"allow_rebase_explicit": true,
"allow_squash_merge": true,
"default_merge_style": "squash",
"avatar_url": "",
"internal": false,
"mirror_interval": ""
},
"sender": {"id":1,"login":"anbraten","full_name":"Anbraten","email":"anbraten@noreply.xxx","avatar_url":"https://git.xxx/user/avatar/anbraten/-1","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2018-03-21T10:04:48Z","restricted":false,"active":false,"prohibit_login":false,"location":"World","website":"https://xxx","description":"","visibility":"public","followers_count":1,"following_count":1,"starred_repos_count":1,"username":"anbraten"}
}
`
47 changes: 35 additions & 12 deletions server/remote/gitea/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,40 @@ func buildFromPullRequest(hook *pullRequestHook) *model.Build {
return build
}

// helper function that extracts the Repository data from a Gitea push hook
func repoFromPush(hook *pushHook) *model.Repo {
return &model.Repo{
Name: hook.Repo.Name,
Owner: hook.Repo.Owner.Username,
FullName: hook.Repo.FullName,
Link: hook.Repo.URL,
func buildFromRelease(hook *releaseHook) *model.Build {
avatar := expandAvatar(
hook.Repo.URL,
fixMalformedAvatar(hook.Sender.Avatar),
)
author := hook.Sender.Login
if author == "" {
author = hook.Sender.Username
}
sender := hook.Sender.Username
if sender == "" {
sender = hook.Sender.Login
}

return &model.Build{
Event: model.EventRelease,
Ref: fmt.Sprintf("refs/tags/%s", hook.Release.TagName),
Link: fmt.Sprintf("%s/src/tag/%s", hook.Repo.URL, hook.Release.TagName),
Branch: fmt.Sprintf("refs/tags/%s", hook.Release.TagName),
Message: fmt.Sprintf("created release %s", hook.Release.Name),
Avatar: avatar,
Author: author,
Sender: sender,
Timestamp: time.Now().UTC().Unix(),
}
}

// helper function that extracts the Repository data from a Gitea pull_request hook
func repoFromPullRequest(hook *pullRequestHook) *model.Repo {
func repoFromHook(repo *giteaRepo) *model.Repo {
return &model.Repo{
Name: hook.Repo.Name,
Owner: hook.Repo.Owner.Username,
FullName: hook.Repo.FullName,
Link: hook.Repo.URL,
Name: repo.Name,
Owner: repo.Owner.Username,
FullName: repo.FullName,
Link: repo.URL,
}
}

Expand All @@ -209,6 +226,12 @@ func parsePullRequest(r io.Reader) (*pullRequestHook, error) {
return pr, err
}

func parseRelease(r io.Reader) (*releaseHook, error) {
pr := new(releaseHook)
err := json.NewDecoder(r).Decode(pr)
return pr, err
}

// fixMalformedAvatar is a helper function that fixes an avatar url if malformed
// (currently a known bug with gitea)
func fixMalformedAvatar(url string) string {
Expand Down
4 changes: 2 additions & 2 deletions server/remote/gitea/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func Test_parse(t *testing.T) {
g.It("Should return a Repo struct from a push hook", func() {
buf := bytes.NewBufferString(fixtures.HookPush)
hook, _ := parsePush(buf)
repo := repoFromPush(hook)
repo := repoFromHook(&hook.Repo)
g.Assert(repo.Name).Equal(hook.Repo.Name)
g.Assert(repo.Owner).Equal(hook.Repo.Owner.Username)
g.Assert(repo.FullName).Equal("gordon/hello-world")
Expand Down Expand Up @@ -150,7 +150,7 @@ func Test_parse(t *testing.T) {
g.It("Should return a Repo struct from a pull_request hook", func() {
buf := bytes.NewBufferString(fixtures.HookPullRequest)
hook, _ := parsePullRequest(buf)
repo := repoFromPullRequest(hook)
repo := repoFromHook(&hook.Repo)
g.Assert(repo.Name).Equal(hook.Repo.Name)
g.Assert(repo.Owner).Equal(hook.Repo.Owner.Username)
g.Assert(repo.FullName).Equal("gordon/hello-world")
Expand Down
Loading