Skip to content

Commit f7271a9

Browse files
committed
Add pipeline to use on tag release
Signed-off-by: Chmouel Boudjnah <[email protected]>
1 parent 693bd65 commit f7271a9

File tree

6 files changed

+435
-122
lines changed

6 files changed

+435
-122
lines changed

.goreleaser.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# This is an example goreleaser.yaml file with some sane defaults.
2+
# Make sure to check the documentation at http://goreleaser.com
3+
builds:
4+
- env:
5+
- CGO_ENABLED=0
6+
main: ./cmd/tkn-pac
7+
binary: tkn-pac
8+
goos:
9+
- linux
10+
- darwin
11+
- windows
12+
goarch:
13+
- amd64
14+
archives:
15+
- name_template: "{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
16+
replacements:
17+
darwin: Darwin
18+
linux: Linux
19+
windows: Windows
20+
386: i386
21+
amd64: x86_64
22+
format_overrides:
23+
- goos: windows
24+
format: zip
25+
checksum:
26+
name_template: 'checksums.txt'
27+
snapshot:
28+
name_template: "{{ .Tag }}-next"
29+
changelog:
30+
sort: asc
31+
filters:
32+
exclude:
33+
- '^docs:'
34+
- '^test:'
35+
- Merge pull request
36+
- Merge branch
37+
release:
38+
prerelease: true
39+
header: |
40+
## OpenShift Pipelines version $VERSION
41+
42+
OpenShift Pipelines as Code version has been released 🥳
43+
44+
To install this version you can just do :
45+
46+
```shell
47+
kubectl apply -f https://raw.githubusercontent.com/openshift-pipelines/pipelines-as-code/release-$VERSION/release-$VERSION.yaml
48+
```
49+
50+
and make sure you follow the setup documentation :
51+
52+
https://github.com/openshift-pipelines/pipelines-as-code/tree/main/INSTALL.md
53+
54+
brews:
55+
- name: tektoncd-pac
56+
tap:
57+
owner: openshift-pipelines
58+
name: homebrew-pipelines-as-code
59+
folder: Formula
60+
dependencies:
61+
- name: tektoncd-cli
62+
type: optional
63+
- name: git
64+
homepage: "https://github.com/openshift-pipelines/pipelines-as-code"
65+
description: Tekton PAC - The command line interface for interacting with Pipelines as Code
66+
install: |
67+
bin.install "tkn-pac" => "tkn-pac"
68+
output = Utils.popen_read("SHELL=bash #{bin}/tkn-pac completion bash")
69+
(bash_completion/"tkn-pac").write output
70+
output = Utils.popen_read("SHELL=zsh #{bin}/tkn-pac completion zsh")
71+
(zsh_completion/"_tkn-pac").write output
72+
prefix.install_metafiles
73+
nfpms:
74+
- file_name_template: "tektoncd-cli-{{.Version}}_{{.Os}}-{{.Arch}}"
75+
homepage: https://github.com/openshift-pipelines/pipelines-as-code
76+
description: Command line interface to OpenShift Pipelines as Code
77+
maintainer: OpenShift Pipelines Developers <[email protected]>
78+
license: BSD
79+
vendor: Red Hat
80+
formats:
81+
- deb
82+
- rpm
83+
bindir: /usr/bin
84+
replacements:
85+
amd64: 64bit
86+
386: 32bit
87+
arm: ARM
88+
arm64: ARM64
89+
darwin: macOS
90+
linux: Linux
91+
windows: Windows

.tekton/release-pipeline.yaml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
apiVersion: tekton.dev/v1beta1
3+
kind: PipelineRun
4+
metadata:
5+
name: release-pipeline
6+
annotations:
7+
pipelinesascode.tekton.dev/on-event: "[push]"
8+
pipelinesascode.tekton.dev/on-target-branch: "[refs/tags/*]"
9+
pipelinesascode.tekton.dev/task: "[git-clone, .tekton/tasks/goreleaser.yaml]"
10+
pipelinesascode.tekton.dev/max-keep-runs: "5"
11+
spec:
12+
params:
13+
- name: repo_url
14+
value: "{{repo_url}}"
15+
- name: revision
16+
value: "{{revision}}"
17+
pipelineSpec:
18+
params:
19+
- name: repo_url
20+
- name: revision
21+
workspaces:
22+
- name: source
23+
tasks:
24+
- name: fetch-repository
25+
taskRef:
26+
name: git-clone
27+
workspaces:
28+
- name: output
29+
workspace: source
30+
params:
31+
- name: url
32+
value: $(params.repo_url)
33+
- name: revision
34+
value: $(params.revision)
35+
- name: release-yaml
36+
runAfter:
37+
- fetch-repository
38+
workspaces:
39+
- name: source
40+
workspace: source
41+
taskSpec:
42+
workspaces:
43+
- name: source
44+
steps:
45+
- name: push-release-to-branch
46+
image: registry.access.redhat.com/ubi8/python-39:latest
47+
workingDir: $(workspaces.source.path)
48+
env:
49+
- name: HUB_TOKEN
50+
valueFrom:
51+
secretKeyRef:
52+
name: "nightly-ci-github-hub-token"
53+
key: "hub-token"
54+
script: |
55+
#!/usr/bin/env bash
56+
set -euf
57+
set -x
58+
git fetch --tag -v
59+
version=$(git --no-pager tag --points-at HEAD)
60+
[[ -z ${version} ]] && {
61+
echo "No tags detected"
62+
exit
63+
}
64+
msg="Release version ${version}"
65+
echo ${msg}
66+
export TARGET_BRANCH=${version}
67+
hack/upload-file-to-github.py \
68+
--message "Release yaml generated for Release ${TARGET_BRANCH}" \
69+
--owner-repository openshift-pipelines/pipelines-as-code \
70+
--token ${HUB_TOKEN} \
71+
--from-tag=refs/tags/${TARGET_BRANCH} \
72+
-d release-${TARGET_BRANCH}.yaml -f <(./hack/generate-releaseyaml.sh)
73+
exit 0
74+
- name: gorelease
75+
runAfter:
76+
- release-yaml
77+
taskRef:
78+
name: goreleaser
79+
params:
80+
- name: package
81+
value: github.com/openshift-pipelines/pipelines-as-code
82+
- name: github-token-secret
83+
value: "nightly-ci-github-hub-token"
84+
- name: github-token-secret-key
85+
value: "hub-token"
86+
workspaces:
87+
- name: source
88+
workspace: source
89+
workspaces:
90+
- name: source
91+
volumeClaimTemplate:
92+
spec:
93+
accessModes:
94+
- ReadWriteOnce
95+
resources:
96+
requests:
97+
storage: 1Gi

.tekton/tasks/goreleaser.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
apiVersion: tekton.dev/v1beta1
2+
kind: Task
3+
metadata:
4+
name: goreleaser
5+
labels:
6+
app.kubernetes.io/version: "0.1"
7+
annotations:
8+
tekton.dev/pipelines.minVersion: "0.12.1"
9+
tekton.dev/tags: golang, release-automation, package
10+
tekton.dev/displayName: "GoReleaser"
11+
spec:
12+
description: >-
13+
GoReleaser builds Go binaries for several platforms.
14+
15+
It creates a GitHub release and then pushes a Homebrew formula to a tap repository.
16+
workspaces:
17+
- name: source
18+
mountPath: /workspace/src/$(params.package)
19+
description: >-
20+
The workspace containing the Go source code
21+
which needs to be released.
22+
params:
23+
- name: package
24+
description: base package to build in
25+
- name: github-token-secret
26+
description: name of the secret holding the github-token
27+
default: bot-token-github
28+
- name: github-token-secret-key
29+
description: name of the secret key holding the github-token
30+
default: bot-token
31+
- name: flags
32+
description: flags to pass to `goreleaser release`
33+
default: --timeout=30m
34+
steps:
35+
- name: pull
36+
image: docker.io/goreleaser/goreleaser
37+
workingDir: $(workspaces.source.path)
38+
script: |
39+
git status; git fetch -p --all
40+
- name: release
41+
image: docker.io/goreleaser/goreleaser
42+
workingDir: $(workspaces.source.path)
43+
script: |
44+
goreleaser release $(params.flags)
45+
env:
46+
- name: GOPATH
47+
value: /workspace
48+
- name: GITHUB_TOKEN
49+
valueFrom:
50+
secretKeyRef:
51+
name: $(params.github-token-secret)
52+
key: $(params.github-token-secret-key)

INSTALL.MD

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Install
2+
3+
## Pipelines as Code Install
4+
5+
To install Pipelines as Code on your server you simply need to run this command :
6+
7+
```shell
8+
VERSION=0.1
9+
kubectl apply -f https://raw.githubusercontent.com/openshift-pipelines/pipelines-as-code/release-$VERSION/release-$VERSION.yaml
10+
```
11+
12+
If you would like to install the current developement version you can simply install it like this :
13+
14+
```shell
15+
kubectl apply -f https://raw.githubusercontent.com/openshift-pipelines/pipelines-as-code/nightly/release.yaml
16+
```
17+
18+
It will apply the release.yaml to your kubernetes cluster, creating the
19+
admin namespace `pipelines-as-code`, the roles and all other bits needed.
20+
21+
The `pipelines-as-code` namespace is where all the admin pipelinerun are run,
22+
they are supposed to be accesible only by the admin.
23+
24+
You will need then to have events from github or others coming through to your
25+
EventListenner so follow the next steps on how to do that.
26+
27+
### Github configuration
28+
29+
To setup Pipelines as Code on Github, you need to have a Github App created.
30+
31+
You need the Webhook of the app pointing to your Ingress endpoint which would
32+
then go to the triggers enventlistenner/service.
33+
34+
You need to make sure you have those permissions and events checked on the
35+
GitHub app :
36+
37+
```json
38+
"default_permissions": {
39+
"checks": "write",
40+
"contents": "write",
41+
"issues": "write",
42+
"members": "read",
43+
"metadata": "read",
44+
"organization_plan": "read",
45+
"pull_requests": "write"
46+
},
47+
"default_events": [
48+
"commit_comment",
49+
"issue_comment",
50+
"pull_request",
51+
"pull_request_review",
52+
"pull_request_review_comment",
53+
"push"
54+
]
55+
```
56+
57+
When you have created the `github-app-secret` Secret, grab the private key the
58+
`application_id` and the `webhook_secret` from the interface, place the private
59+
key in a file named for example `/tmp/github.app.key` and issue those commands :
60+
61+
```bash
62+
% kubectl -n pipelines-as-code create secret generic github-app-secret \
63+
--from-literal private.key="$(cat /tmp/github.app.key)"
64+
--from-literal application_id="APPLICATION_ID_NUMBER" \
65+
--from-literal webhook.secret="WEBHOOK_SECRET"
66+
```
67+
68+
This secret is used to generate a token on behalf of the user running the event
69+
and make sure to validate the webhook via the webhook secret.
70+
71+
You will then need to make sure to expose the `EventListenner` via a
72+
[Ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/) or a
73+
[OpenShift
74+
Route](https://docs.openshift.com/container-platform/latest/networking/routes/route-configuration.html)
75+
so GitHub can get send the webhook to it.
76+
77+
### GitHub Enteprise
78+
79+
Pipelines as Code supports Github Enterprise.
80+
81+
You don't need to do anything special to get Pipelines as code working with GHE.
82+
Pipelines as code will automatically detects the header as set from GHE and use it the GHE API auth url instead of the public github.
83+
84+
## Configuration
85+
86+
There is a few things you can configure via the configmap `pipelines-as-code` in
87+
the `pipelines-as-code` namespace.
88+
89+
- **application-name**: The name of the application showing for example in the
90+
GitHub Checks labels. Default to `"Pipelines as Code"`
91+
- **max-keep-days**: The number of the day to keep the PR runs in the
92+
`pipelines-as-code` namespace, see below for more details about it..
93+
94+
### PR cleanups in pipelines-as-code admin namespace
95+
96+
We install by default a cron that cleanups the PR generated on events in pipelines-as-code
97+
namespace. The crons runs every hour and by default cleanups pipelineruns over a
98+
day. If you would like to change the max number of days to keep you can change the
99+
key `max-keep-days` in the `pipelines-as-code` configmap. This configmap
100+
setting doens't affect the cleanups of the user's PR controlled by the
101+
annotations.
102+
103+
## OpenShift Pipelines CLI
104+
105+
OpenShift Pipelines CLI offer a easy to use CLI to manage your repositories status.
106+
107+
## Binary releases
108+
109+
You can grab the latest binary directly from the
110+
[releases](https://github.com/openshift-pipelines/pipelines-as-code/releases)
111+
page.
112+
113+
## Dev release
114+
115+
If you want to install from the git repository you can just do :
116+
117+
```shell
118+
go install github.com/openshift-pipelines/pipelines-as-code/cmd/tkn-pac
119+
```
120+
121+
## Brew release
122+
123+
On LinuxBrew or OSX brew you can simply add the tap :
124+
125+
```shell
126+
brew install openshift-pipelines/pipelines-as-code/tektoncd-pac
127+
```

0 commit comments

Comments
 (0)