Skip to content

Commit 08d67dc

Browse files
authored
push image and chart on release on sub project (#49)
Signed-off-by: Qing Hao <qhao@redhat.com>
1 parent 9970124 commit 08d67dc

8 files changed

Lines changed: 515 additions & 4 deletions

File tree

.github/actions/prepare-release-env/action.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ outputs:
1919
value: ${{ steps.env-vars.outputs.TRIMMED_RELEASE_VERSION }}
2020
MATRIX:
2121
description: Repository matrix
22-
value: ${{ steps.generate-matrix.outputs.matrix }}
22+
value: ${{ steps.filter-matrix.outputs.matrix }}
2323

2424
runs:
2525
using: 'composite'
@@ -50,3 +50,32 @@ runs:
5050
uses: ./go/src/open-cluster-management.io/addon-contrib/.github/actions/generate-repo-matrix
5151
with:
5252
repoRoot: go/src/open-cluster-management.io/addon-contrib
53+
54+
- name: filter matrix by release prefix
55+
id: filter-matrix
56+
shell: bash
57+
env:
58+
GITHUB_REF: ${{ inputs.github_ref }}
59+
run: |
60+
set -e
61+
62+
# Get the release prefix from the GitHub reference
63+
RELEASE_PREFIX=${GITHUB_REF%/*}
64+
RELEASE_PREFIX=${RELEASE_PREFIX##*/}
65+
66+
# Get the full repositories configuration
67+
repositories_json='${{ steps.generate-matrix.outputs.repositories }}'
68+
69+
# Check if RELEASE_PREFIX exists in repositories
70+
if echo "$repositories_json" | jq -e "has(\"$RELEASE_PREFIX\")" > /dev/null; then
71+
# RELEASE_PREFIX exists, create matrix with only this repository
72+
filtered_repos_json=$(echo "$repositories_json" | jq -c "{\"$RELEASE_PREFIX\": .[\"$RELEASE_PREFIX\"]}")
73+
matrix_json=$(echo "[\"$RELEASE_PREFIX\"]" | jq -c '{"repository": .}')
74+
75+
echo "matrix=$matrix_json" >> $GITHUB_OUTPUT
76+
echo "Found matching repository: $RELEASE_PREFIX"
77+
else
78+
# RELEASE_PREFIX doesn't exist, use empty matrix
79+
echo "matrix=" >> $GITHUB_OUTPUT
80+
echo "No matching repository found for prefix: $RELEASE_PREFIX"
81+
fi

.github/workflows/chart-upload.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: ChartUpload
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
release:
8+
types: [published]
9+
10+
jobs:
11+
env:
12+
name: prepare release env
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: checkout code
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 1
19+
path: go/src/open-cluster-management.io/addon-contrib
20+
21+
- name: prepare release environment
22+
id: prepare-env
23+
uses: ./go/src/open-cluster-management.io/addon-contrib/.github/actions/prepare-release-env
24+
with:
25+
github_ref: ${{ github.ref }}
26+
outputs:
27+
MAJOR_RELEASE_VERSION: ${{ steps.prepare-env.outputs.MAJOR_RELEASE_VERSION }}
28+
RELEASE_VERSION: ${{ steps.prepare-env.outputs.RELEASE_VERSION }}
29+
TRIMMED_RELEASE_VERSION: ${{ steps.prepare-env.outputs.TRIMMED_RELEASE_VERSION }}
30+
MATRIX: ${{ steps.prepare-env.outputs.MATRIX }}
31+
32+
upload:
33+
name: upload
34+
runs-on: ubuntu-latest
35+
needs: [env]
36+
permissions:
37+
contents: write
38+
strategy:
39+
matrix: ${{ fromJson(needs.env.outputs.MATRIX) }}
40+
steps:
41+
- name: submit addon-contrib chart to OCM chart repo
42+
if: github.event_name != 'pull_request'
43+
uses: actions/github-script@v7
44+
with:
45+
github-token: ${{ secrets.OCM_BOT_PAT }}
46+
script: |
47+
try {
48+
const result = await github.rest.actions.createWorkflowDispatch({
49+
owner: 'open-cluster-management-io',
50+
repo: 'helm-charts',
51+
workflow_id: 'download-chart.yml',
52+
ref: 'main',
53+
inputs: {
54+
repo: "${{ github.repository }}",
55+
version: "${{ needs.env.outputs.TRIMMED_RELEASE_VERSION }}",
56+
component: "${{ matrix.repository }}",
57+
"chart-name": "${{ matrix.repository }}",
58+
},
59+
})
60+
console.log(result);
61+
} catch(error) {
62+
console.error(error);
63+
core.setFailed(error);
64+
}

.github/workflows/post.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,18 @@ jobs:
122122
run: docker pull registry.access.redhat.com/ubi9/ubi-minimal:latest --platform=linux/${{ matrix.arch }}
123123
- name: build image
124124
run: |
125+
set -e
126+
cd ${{ matrix.repo }}
125127
IMAGE_TAG=latest-${{ matrix.arch }} \
126128
IMAGE_BUILD_EXTRA_FLAGS="--build-arg OS=linux --build-arg ARCH=${{ matrix.arch }}" \
127-
cd ${{ matrix.repo }} && make image
129+
make image
128130
- name: push image
129131
run: |
132+
set -e
133+
cd ${{ matrix.repo }}
130134
echo ${{ secrets.DOCKER_PASSWORD }} | docker login quay.io --username ${{ secrets.DOCKER_USER }} --password-stdin
131135
IMAGE_TAG=latest-${{ matrix.arch }} \
132-
cd ${{ matrix.repo }} && make image-push
136+
make image-push
133137
134138
image-manifest:
135139
name: Create and Push Image Manifest
@@ -144,6 +148,8 @@ jobs:
144148
uses: actions/checkout@v4
145149
- name: create and push manifest
146150
run: |
151+
set -e
152+
cd ${{ matrix.repo }}
147153
echo ${{ secrets.DOCKER_PASSWORD }} | docker login quay.io --username ${{ secrets.DOCKER_USER }} --password-stdin
148154
IMAGE_TAG=latest \
149-
cd ${{ matrix.repo }} && make image-manifest
155+
make image-manifest

.github/workflows/release.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: GoRelease
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request:
8+
paths:
9+
- .github/workflows/release.yml
10+
push:
11+
tags:
12+
- '*/v*.*.*'
13+
14+
env:
15+
GITHUB_REF: ${{ github.ref }}
16+
17+
defaults:
18+
run:
19+
working-directory: go/src/open-cluster-management.io/addon-contrib
20+
21+
jobs:
22+
env:
23+
name: prepare release env
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: checkout code
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 1
30+
path: go/src/open-cluster-management.io/addon-contrib
31+
32+
- name: prepare release environment
33+
id: prepare-env
34+
uses: ./go/src/open-cluster-management.io/addon-contrib/.github/actions/prepare-release-env
35+
with:
36+
github_ref: ${{ github.ref }}
37+
outputs:
38+
MAJOR_RELEASE_VERSION: ${{ steps.prepare-env.outputs.MAJOR_RELEASE_VERSION }}
39+
RELEASE_VERSION: ${{ steps.prepare-env.outputs.RELEASE_VERSION }}
40+
TRIMMED_RELEASE_VERSION: ${{ steps.prepare-env.outputs.TRIMMED_RELEASE_VERSION }}
41+
MATRIX: ${{ steps.prepare-env.outputs.MATRIX }}
42+
43+
release:
44+
name: release
45+
runs-on: ubuntu-latest
46+
needs: [ env ]
47+
permissions:
48+
contents: write
49+
strategy:
50+
matrix: ${{ fromJson(needs.env.outputs.MATRIX) }}
51+
steps:
52+
- name: checkout code
53+
uses: actions/checkout@v4
54+
with:
55+
fetch-depth: 1
56+
path: go/src/open-cluster-management.io/addon-contrib
57+
58+
- name: Set up Python 3.x
59+
uses: actions/setup-python@v5
60+
with:
61+
# Semantic version range syntax or exact version of a Python version
62+
python-version: '3.x'
63+
64+
- name: Install dependencies
65+
run: |
66+
python -m pip install --upgrade pip
67+
pip install PyGithub
68+
69+
- name: generate changelog
70+
run: |
71+
python hack/changelog.py ${{ secrets.GITHUB_TOKEN }} ${{ matrix.repository }} ${{ needs.env.outputs.RELEASE_VERSION }} > /home/runner/work/changelog.txt
72+
cat /home/runner/work/changelog.txt
73+
74+
- name: setup helm
75+
uses: azure/setup-helm@v4
76+
77+
- name: chart package
78+
if: github.event_name != 'pull_request'
79+
run: |
80+
set -e
81+
mkdir -p release
82+
pushd release
83+
yq eval '.dependencies[] | .name + " " + .repository' ../${{ matrix.repository }}/charts/${{ matrix.repository }}/Chart.yaml | while read -r repo_name repo_url; do
84+
if [[ ! "$repo_url" =~ ^(oci://|file://) ]]; then
85+
helm repo add "$repo_name" "$repo_url"
86+
else
87+
echo "Skipping repository $repo_url for $repo_name"
88+
fi
89+
done
90+
if helm repo list | grep -q .; then
91+
helm repo update
92+
else
93+
echo "No helm repositories to update."
94+
fi
95+
helm dependency build ../${{ matrix.repository }}/charts/${{ matrix.repository }}
96+
helm package ../${{ matrix.repository }}/charts/${{ matrix.repository }} \
97+
--version ${{ needs.env.outputs.TRIMMED_RELEASE_VERSION }}
98+
popd
99+
100+
- name: publish release
101+
if: github.event_name != 'pull_request'
102+
uses: softprops/action-gh-release@v2
103+
env:
104+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
105+
with:
106+
body_path: /home/runner/work/changelog.txt
107+
draft: true
108+
generate_release_notes: true
109+
files: |
110+
/home/runner/work/addon-contrib/addon-contrib/go/src/open-cluster-management.io/addon-contrib/release/*.tgz

.github/workflows/releaseimage.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: ImageRelease
2+
3+
on:
4+
push:
5+
tags:
6+
- '*/v*.*.*'
7+
8+
env:
9+
# Common versions
10+
GO_VERSION: '1.23'
11+
GO_REQUIRED_MIN_VERSION: ''
12+
GOPATH: '/home/runner/work/addon-contrib/addon-contrib/go'
13+
GITHUB_REF: ${{ github.ref }}
14+
15+
defaults:
16+
run:
17+
working-directory: go/src/open-cluster-management.io/addon-contrib
18+
19+
permissions:
20+
contents: read
21+
22+
jobs:
23+
env:
24+
name: prepare release env
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: checkout code
28+
uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 1
31+
path: go/src/open-cluster-management.io/addon-contrib
32+
33+
- name: prepare release environment
34+
id: prepare-env
35+
uses: ./go/src/open-cluster-management.io/addon-contrib/.github/actions/prepare-release-env
36+
with:
37+
github_ref: ${{ github.ref }}
38+
outputs:
39+
MAJOR_RELEASE_VERSION: ${{ steps.prepare-env.outputs.MAJOR_RELEASE_VERSION }}
40+
RELEASE_VERSION: ${{ steps.prepare-env.outputs.RELEASE_VERSION }}
41+
MATRIX: ${{ steps.prepare-env.outputs.MATRIX }}
42+
43+
images:
44+
name: images
45+
runs-on: ubuntu-latest
46+
needs: [ env ]
47+
strategy:
48+
matrix:
49+
arch: [ amd64, arm64 ]
50+
repository: ${{ fromJson(needs.env.outputs.MATRIX).repository }}
51+
steps:
52+
- name: checkout code
53+
uses: actions/checkout@v4
54+
with:
55+
fetch-depth: 1
56+
path: go/src/open-cluster-management.io/addon-contrib
57+
58+
- name: install Go
59+
uses: actions/setup-go@v5
60+
with:
61+
go-version: ${{ env.GO_VERSION }}
62+
63+
- name: install imagebuilder
64+
run: go install github.com/openshift/imagebuilder/cmd/imagebuilder@v1.2.16
65+
66+
- name: pull base image
67+
run: docker pull registry.access.redhat.com/ubi9/ubi-minimal:latest --platform=linux/${{ matrix.arch }}
68+
69+
- name: build image
70+
run: |
71+
set -e
72+
cd ${{ matrix.repository }}
73+
IMAGE_TAG=${{ needs.env.outputs.RELEASE_VERSION }}-${{ matrix.arch }} \
74+
IMAGE_BUILD_EXTRA_FLAGS="--build-arg OS=linux --build-arg ARCH=${{ matrix.arch }}" \
75+
make image
76+
77+
- name: push image
78+
run: |
79+
set -e
80+
cd ${{ matrix.repository }}
81+
echo ${{ secrets.DOCKER_PASSWORD }} | docker login quay.io --username ${{ secrets.DOCKER_USER }} --password-stdin
82+
IMAGE_TAG=${{ needs.env.outputs.RELEASE_VERSION }}-${{ matrix.arch }} \
83+
make image-push
84+
85+
image-manifest:
86+
name: Create and Push Image Manifest
87+
runs-on: ubuntu-latest
88+
needs: [ env, images ]
89+
strategy:
90+
matrix:
91+
repository: ${{ fromJson(needs.env.outputs.MATRIX).repository }}
92+
steps:
93+
- name: checkout code
94+
uses: actions/checkout@v4
95+
with:
96+
fetch-depth: 1
97+
path: go/src/open-cluster-management.io/addon-contrib
98+
99+
- name: create
100+
run: |
101+
set -e
102+
cd ${{ matrix.repository }}
103+
echo ${{ secrets.DOCKER_PASSWORD }} | docker login quay.io --username ${{ secrets.DOCKER_USER }} --password-stdin
104+
IMAGE_TAG=${{ needs.env.outputs.RELEASE_VERSION }} \
105+
make image-manifest

0 commit comments

Comments
 (0)