Skip to content

Commit 8dfc399

Browse files
committed
github: add new workflow
- odh-release.yaml: create release branch, tag, releasenotes - odh-build-image.yaml: build image for PR, build image and push to quay.io when PR merge to main Signed-off-by: Wen Zhou <wenzhou@redhat.com>
1 parent 06862a9 commit 8dfc399

2 files changed

Lines changed: 184 additions & 0 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: ODH Build and Push Image
2+
# Builds container image on every PR to validate the build.
3+
# On merge to main, builds and pushes the image to Quay.io.
4+
5+
on:
6+
pull_request:
7+
branches:
8+
- main
9+
types: [opened, synchronize, reopened]
10+
paths-ignore:
11+
- '**/*.md'
12+
- 'docs/**'
13+
- 'deploy/**'
14+
- 'hack/**'
15+
- 'test/**'
16+
- 'LICENSE'
17+
- 'OWNERS'
18+
- '_typos.toml'
19+
- '.github/**'
20+
- '!.github/workflows/odh-build-image.yaml'
21+
push:
22+
branches:
23+
- main
24+
paths-ignore:
25+
- '**/*.md'
26+
- 'docs/**'
27+
- 'deploy/**'
28+
- 'hack/**'
29+
- 'test/**'
30+
- 'LICENSE'
31+
- 'OWNERS'
32+
- '_typos.toml'
33+
- '.github/**'
34+
- '!.github/workflows/odh-build-image.yaml'
35+
36+
env:
37+
REGISTRY: quay.io
38+
REGISTRY_ORG: opendatahub-io
39+
IMAGE_NAME: workload-variant-autoscaler
40+
41+
jobs:
42+
build-and-push:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- name: Checkout source
46+
uses: actions/checkout@v6
47+
48+
- name: Determine image tag
49+
id: tag
50+
run: |
51+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
52+
TAG="pr-${{ github.event.number }}"
53+
else
54+
TAG="latest"
55+
fi
56+
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
57+
echo "Image will be tagged as: ${TAG}"
58+
59+
- name: Set up Docker Buildx
60+
uses: docker/setup-buildx-action@v3
61+
62+
- name: Login to Quay.io
63+
if: github.event_name == 'push'
64+
uses: docker/login-action@v3
65+
with:
66+
registry: ${{ env.REGISTRY }}
67+
username: ${{ secrets.QUAY_ID }}
68+
password: ${{ secrets.QUAY_TOKEN }}
69+
70+
- name: Build and push image
71+
uses: docker/build-push-action@v6
72+
with:
73+
context: .
74+
push: ${{ github.event_name == 'push' }}
75+
tags: ${{ env.REGISTRY }}/${{ env.REGISTRY_ORG }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.tag }}
76+
platforms: linux/amd64
77+
cache-from: type=gha
78+
cache-to: type=gha,mode=max

.github/workflows/odh-release.yaml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: ODH Release
2+
# Creates a release branch from main (or a specific commit), optionally tags it,
3+
# and creates a GitHub release with auto-generated release notes.
4+
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
release_branch:
9+
description: 'Name of the release branch (e.g. release-v3.5.0, release-v3.4.0-ea1)'
10+
required: true
11+
type: string
12+
source_ref:
13+
description: 'Source commit SHA to create the release branch from. Leave empty to use the latest commit on main.'
14+
required: false
15+
type: string
16+
default: ''
17+
create_tag:
18+
description: 'Create a tag from the release branch? Tag will be derived from branch name (e.g. release-v3.5.0 -> v3.5.0)'
19+
required: true
20+
type: boolean
21+
default: false
22+
create_release:
23+
description: 'Create a GitHub release with auto-generated release notes? (requires create_tag)'
24+
required: true
25+
type: boolean
26+
default: false
27+
28+
env:
29+
DEFAULT_BRANCH: main
30+
31+
jobs:
32+
create-release-branch:
33+
runs-on: ubuntu-latest
34+
permissions:
35+
contents: write
36+
steps:
37+
- name: Validate branch name
38+
run: |
39+
BRANCH="${{ inputs.release_branch }}"
40+
if [[ ! "$BRANCH" =~ ^release-v[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]]; then
41+
echo "::error::Invalid branch name '${BRANCH}'. Must match pattern 'release-v<major>.<minor>.<patch>[-<prerelease>]' (e.g. release-v3.5.0, release-v3.4.0-ea1)"
42+
exit 1
43+
fi
44+
echo "Branch name '${BRANCH}' is valid."
45+
46+
- name: Checkout ${{ env.DEFAULT_BRANCH }}
47+
uses: actions/checkout@v6
48+
with:
49+
ref: ${{ env.DEFAULT_BRANCH }}
50+
fetch-depth: 0
51+
52+
- name: Create release branch
53+
run: |
54+
BRANCH="${{ inputs.release_branch }}"
55+
SOURCE_REF="${{ inputs.source_ref }}"
56+
if [[ -n "${SOURCE_REF}" ]]; then
57+
echo "Creating release branch from SHA: ${SOURCE_REF}"
58+
git checkout "${SOURCE_REF}"
59+
else
60+
echo "Creating release branch from latest ${{ env.DEFAULT_BRANCH }}"
61+
fi
62+
git checkout -b "${BRANCH}"
63+
git push origin "${BRANCH}"
64+
echo "::notice::Created release branch '${BRANCH}' from ${SOURCE_REF:-${{ env.DEFAULT_BRANCH }}}"
65+
66+
tag-release:
67+
needs: create-release-branch
68+
if: inputs.create_tag
69+
runs-on: ubuntu-latest
70+
permissions:
71+
contents: write
72+
steps:
73+
- name: Checkout release branch
74+
uses: actions/checkout@v6
75+
with:
76+
ref: ${{ inputs.release_branch }}
77+
fetch-depth: 0
78+
79+
- name: Derive tag and push
80+
id: derive-tag
81+
run: |
82+
BRANCH="${{ inputs.release_branch }}"
83+
TAG="${BRANCH#release-}"
84+
echo "Tagging release branch '${BRANCH}' as '${TAG}'"
85+
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
86+
87+
git tag "${TAG}"
88+
git push origin "${TAG}"
89+
echo "::notice::Created and pushed tag '${TAG}'"
90+
outputs:
91+
tag: ${{ steps.derive-tag.outputs.tag }}
92+
93+
create-release:
94+
needs: tag-release
95+
if: inputs.create_tag && inputs.create_release
96+
runs-on: ubuntu-latest
97+
permissions:
98+
contents: write
99+
steps:
100+
- name: Create GitHub release
101+
uses: softprops/action-gh-release@v2
102+
with:
103+
tag_name: ${{ needs.tag-release.outputs.tag }}
104+
name: ODH release ${{ needs.tag-release.outputs.tag }}
105+
generate_release_notes: true
106+
prerelease: ${{ contains(needs.tag-release.outputs.tag, '-') }}

0 commit comments

Comments
 (0)