Skip to content

Commit caac146

Browse files
haoqing0110mrrr3d
authored andcommitted
add pre and post worflow for sub project changes (open-cluster-management-io#48)
Signed-off-by: Qing Hao <qhao@redhat.com>
1 parent 3d7aa9c commit caac146

21 files changed

Lines changed: 682 additions & 29 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Generate Repository Matrix
2+
description: Generates a matrix of repositories from the repositories.json file
3+
inputs:
4+
repoRoot:
5+
description: The root directory of the repository
6+
required: true
7+
type: string
8+
outputs:
9+
matrix:
10+
description: JSON matrix of repositories
11+
value: ${{ steps.generate.outputs.matrix }}
12+
repositories:
13+
description: Complete repositories configuration as JSON
14+
value: ${{ steps.generate.outputs.repositories }}
15+
runs:
16+
using: 'composite'
17+
steps:
18+
- name: generate matrix
19+
id: generate
20+
shell: bash
21+
run: |
22+
set -e
23+
24+
# Read repositories.json and properly escape for GitHub Actions
25+
repositories_json=$(cat ${{ inputs.repoRoot }}/.github/repositories.json | jq -c .)
26+
echo "repositories=$repositories_json" >> $GITHUB_OUTPUT
27+
28+
# Extract repository names for matrix
29+
repository_names=$(echo "$repositories_json" | jq -r 'keys')
30+
matrix_json=$(echo "$repository_names" | jq -c '{"repository": .}')
31+
echo "matrix=$matrix_json" >> $GITHUB_OUTPUT
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Prepare Release Environment
2+
description: Prepare release environment variables and repository matrix
3+
4+
inputs:
5+
github_ref:
6+
description: GitHub reference
7+
required: true
8+
default: ${{ github.ref }}
9+
10+
outputs:
11+
MAJOR_RELEASE_VERSION:
12+
description: Major release version
13+
value: ${{ steps.env-vars.outputs.MAJOR_RELEASE_VERSION }}
14+
RELEASE_VERSION:
15+
description: Release version
16+
value: ${{ steps.env-vars.outputs.RELEASE_VERSION }}
17+
TRIMMED_RELEASE_VERSION:
18+
description: Trimmed release version
19+
value: ${{ steps.env-vars.outputs.TRIMMED_RELEASE_VERSION }}
20+
MATRIX:
21+
description: Repository matrix
22+
value: ${{ steps.generate-matrix.outputs.matrix }}
23+
24+
runs:
25+
using: 'composite'
26+
steps:
27+
- name: get release version
28+
shell: bash
29+
run: |
30+
echo "RELEASE_VERSION=${GITHUB_REF##*/}" >> $GITHUB_ENV
31+
env:
32+
GITHUB_REF: ${{ inputs.github_ref }}
33+
34+
- name: get major release version
35+
shell: bash
36+
run: |
37+
echo "MAJOR_RELEASE_VERSION=${RELEASE_VERSION%.*}" >> $GITHUB_ENV
38+
echo "TRIMMED_RELEASE_VERSION=${RELEASE_VERSION#v}" >> $GITHUB_ENV
39+
40+
- name: set outputs
41+
id: env-vars
42+
shell: bash
43+
run: |
44+
echo "MAJOR_RELEASE_VERSION=${MAJOR_RELEASE_VERSION}" >> $GITHUB_OUTPUT
45+
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_OUTPUT
46+
echo "TRIMMED_RELEASE_VERSION=${TRIMMED_RELEASE_VERSION}" >> $GITHUB_OUTPUT
47+
48+
- name: generate matrix
49+
id: generate-matrix
50+
uses: ./go/src/open-cluster-management.io/addon-contrib/.github/actions/generate-repo-matrix
51+
with:
52+
repoRoot: go/src/open-cluster-management.io/addon-contrib

.github/repositories.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"kueue-addon": {
3+
"e2e-artifacts": ["kueue-addon.tar.gz"]
4+
},
5+
"resource-usage-collect-addon": {
6+
"e2e-artifacts": ["resource-usage-collect-addon.tar.gz"]
7+
}
8+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Dependency Review Action
2+
#
3+
# This Action will scan dependency manifest files that change as part of a Pull Request,
4+
# surfacing known-vulnerable versions of the packages declared or updated in the PR.
5+
# Once installed, if the workflow run is marked as required,
6+
# PRs introducing known-vulnerable packages will be blocked from merging.
7+
#
8+
# Source repository: https://github.com/actions/dependency-review-action
9+
name: 'Dependency Review'
10+
on: [pull_request]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
dependency-review:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Harden Runner
20+
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
21+
with:
22+
egress-policy: audit
23+
24+
- name: 'Checkout Repository'
25+
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
26+
- name: 'Dependency Review'
27+
uses: actions/dependency-review-action@ce3cf9537a52e8119d91fd484ab5b8a807627bf8 # v4.6.0

.github/workflows/e2e.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: E2E
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
repo:
7+
required: true
8+
type: string
9+
artifacts:
10+
required: false
11+
type: string
12+
13+
env:
14+
GO_REQUIRED_MIN_VERSION: ''
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
e2e:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Install DevSpace
27+
uses: loft-sh/setup-devspace@main
28+
29+
- name: Setup Go
30+
uses: actions/setup-go@v5
31+
with:
32+
go-version: 1.23
33+
34+
- name: Test E2E
35+
run: |
36+
cd ${{ inputs.repo }} && make test-e2e
37+
38+
- name: Upload Artifacts
39+
if: |
40+
(success() || failure()) && inputs.artifacts != ''
41+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
42+
with:
43+
name: e2e-artifacts
44+
path: ${{ inputs.artifacts }}
45+
if-no-files-found: ignore
46+
retention-days: 7

.github/workflows/post.yml

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
name: Post
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch: {}
8+
9+
concurrency:
10+
group: post-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
generate-matrix:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
id-token: write
19+
outputs:
20+
matrix: ${{ steps.generate.outputs.matrix }}
21+
repositories: ${{ steps.repo-matrix.outputs.repositories }}
22+
artifacts: ${{ steps.generate.outputs.artifacts }}
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
26+
with:
27+
fetch-depth: 0
28+
ref: ${{ github.sha }}
29+
- name: Compute diff refs
30+
id: compute-refs
31+
run: |
32+
set -e
33+
34+
BASE_SHA=${{ github.event.before }}
35+
HEAD_SHA=${{ github.sha }}
36+
37+
# Ensure we have both the base and head commits
38+
git fetch --depth=1 origin $BASE_SHA
39+
git fetch --depth=1 origin $HEAD_SHA
40+
echo "BASE_SHA=$BASE_SHA" >> $GITHUB_ENV
41+
echo "HEAD_SHA=$HEAD_SHA" >> $GITHUB_ENV
42+
43+
# echo "Diff will compare $BASE_SHA with $HEAD_SHA"
44+
echo "Diff will compare main ($BASE_SHA) with $HEAD_SHA"
45+
- name: Generate repository matrix
46+
id: repo-matrix
47+
uses: ./.github/actions/generate-repo-matrix
48+
with:
49+
repoRoot: "."
50+
- name: Build changed project matrix
51+
id: generate
52+
run: |
53+
set -e
54+
55+
# Get repository names and check for changes
56+
repositories_json='${{ steps.repo-matrix.outputs.repositories }}'
57+
changed_repos=()
58+
59+
# Check each repository for changes
60+
while IFS= read -r repo; do
61+
if git diff --name-only $BASE_SHA $HEAD_SHA | grep "^$repo/" > /dev/null 2>&1; then
62+
changed_repos+=("$repo")
63+
fi
64+
done < <(echo "$repositories_json" | jq -r 'keys[]')
65+
66+
if [ ${#changed_repos[@]} -eq 0 ]; then
67+
echo "No changes detected for any project"
68+
echo "matrix=" >> $GITHUB_OUTPUT
69+
echo "artifacts={}" >> $GITHUB_OUTPUT
70+
else
71+
# Convert changed repos array to JSON
72+
changed_repos_json=$(printf '%s\n' "${changed_repos[@]}" | jq -R . | jq -s .)
73+
matrixJson=$(echo "$changed_repos_json" | jq -c '{"repo": .}')
74+
75+
# Generate artifacts JSON with workspace prefix
76+
artifacts_json=$(
77+
echo "$repositories_json" | jq -c \
78+
--argjson changed_repos "$changed_repos_json" \
79+
--arg workspace "${{ github.workspace }}" \
80+
'
81+
to_entries
82+
| map(select(.key as $repo | $changed_repos | index($repo) != null))
83+
| from_entries
84+
| with_entries(
85+
.key as $repo
86+
| .value = (
87+
.value["e2e-artifacts"]
88+
| map($workspace + "/" + $repo + "/" + .)
89+
| join("\n")
90+
)
91+
)
92+
'
93+
)
94+
95+
echo "matrix=$matrixJson" >> $GITHUB_OUTPUT
96+
echo "artifacts=$artifacts_json" >> $GITHUB_OUTPUT
97+
fi
98+
99+
echo "Matrix: $matrixJson"
100+
echo "Artifacts: $artifacts_json"
101+
102+
images:
103+
name: Build and Push Images
104+
needs: generate-matrix
105+
if: needs.generate-matrix.outputs.matrix != ''
106+
runs-on: ubuntu-latest
107+
strategy:
108+
fail-fast: false
109+
matrix:
110+
repo: ${{ fromJson(needs.generate-matrix.outputs.matrix).repo }}
111+
arch: [amd64, arm64]
112+
steps:
113+
- name: Checkout code
114+
uses: actions/checkout@v4
115+
- name: install Go
116+
uses: actions/setup-go@v5
117+
with:
118+
go-version: '1.23'
119+
- name: install imagebuilder
120+
run: go install github.com/openshift/imagebuilder/cmd/imagebuilder@v1.2.16
121+
- name: pull base image
122+
run: docker pull registry.access.redhat.com/ubi9/ubi-minimal:latest --platform=linux/${{ matrix.arch }}
123+
- name: build image
124+
run: |
125+
IMAGE_TAG=latest-${{ matrix.arch }} \
126+
IMAGE_BUILD_EXTRA_FLAGS="--build-arg OS=linux --build-arg ARCH=${{ matrix.arch }}" \
127+
cd ${{ matrix.repo }} && make image
128+
- name: push image
129+
run: |
130+
echo ${{ secrets.DOCKER_PASSWORD }} | docker login quay.io --username ${{ secrets.DOCKER_USER }} --password-stdin
131+
IMAGE_TAG=latest-${{ matrix.arch }} \
132+
cd ${{ matrix.repo }} && make image-push
133+
134+
image-manifest:
135+
name: Create and Push Image Manifest
136+
needs: [images, generate-matrix]
137+
runs-on: ubuntu-latest
138+
strategy:
139+
fail-fast: false
140+
matrix:
141+
repo: ${{ fromJson(needs.generate-matrix.outputs.matrix).repo }}
142+
steps:
143+
- name: Checkout code
144+
uses: actions/checkout@v4
145+
- name: create and push manifest
146+
run: |
147+
echo ${{ secrets.DOCKER_PASSWORD }} | docker login quay.io --username ${{ secrets.DOCKER_USER }} --password-stdin
148+
IMAGE_TAG=latest \
149+
cd ${{ matrix.repo }} && make image-manifest

0 commit comments

Comments
 (0)