22apiVersion : tekton.dev/v1beta1
33kind : PipelineRun
44metadata :
5- name : doc-generation
5+ name : doc-deployment
66 annotations :
77 pipelinesascode.tekton.dev/max-keep-runs : " 2"
88 pipelinesascode.tekton.dev/cancel-in-progress : " true"
9- pipelinesascode.tekton.dev/on-event : " pull_request"
10- pipelinesascode.tekton.dev/on-path-change : " [docs/***]"
11- pipelinesascode.tekton.dev/on-target-branch : " main"
9+ pipelinesascode.tekton.dev/on-cel-expression : |
10+ event == "push" && (
11+ (target_branch == "main" && "docs/***".pathChanged()) ||
12+ target_branch.startsWith("refs/tags/")
13+ ) ||
14+ (event == "pull_request" && "docs/***".pathChanged())
1215spec :
1316 params :
1417 - name : repo_url
@@ -17,13 +20,16 @@ spec:
1720 value : " {{revision}}"
1821 - name : hugo_version
1922 value : " 0.146.0"
23+ - name : wrangler_version
24+ value : " 4.72.0"
2025 pipelineSpec :
2126 params :
2227 - name : repo_url
2328 - name : revision
2429 - name : hugo_version
30+ - name : wrangler_version
2531 tasks :
26- - name : build -doc
32+ - name : deploy -doc
2733 taskSpec :
2834 workspaces :
2935 - name : source
5662 value : $(workspaces.source.path)/tmp/hugo
5763 - name : workingdir
5864 value : $(workspaces.source.path)
59-
60- - name : hugo-gen
65+ - name : hugo-build
6166 image : docker.io/golang:1.25
6267 workingDir : $(workspaces.source.path)
63- env :
64- - name : UPLOADER_PUBLIC_URL
65- valueFrom :
66- secretKeyRef :
67- name : " uploader-upload-credentials"
68- key : " public_url"
6968 script : |
7069 #!/usr/bin/env bash
7170 set -xeuo pipefail
@@ -76,37 +75,56 @@ spec:
7675 echo "Hugo was not downloaded properly" && exit 1
7776 }
7877 cd $(git rev-parse --show-toplevel)/docs
79- url="${UPLOADER_PUBLIC_URL}/docs/{{ pull_request_number }}"
80- ${hugobin} build --gc --minify -d {{ pull_request_number }} -b ${url}
81- echo "Preview URL: ${url}"
82- - name : upload-to-static-server
83- # it has curl and we already pulled it
84- image : docker.io/curlimages/curl
78+ ${hugobin} build --gc --minify
79+ - name : deploy
80+ image : docker.io/node:20-slim
8581 workingDir : $(workspaces.source.path)
8682 env :
87- - name : HUB_TOKEN
83+ - name : CLOUDFLARE_API_TOKEN
8884 valueFrom :
8985 secretKeyRef :
90- name : " nightly-ci-github-hub-token "
91- key : " hub -token"
92- - name : UPLOADER_UPLOAD_CREDENTIALS
86+ name : cloudflare-creds
87+ key : api -token
88+ - name : CLOUDFLARE_ACCOUNT_ID
9389 valueFrom :
9490 secretKeyRef :
95- name : " uploader-upload-credentials"
96- key : " credentials"
97- - name : UPLOADER_PUBLIC_URL
91+ name : cloudflare-creds
92+ key : account-id
93+ script : |
94+ #!/usr/bin/env bash
95+ set -euo pipefail
96+ pull_request_number="{{pull_request_number}}"
97+ git_tag="{{git_tag}}"
98+ target_branch="{{target_branch}}"
99+
100+ if [[ -n "${pull_request_number}" ]]; then
101+ branch="pr-${pull_request_number}"
102+ elif [[ -n "${git_tag}" ]]; then
103+ branch="${git_tag}"
104+ else
105+ branch="${target_branch}"
106+ fi
107+ cd docs/public
108+ npx --yes "wrangler@$(params.wrangler_version)" pages deploy . \
109+ --project-name='pipelines-as-code' \
110+ --branch="${branch}"
111+ - name : post-preview-status
112+ image : docker.io/curlimages/curl
113+ env :
114+ - name : HUB_TOKEN
98115 valueFrom :
99116 secretKeyRef :
100- name : " uploader-upload-credentials "
101- key : " public_url "
117+ name : " nightly-ci-github-hub-token "
118+ key : " hub-token "
102119 script : |
103- cd docs
104- test -d "{{ pull_request_number }}" || exit 0
105- tar czf - "{{ pull_request_number }}" | curl -u ${UPLOADER_UPLOAD_CREDENTIALS} -F path=docs -F targz=true -X POST -F file=@- http://uploader:8080/upload
106- # Post as status
120+ pull_request_number="{{pull_request_number}}"
121+ [[ -z "${pull_request_number}" ]] && exit 0
122+ preview_url="https://pr-${pull_request_number}.pipelines-as-code-4ko.pages.dev"
107123 set +x
108- curl -H "Authorization: Bearer ${HUB_TOKEN}" -H 'Accept: application/vnd.github.v3+json' -X POST https://api.github.com/repos/{{repo_owner}}/{{repo_name}}/statuses/{{revision}} -d \
109- "{\"state\": \"success\", \"target_url\": \"${UPLOADER_PUBLIC_URL}/docs/{{ pull_request_number }}\", \"description\": \"Generated with brio.\", \"context\": \"Pipelines as Code Preview URL\"}"
124+ curl -s -H "Authorization: Bearer ${HUB_TOKEN}" \
125+ -H 'Accept: application/vnd.github.v3+json' \
126+ -X POST "https://api.github.com/repos/{{repo_owner}}/{{repo_name}}/statuses/{{revision}}" \
127+ -d "{\"state\": \"success\", \"target_url\": \"${preview_url}\", \"description\": \"Documentation Preview\", \"context\": \"Pipelines as Code Preview URL\"}"
110128 - name : cache-upload
111129 ref :
112130 resolver : http
@@ -118,6 +136,8 @@ spec:
118136 value : ["$(workspaces.source.path)/README.md"]
119137 - name : target
120138 value : oci://image-registry.openshift-image-registry.svc:5000/$(context.pipelineRun.namespace)/cache-hugo:v$(params.hugo_version)
139+ - name : fetched
140+ value : $(steps.cache-fetch.results.fetched)
121141 - name : cachePath
122142 value : $(workspaces.source.path)/tmp/hugo
123143 - name : workingdir
0 commit comments