Skip to content

Commit 4b0fb1e

Browse files
authored
chore: Add release and publish automation (#12)
* fix lint * add actions and make needed Makefiles and scripts changes * update action triggers
1 parent 4e6886c commit 4b0fb1e

File tree

14 files changed

+273
-18
lines changed

14 files changed

+273
-18
lines changed

.github/workflows/license-check.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ name: Check Go Dependency Licenses
22

33
on:
44
workflow_call: {}
5-
pull_request:
5+
push:
6+
tags:
7+
- v*
68
branches:
79
- main
810
paths:
911
- go.mod
1012
- go.sum
11-
13+
pull_request:
14+
1215
permissions:
1316
contents: read
1417

.github/workflows/publish.yaml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: publish
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
workflow_dispatch:
7+
8+
9+
permissions:
10+
packages: write
11+
12+
env:
13+
OCI_URL: ghcr.io/sap
14+
15+
jobs:
16+
release_tag:
17+
name: Release version
18+
runs-on: ubuntu-24.04
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
with:
23+
ssh-key: ${{ secrets.PUSH_KEY }}
24+
fetch-tags: true
25+
fetch-depth: 0
26+
27+
- name: Read and validate VERSION
28+
id: version
29+
run: |
30+
VERSION=$(cat VERSION)
31+
if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-dev)?$ ]]; then
32+
echo "Invalid version format in VERSION file: $VERSION"
33+
exit 1
34+
fi
35+
echo "New version: $VERSION"
36+
echo "version=$VERSION" >> $GITHUB_ENV
37+
38+
- name: Skip release if version is a dev version
39+
if: contains(env.version, '-dev')
40+
run: |
41+
echo "Skipping development version release: ${{ env.version }}"
42+
echo "SKIP=true" >> $GITHUB_ENV
43+
exit 0
44+
45+
- name: Set up QEMU
46+
uses: docker/setup-qemu-action@v2
47+
48+
- name: Set up Docker Context for Buildx
49+
id: buildx-context
50+
run: |
51+
docker context create builders
52+
53+
- name: Login to GitHub Container Registry
54+
uses: docker/login-action@v3
55+
with:
56+
registry: ghcr.io
57+
username: ${{ github.actor }}
58+
password: ${{ secrets.GITHUB_TOKEN }}
59+
60+
- name: Set up Docker Buildx
61+
timeout-minutes: 5
62+
uses: docker/setup-buildx-action@v2
63+
with:
64+
version: latest
65+
66+
- name: Set up Go
67+
uses: actions/setup-go@v5
68+
with:
69+
go-version-file: go.mod
70+
71+
- name: Build the ${{ github.repository }}
72+
run: |
73+
make reviewable
74+
make build
75+
76+
- name: Build Images
77+
run: |
78+
IMAGE_REGISTRY=ghcr.io/sap/metrics-operator make docker-build
79+
80+
- name: setup OCM
81+
uses: open-component-model/ocm-setup-action@main
82+
83+
- name: Create OCM CTF
84+
run: |
85+
ocm add componentversions --create \
86+
--file ctf component-constructor.yaml \
87+
--settings settings.yaml -- VERSION=${{ env.version }}
88+
89+
- name: Push CTF
90+
run: |
91+
ocm transfer ctf --overwrite ./ctf ${{ env.OCI_URL }}

.github/workflows/release.yaml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Versioned Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write # we need this to be able to push tags
10+
11+
jobs:
12+
release_tag:
13+
name: Release version
14+
runs-on: ubuntu-24.04
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
with:
19+
ssh-key: ${{ secrets.PUSH_KEY }}
20+
fetch-tags: true
21+
fetch-depth: 0
22+
23+
- name: Read and validate VERSION
24+
id: version
25+
run: |
26+
VERSION=$(cat VERSION)
27+
if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-dev)?$ ]]; then
28+
echo "Invalid version format in VERSION file: $VERSION"
29+
exit 1
30+
fi
31+
echo "New version: $VERSION"
32+
echo "version=$VERSION" >> $GITHUB_ENV
33+
34+
- name: Skip release if version is a dev version
35+
if: contains(env.version, '-dev')
36+
run: |
37+
echo "Skipping development version release: ${{ env.version }}"
38+
echo "SKIP=true" >> $GITHUB_ENV
39+
exit 0
40+
41+
- name: Check if VERSION is already tagged
42+
id: check_tag
43+
run: |
44+
if git rev-parse "refs/tags/${{ env.version }}" >/dev/null 2>&1; then
45+
echo "Tag ${{ env.version }} already exists. Skipping release."
46+
echo "SKIP=true" >> $GITHUB_ENV
47+
exit 0
48+
fi
49+
echo "Tag ${{ env.version }} doesn't exists. Proceeding with release."
50+
51+
- name: Create Git tag
52+
if: ${{ env.SKIP != 'true' }}
53+
run: |
54+
AUTHOR_NAME=$(git log -1 --pretty=format:'%an')
55+
AUTHOR_EMAIL=$(git log -1 --pretty=format:'%ae')
56+
echo "Tagging as $AUTHOR_NAME <$AUTHOR_EMAIL>"
57+
58+
echo "AUTHOR_NAME=$AUTHOR_NAME" >> $GITHUB_ENV
59+
echo "AUTHOR_EMAIL=$AUTHOR_EMAIL" >> $GITHUB_ENV
60+
61+
git config user.name "$AUTHOR_NAME"
62+
git config user.email "$AUTHOR_EMAIL"
63+
64+
git tag -a "${{ env.version }}" -m "Release ${{ env.version }}"
65+
git push origin "${{ env.version }}"
66+
67+
- name: Build Changelog
68+
id: github_release
69+
uses: mikepenz/release-changelog-builder-action@v5
70+
with:
71+
mode: "PR"
72+
configurationJson: |
73+
{
74+
"template": "#{{CHANGELOG}}",
75+
"pr_template": "- #{{TITLE}}: ##{{NUMBER}}",
76+
"categories": [
77+
{
78+
"title": "## Feature",
79+
"labels": ["feat", "feature"]
80+
},
81+
{
82+
"title": "## Fix",
83+
"labels": ["fix", "bug"]
84+
},
85+
{
86+
"title": "## Other",
87+
"labels": []
88+
}
89+
],
90+
"label_extractor": [
91+
{
92+
"pattern": "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\\([\\w\\-\\.]+\\))?(!)?: ([\\w ])+([\\s\\S]*)",
93+
"on_property": "title",
94+
"target": "$1"
95+
}
96+
]
97+
}
98+
env:
99+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
100+
101+
- name: Create GitHub release
102+
if: ${{ env.SKIP != 'true' }}
103+
uses: softprops/action-gh-release@v2
104+
with:
105+
tag_name: ${{ env.version }}
106+
name: Release ${{ env.version }}
107+
body: "Automated release for version ${{ env.version }}"
108+
draft: false
109+
prerelease: false
110+
env:
111+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
112+
113+
- name: Push dev VERSION
114+
if: ${{ env.SKIP != 'true' }}
115+
run: |
116+
echo "${{ env.version }}-dev" > VERSION
117+
git config user.name "${{ env.AUTHOR_NAME }}"
118+
git config user.email "${{ env.AUTHOR_EMAIL }}"
119+
git add VERSION
120+
git commit -m "Update VERSION to ${{ env.version }}-dev"
121+
git push origin main

.github/workflows/reuse-scan.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ name: REUSE Compliance Check
44

55
on:
66
workflow_call: {}
7-
pull_request:
7+
push:
88
branches:
99
- main
10-
10+
pull_request:
11+
1112

1213
jobs:
1314
lint-reuse:

.github/workflows/reviewable.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ name: make reviewable && make check-Diff
44

55
on:
66
workflow_call: {}
7-
pull_request:
7+
push:
8+
tags:
9+
- v*
810
branches:
911
- main
12+
pull_request:
1013
env:
1114
GO_IMPORT_VERSION: 'v0.16.1'
1215

@@ -35,7 +38,10 @@ jobs:
3538

3639
- name: tidy
3740
run: go mod tidy
38-
41+
42+
- name: sync chart version
43+
run: make helm-chart
44+
3945
- name: make check-diff
4046
run: make check-diff
4147

Makefile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,18 @@ docker-push: ## Push docker image with the manager.
103103
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
104104
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
105105
# To properly provided solutions that supports more than one platform you should use this option.
106-
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
106+
PLATFORMS ?= linux/arm64 linux/amd64
107107
.PHONY: docker-buildx
108-
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
109-
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
110-
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
111-
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
108+
docker-buildx: #test ## Build and tag docker image for each platform locally using --load
109+
sed '1 s/^FROM/FROM --platform=$${BUILDPLATFORM}/' Dockerfile > Dockerfile.cross
110+
$(CONTAINER_TOOL) buildx create --name project-v3-builder || true
112111
$(CONTAINER_TOOL) buildx use project-v3-builder
113-
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
114-
- $(CONTAINER_TOOL) buildx rm project-v3-builder
112+
@for platform in $(PLATFORMS); do \
113+
tag="$(IMG)-$$(echo $$platform | tr / -)"; \
114+
echo "Building $$tag for $$platform"; \
115+
$(CONTAINER_TOOL) buildx build --platform=$$platform --tag $$tag --load -f Dockerfile.cross .; \
116+
done
117+
$(CONTAINER_TOOL) buildx rm project-v3-builder
115118
rm Dockerfile.cross
116119

117120
##@ Deployment

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v0.5.0

api/v1alpha1/common_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type GroupVersionKind struct {
2222
Version string `json:"version,omitempty"`
2323
}
2424

25+
// GVK returns the schema.GroupVersionKind object of v1alpha1 GVK
2526
func (gvk *GroupVersionKind) GVK() schema.GroupVersionKind {
2627
return schema.GroupVersionKind{
2728
Group: gvk.Group,

api/v1alpha1/metric_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ func (r *Metric) SetConditions(conditions ...metav1.Condition) {
9393
meta.SetStatusCondition(&r.Status.Conditions, c)
9494
}
9595
}
96+
97+
// GvkToString returns the string representation of the metric targe GVK
9698
func (r *Metric) GvkToString() string {
9799
if r.Spec.Target.Group == "" {
98100
return fmt.Sprintf("/%s, Kind=%s", r.Spec.Target.Version, r.Spec.Target.Kind)

charts/metrics-operator/Chart.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: v2
22
name: metrics-operator
3-
description: A Helm chart for the co-metrics-operator
3+
description: A Helm chart for the metrics-operator
44
type: application
5-
version: 0.4.2
6-
appVersion: 0.4.2
5+
version: v0.5.0
6+
appVersion: v0.5.0

0 commit comments

Comments
 (0)