chore: update pipeline to merge and tag release

This commit is contained in:
2023-09-25 21:26:24 -06:00
parent f38ad5ecaf
commit cd329a4ce8
3 changed files with 145 additions and 1 deletions

View File

@@ -299,6 +299,25 @@ spec:
value: $(params.git-merge-delete-branch) value: $(params.git-merge-delete-branch)
- name: TARGET_URL - name: TARGET_URL
value: https://console-openshift-console.apps.ocp.endofday.com/pipelines value: https://console-openshift-console.apps.ocp.endofday.com/pipelines
- name: create-git-release
runAfter: ["pass-pr-check"]
taskRef:
name: gitea-create-release
params:
- name: SHA
value: $(params.git-commit-sha)
- name: GITEA_HOST_URL
value: git.endofday.com
- name: REPO_FULL_NAME
value: $(params.git-repo-full-name)
- name: GITEA_TOKEN_SECRET_NAME
value: $(params.git-token-secret-name)
- name: GITEA_TOKEN_SECRET_KEY
value: $(params.git-token-secret-key)
- name: TAG
value: $(tasks.git-semver.results.version)
- name: TITLE
value: "$(params.git-repo-full-name)-$(tasks.git-semver.results.version)"
finally: finally:
- name: fail-pr-check - name: fail-pr-check
when: when:

View File

@@ -0,0 +1,125 @@
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: gitea-create-release
namespace: goghvideo-cicd-pipeline
spec:
description: |-
This task will merge a PR and delete the branch.
params:
- name: GITEA_HOST_URL
description: |
The Gitea host, e.g: git.yourcompany.com. Can include port.
type: string
- name: GITEA_HTTPS_OR_HTTP
default: https
description: |
If we should connect with HTTP or HTTPS. Use "http" or "https" here.
type: string
- name: API_PATH_PREFIX
default: /api/v1
description: |
The API path prefix of Gitea, default: /api/v1
type: string
- name: REPO_FULL_NAME
description: |
The Gitea repository full name, e.g.: tektoncd/catalog
type: string
- name: GITEA_TOKEN_SECRET_NAME
default: gitea
description: |
The name of the kubernetes secret that contains the Gitea token, default: gitea
type: string
- name: GITEA_TOKEN_SECRET_KEY
default: token
description: |
The key within the kubernetes secret that contains the Gitea token, default: token
type: string
- name: IMAGE
default: python:3.10.1-alpine3.15@sha256:affe0faa14e7553fc570beec3864e74b5e36f8c19b2bb49ae8ba79c0e9e7236e
description: |
Image providing the python binary which this task uses.
type: string
- name: TITLE
description: Main title of release
type: string
- name: TAG
description: Version tag
type: string
- name: SHEBANG
default: /usr/bin/env python
description: |
Python path. Depends on the image.
type: string
- name: SHA
description: |
The SHA of the merge commit
type: string
steps:
- image: $(params.IMAGE)
name: create-git-release
script: |
#!$(params.SHEBANG)
"""This script will create a git release tag"""
import json
import sys
import http.client
gitea_token = open("/etc/gitea-set-status/$(params.GITEA_TOKEN_SECRET_KEY)", "r").read()
merge_url = "$(params.API_PATH_PREFIX)" + "/repos/$(params.REPO_FULL_NAME)/" + \
"releases"
data = {
"name": "$(params.TITLE)",
"tagname": "$(params.TAG)",
"target_commitish": "$(params.SHA)"
}
print("Sending this data to Gitea: ")
print(data)
authHeader = "token " + gitea_token
if "$(params.GITEA_HTTPS_OR_HTTP)" == "https":
conn = http.client.HTTPSConnection("$(params.GITEA_HOST_URL)")
else:
conn = http.client.HTTPConnection("$(params.GITEA_HOST_URL)")
conn.request(
"POST",
merge_url,
body=json.dumps(data),
headers={
"User-Agent": "TektonCD, the peaceful cat",
"Authorization": authHeader,
"Accept": "application/json",
"Content-Type": "application/json",
})
resp = conn.getresponse()
if not str(resp.status).startswith("2"):
print("Error: %d" % (resp.status))
print(resp.read())
sys.exit(1)
else:
print("Create release completed on $(params.REPO_FULL_NAME)")
volumeMounts:
- mountPath: /etc/gitea-set-status
name: giteatoken
volumes:
- name: giteatoken
secret:
secretName: $(params.GITEA_TOKEN_SECRET_NAME)

View File

@@ -52,7 +52,7 @@ spec:
- name: git-token-secret-key - name: git-token-secret-key
value: password value: password
- name: git-merge-type - name: git-merge-type
value: squash value: merge
- name: git-merge-delete-branch - name: git-merge-delete-branch
value: True value: True
- name: git-helm-url - name: git-helm-url