Repository navigation
131 lines (121 loc) · 4.62 KB
/
Copy pathhelm-publish.yml
File metadata and controls
131 lines (121 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: Helm Publish
# 版本标签 v* 上把 deploy/helm/octop 打成包,推到与镜像相同的 GHCR。
# 不另建 HTTP Helm 仓库。安装地址:
# oci://ghcr.io/tencentcloud/octop/charts/octop
#
# Chart 源码仍在仓库里。克隆后用目录安装;没有仓库的机器用上面的 OCI 地址。
# 推送时改写版本,不把改写提交回 git:
# appVersion = 镜像 tag(v1.0.3b5 → 1.0.3b5)
# version = Helm SemVer(1.0.3b5 → 1.0.3-b5,1.0.3 保持 1.0.3)
#
# 触发路径与 docker-publish.yml 相同:
# 1. 人工推送 v* tag → on.push.tags
# 2. Auto Tag 用 GITHUB_TOKEN 推 tag 后显式 workflow_dispatch(token push 不会触发 push 工作流)
# 3. 在任意 ref 上 Run workflow,填 tag=vX.Y.Z。版本以输入的 tag 为准,并检出该 tag。
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "v* tag to publish (e.g. v1.0.3b5). Required when not running on a tag."
required: false
type: string
permissions:
contents: read
packages: write
jobs:
publish:
name: Push chart to GHCR
runs-on: ubuntu-latest
if: >-
startsWith(github.ref, 'refs/tags/v')
|| (github.event_name == 'workflow_dispatch' && startsWith(inputs.tag, 'v'))
steps:
- name: Resolve version from tag ref
id: ver
env:
DISPATCH_TAG: ${{ inputs.tag }}
run: |
set -euo pipefail
if [ -n "${DISPATCH_TAG:-}" ]; then
ref="$DISPATCH_TAG"
else
ref="${GITHUB_REF_NAME}"
fi
case "$ref" in
v*)
version="${ref#v}"
;;
*)
echo "::error::Expected v* tag, got ref=$ref"
exit 1
;;
esac
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "tag=$ref" >> "$GITHUB_OUTPUT"
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ steps.ver.outputs.tag }}
- name: Set up Helm
uses: azure/setup-helm@v4
with:
version: v3.17.3
- name: Set chart version from the release tag
env:
OCTOP_VERSION: ${{ steps.ver.outputs.version }}
run: |
set -euo pipefail
python3 - << 'PY'
import os
import re
from pathlib import Path
image_tag = os.environ["OCTOP_VERSION"]
match = re.fullmatch(r"(\d+\.\d+\.\d+)([A-Za-z].*)?", image_tag)
if match is None:
raise SystemExit(f"unsupported version {image_tag}")
base, pre = match.group(1), match.group(2)
chart_version = f"{base}-{pre}" if pre else base
path = Path("deploy/helm/octop/Chart.yaml")
text = path.read_text()
text = re.sub(r"(?m)^version:.*$", f"version: {chart_version}", text, count=1)
text = re.sub(r'(?m)^appVersion:.*$', f'appVersion: "{image_tag}"', text, count=1)
path.write_text(text)
print(f"chart {chart_version}, image tag {image_tag}")
PY
- name: Lint and package
run: |
set -euo pipefail
helm lint deploy/helm/octop
helm package deploy/helm/octop --destination /tmp/octop-chart
- name: Log in to GHCR
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io \
--username "${{ github.actor }}" --password-stdin
- name: Push chart
env:
GHCR: ghcr.io/${{ github.repository }}
run: |
set -euo pipefail
registry="$(echo "$GHCR" | tr '[:upper:]' '[:lower:]')"
helm push /tmp/octop-chart/octop-*.tgz "oci://${registry}/charts"
# gh api percent-encodes the path again, so a pre-encoded slash becomes %252F.
# Call the API directly. The chart lives at octop/charts/octop so it does
# not replace the container image package named octop.
- name: Mark the GHCR chart package public
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
run: |
set -euo pipefail
owner="$(echo "$OWNER" | tr '[:upper:]' '[:lower:]')"
package="$(python3 -c 'import urllib.parse; print(urllib.parse.quote("octop/charts/octop", safe=""))')"
curl -fsS -X PUT \
-H "Authorization: Bearer ${GH_TOKEN}" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/orgs/${owner}/packages/container/${package}/visibility" \
-d '{"visibility":"public"}'