Skip to content

Commit e3824ae

Browse files
authored
Merge pull request #169 from morri-son/enhance-controller-release
Enhance controller release
2 parents 8d31d66 + ff3825b commit e3824ae

File tree

5 files changed

+119
-3
lines changed

5 files changed

+119
-3
lines changed

.github/scripts/compute-version.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function computeVersion(ref, tagPrefix, options = {}) {
4747
// using current timestamp and git SHA for uniqueness
4848
const timestamp = toUtcCompactTimestamp(options.now ?? new Date());
4949
const sanitizedRef = sanitizePrereleaseIdentifier(ref) || "ref";
50-
const shortSha = normalizeSha(options.gitSha ?? "unknown") || "unknown";
50+
const shortSha = options.gitSha ? normalizeSha(options.gitSha) : "unknown";
5151

5252
return `0.0.0-${sanitizedRef}.${timestamp}.${shortSha}`;
5353
}
@@ -84,7 +84,13 @@ function toUtcCompactTimestamp(date) {
8484
* @returns {string}
8585
*/
8686
function normalizeSha(sha) {
87-
return sha.toLowerCase().replace(/[^0-9a-f]/g, "").slice(0, 12);
87+
const normalized = sha.toLowerCase().replace(/[^0-9a-f]/g, "").slice(0, 12);
88+
if (normalized.length < 7) {
89+
throw new Error(
90+
`Invalid git SHA: expected at least 7 hex characters, got "${sha}" (normalized: "${normalized}")`
91+
);
92+
}
93+
return normalized;
8894
}
8995

9096
/**

.github/workflows/cli-release.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ jobs:
105105
secrets: inherit
106106
with:
107107
ref: ${{ needs.prepare.outputs.new_tag }}
108+
version: ${{ needs.prepare.outputs.base_version }}
108109

109110
# --------------------------------------------------------
110111
# 4. RELEASE RC: Create GitHub pre-release
@@ -480,7 +481,16 @@ jobs:
480481
481482
# Verify patching was successful
482483
ACTUAL_VERSION=$(yq '.version' "${CONSTRUCTOR}")
483-
test "${ACTUAL_VERSION}" = "${FINAL_VERSION}" || { echo "❌ Version mismatch: ${ACTUAL_VERSION} != ${FINAL_VERSION}"; exit 1; }
484+
test "${ACTUAL_VERSION}" = "${FINAL_VERSION}" || { echo "❌ .version mismatch: ${ACTUAL_VERSION} != ${FINAL_VERSION}"; exit 1; }
485+
486+
# Verify all resource versions were patched
487+
RESOURCE_VERSIONS=$(yq '[.resources[].version] | unique | .[]' "${CONSTRUCTOR}")
488+
test "${RESOURCE_VERSIONS}" = "${FINAL_VERSION}" || { echo "❌ Resource version mismatch: ${RESOURCE_VERSIONS}"; exit 1; }
489+
490+
# Verify image reference uses final version tag
491+
ACTUAL_IMAGE_REF=$(yq '.resources[] | select(.name == "image") | .access.imageReference' "${CONSTRUCTOR}")
492+
test "${ACTUAL_IMAGE_REF}" = "${IMAGE_REF}" || { echo "❌ Image ref mismatch: ${ACTUAL_IMAGE_REF} != ${IMAGE_REF}"; exit 1; }
493+
484494
echo "✅ Constructor patched to ${FINAL_VERSION}"
485495
486496
- name: Upload final constructor artifact

.github/workflows/cli.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ on:
2929
description: "The ref to build on (branch or tag). Defaults to the current ref."
3030
type: string
3131
required: false
32+
version:
33+
description: "Explicit version to embed (overrides computed version from ref). Leading 'v' is stripped automatically."
34+
type: string
35+
required: false
3236
outputs:
3337
artifact_name:
3438
description: "The artifact name that was built."
@@ -99,8 +103,17 @@ jobs:
99103
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
100104
env:
101105
TAG_PREFIX: "cli/v"
106+
VERSION_OVERRIDE: ${{ inputs.version || '' }}
102107
with:
103108
script: |
109+
const override = process.env.VERSION_OVERRIDE;
110+
if (override) {
111+
const version = override.replace(/^v/, "");
112+
core.exportVariable("VERSION", version);
113+
core.setOutput("version", version);
114+
core.info(`✅ Using explicit VERSION=${version} (override)`);
115+
return;
116+
}
104117
const script = await import('${{ github.workspace }}/.github/scripts/compute-version.js');
105118
await script.default({ core });
106119

.github/workflows/controller-release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ jobs:
319319
IMAGE_REPO: ${{ env.REGISTRY }}/${{ github.repository_owner }}/kubernetes/controller
320320
SET_LATEST: ${{ needs.prepare.outputs.set_latest }}
321321
run: |
322+
set -euo pipefail
322323
if [ "$SET_LATEST" = "true" ]; then
323324
oras tag "${IMAGE_REPO}:${RC_VERSION}" "${FINAL_VERSION}" "latest"
324325
echo "✅ Tagged :${FINAL_VERSION} and :latest"
@@ -345,6 +346,7 @@ jobs:
345346
VERSION: ${{ needs.prepare.outputs.base_version }}
346347
IMAGE_DIGEST: ${{ needs.build.outputs.image_digest }}
347348
run: |
349+
set -euo pipefail
348350
task helm/package VERSION="${VERSION}" APP_VERSION="${VERSION}" IMAGE_DIGEST="${IMAGE_DIGEST}"
349351
helm push dist/chart-${VERSION}.tgz oci://${{ env.REGISTRY }}/${{ github.repository_owner }}/kubernetes/controller
350352
@@ -353,6 +355,7 @@ jobs:
353355
env:
354356
VERSION: ${{ needs.prepare.outputs.base_version }}
355357
run: |
358+
set -euo pipefail
356359
CHART_REPO="${{ env.REGISTRY }}/${{ github.repository_owner }}/kubernetes/controller/chart"
357360
echo "digest=$(oras resolve ${CHART_REPO}:${VERSION})" >> "$GITHUB_OUTPUT"
358361
@@ -368,6 +371,7 @@ jobs:
368371
env:
369372
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
370373
run: |
374+
set -euo pipefail
371375
gh release view "${{ needs.prepare.outputs.new_tag }}" \
372376
--repo "${{ github.repository }}" --json body --jq '.body' > "${{ runner.temp }}/CHANGELOG.md"
373377

kubernetes/controller/cliff.toml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# git-cliff ~ configuration file
2+
# https://git-cliff.org/docs/configuration
3+
4+
5+
[changelog]
6+
# A Tera template to be rendered for each release in the changelog.
7+
# See https://keats.github.io/tera/docs/#introduction
8+
body = """
9+
{% if version %}\
10+
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
11+
{% else %}\
12+
## [unreleased]
13+
{% endif %}\
14+
{% for group, commits in commits | group_by(attribute="group") %}
15+
### {{ group | striptags | trim | upper_first }}
16+
{% for commit in commits %}
17+
- {% if commit.scope %}*({{ commit.scope }})* {% endif %}\
18+
{% if commit.breaking %}[**breaking**] {% endif %}\
19+
{{ commit.message | upper_first }}\
20+
{% endfor %}
21+
{% endfor %}
22+
{% if github.contributors | length > 0 %}
23+
### Community & Contributors
24+
25+
This release we had a total of **{{ github.contributors | length }}** contributors!
26+
If you want to engage with us, check our [community page](https://ocm.software/community/engagement/)!
27+
{% endif %}
28+
"""
29+
30+
# Remove leading and trailing whitespaces from the changelog's body.
31+
trim = true
32+
# Render body even when there are no releases to process.
33+
render_always = true
34+
# An array of regex based postprocessors to modify the changelog.
35+
postprocessors = [
36+
# Replace the placeholder <REPO> with a URL.
37+
#{ pattern = '<REPO>', replace = "https://github.com/orhun/git-cliff" },
38+
]
39+
40+
[git]
41+
# Parse commits according to the conventional commits specification.
42+
# See https://www.conventionalcommits.org
43+
conventional_commits = true
44+
# Exclude commits that do not match the conventional commits specification.
45+
filter_unconventional = true
46+
# Require all commits to be conventional.
47+
# Takes precedence over filter_unconventional.
48+
require_conventional = false
49+
# Split commits on newlines, treating each line as an individual commit.
50+
split_commits = false
51+
# An array of regex based parsers to modify commit messages prior to further processing.
52+
commit_preprocessors = [
53+
# Replace issue numbers with link templates to be updated in `changelog.postprocessors`.
54+
#{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](<REPO>/issues/${2}))"},
55+
]
56+
# Prevent commits that are breaking from being excluded by commit parsers.
57+
protect_breaking_commits = true
58+
# An array of regex based parsers for extracting data from the commit message.
59+
# Assigns commits to groups.
60+
# Optionally sets the commit's scope and can decide to exclude commits from further processing.
61+
commit_parsers = [
62+
{ message = "^feat", group = "<!-- 0 -->🚀 Features" },
63+
{ message = "^chore\\(deps.*\\)", group = "<!-- 2 -->📚 Dependencies" },
64+
{ message = "^fix\\(deps.*\\)", group = "<!-- 2 -->📚 Dependencies" },
65+
{ message = "^chore\\(docs.*\\)", group = "<!-- 8 -->📚 Documentation" },
66+
{ message = "^fix\\(docs.*\\)", group = "<!-- 8 -->📚 Documentation" },
67+
{ message = "^docs", group = "<!-- 8 -->📚 Documentation" },
68+
{ message = "^fix", group = "<!-- 1 -->🐛 Bug Fixes" },
69+
{ message = "^chore|^ci|chore\\(ci.*\\)|fix\\(ci.*\\)", group = "<!-- 7 -->⚙️ Miscellaneous Tasks" },
70+
]
71+
# Exclude commits that are not matched by any commit parser.
72+
filter_commits = false
73+
# An array of link parsers for extracting external references, and turning them into URLs, using regex.
74+
link_parsers = []
75+
# Order releases topologically instead of chronologically.
76+
topo_order = false
77+
# Order releases topologically instead of chronologically.
78+
topo_order_commits = true
79+
# Order of commits in each group/release within the changelog.
80+
# Allowed values: newest, oldest
81+
sort_commits = "oldest"
82+
# Process submodules commits
83+
recurse_submodules = false

0 commit comments

Comments
 (0)