Skip to content

Commit 17e2be1

Browse files
committed
Automate new-release, new-patch and upstream-versions
1 parent b74ada6 commit 17e2be1

File tree

6 files changed

+243
-76
lines changed

6 files changed

+243
-76
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Automated Release Actions
2+
on:
3+
schedule:
4+
- cron: "0 0 * * *" # At every day at 00
5+
workflow_dispatch:
6+
inputs:
7+
action:
8+
description: 'Select Action'
9+
required: true
10+
type: choice
11+
options:
12+
- new-release
13+
- new-patch
14+
- update-upstream-versions
15+
version:
16+
description: |
17+
Provide Release Version for the action. Eg 1.22 or 1.23'
18+
Please do not attach the patch version in this.
19+
For new releases patch version defaults to 0 and for new-patch action patch version is auto increased.
20+
21+
required: true
22+
default: 'next'
23+
type: string
24+
permissions:
25+
contents: read
26+
issues: write
27+
repository-projects: write
28+
jobs:
29+
run-release:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v4
34+
35+
- name: Debug inputs
36+
run: |
37+
echo "Action: ${{ github.event.inputs.action }}"
38+
echo "Version: ${{ github.event.inputs.version }}"
39+
40+
- name: Run Release Script
41+
run: |
42+
./release-manager.sh \
43+
--action "${{ github.event.inputs.action }}" \
44+
--version "${{ github.event.inputs.version }}"
45+
- name: Create Pull Request
46+
run: |
47+
BASE_BRANCH=${GITHUB_REF#refs/heads/}
48+
SOURCE_BRANCH=actions/hack/${{ github.event.inputs.action }}-${{ github.event.inputs.version }}
49+
50+
git checkout -b ${SOURCE_BRANCH}
51+
git add -f .
52+
53+
if [[ -z $(git status --porcelain --untracked-files=no) ]]; then
54+
echo "No change, exiting"
55+
exit 0
56+
fi
57+
58+
git commit -F- <<EOF
59+
[bot: ${{ github.event.inputs.version }}] Action: ${{ github.event.inputs.action }}"
60+
EOF
61+
62+
git push -f origin ${SOURCE_BRANCH}
63+
64+
if [ "$(gh pr list --base ${BASE_BRANCH} --head ${SOURCE_BRANCH} --json url --jq 'length')" = "0" ]; then
65+
echo "creating PR..."
66+
gh pr create -B ${BASE_BRANCH} -H ${SOURCE_BRANCH} --label=automated --fill
67+
fi
68+
69+
70+
env:
71+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/update-upstream-labels.yaml

Lines changed: 0 additions & 28 deletions
This file was deleted.

config/downstream/releases/main.yaml

Lines changed: 0 additions & 13 deletions
This file was deleted.

config/downstream/releases/next.yaml

Lines changed: 0 additions & 35 deletions
This file was deleted.

hack/common-functions.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash
2+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
ROOT="$(dirname "$SCRIPT_DIR")"
4+
KONFLUX_YAML="$ROOT/config/downstream/konflux.yaml"
5+
REPO_DIR="$ROOT/config/downstream/repos/"
6+
7+
function create-new-release() {
8+
RELEASE_VERSION=$1
9+
RELEASE_YAML="$ROOT/config/downstream/releases/${RELEASE_VERSION}.yaml"
10+
touch $RELEASE_YAML
11+
12+
13+
# If version already exists then no action required
14+
exists=$(yq e ".versions[] | select(. == \"$RELEASE_VERSION\")" "$KONFLUX_YAML")
15+
if [[ -n "$exists" ]]; then
16+
echo "Version $RELEASE_VERSION already exists. Skipping..."
17+
exit 0
18+
fi
19+
20+
# Add New version in konflux.yaml
21+
yq -i e ".versions += \"$RELEASE_VERSION\"" $KONFLUX_YAML
22+
23+
#Add Release name in $RELEASE_YAML
24+
yq -i e ".version = \"$RELEASE_VERSION\"" $RELEASE_YAML
25+
yq -i e ".patch-version = \"$RELEASE_VERSION.0\"" $RELEASE_YAML
26+
yq -i e ".image-suffix = \"-rhel9\"" $RELEASE_YAML
27+
28+
update-upstream-versions $RELEASE_VERSION
29+
}
30+
31+
32+
function create-new-patch(){
33+
RELEASE_VERSION=$1
34+
RELEASE_YAML="$ROOT/config/downstream/releases/${RELEASE_VERSION}.yaml"
35+
36+
patch_version=$(yq ".patch-version" $RELEASE_YAML)
37+
echo "Current Patch Version: $patch_version"
38+
39+
next_version=$(echo $patch_version | awk -F. '{printf "%d.%d.%d\n", $1, $2, $3+1}')
40+
echo "next patch Version: $next_version"
41+
42+
yq -i e ".patch-version = \"$next_version\"" $RELEASE_YAML
43+
44+
}
45+
46+
update-upstream-versions() {
47+
RELEASE_VERSION=$1
48+
RELEASE_YAML="$ROOT/config/downstream/releases/${RELEASE_VERSION}.yaml"
49+
touch $RELEASE_YAML
50+
echo "Updating upstream version for release : $RELEASE_VERSION in $RELEASE_YAML"
51+
52+
for file in "$REPO_DIR"/*.yaml; do
53+
[ -e "$file" ] || continue # Skip if no files
54+
55+
# Extract values with yq
56+
downstream="$(basename "$file" .yaml)"
57+
upstream=$(yq e '.upstream' "$file")
58+
# Skip when upstream is empty
59+
[ "$upstream" = "null" ] && upstream=""
60+
if [ -z "$upstream" ]; then
61+
continue
62+
fi
63+
64+
echo "Upstream: $upstream, Downstream: $downstream"
65+
if LATEST=$(gh release view --repo $upstream --json tagName -q .tagName 2>/dev/null); then
66+
echo "Latest release for $upstream : $LATEST"
67+
else
68+
echo "⚠ No releases found for $upstream"
69+
continue
70+
fi
71+
BRANCH="release-${LATEST%.*}.x"
72+
yq -i e ".branches.$downstream.upstream = \"$BRANCH\"" $RELEASE_YAML
73+
done
74+
}
75+
76+
77+
78+

hack/release-manager.sh

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6+
ROOT="$(dirname "$SCRIPT_DIR")"
7+
8+
9+
source $SCRIPT_DIR/common-functions.sh
10+
11+
# Default values
12+
ACTION="update-upstream-versions"
13+
VERSION="next"
14+
ENVIRONMENT="dev"
15+
16+
17+
help() {
18+
cat <<EOF
19+
Usage: $0 [OPTIONS]
20+
21+
Required Flags:
22+
--action, -a Action to perform. Supported values:
23+
* new-release Create a new release version
24+
* new-patch Create a new patch version
25+
* update-upstream-versions Update upstream related versions
26+
27+
--version, -v Version to operate on (e.g., 1.23.0)
28+
29+
Optional Flags:
30+
--env, --environment, -e Target environment (optional)
31+
--help, -h Show this help message and exit
32+
33+
Examples:
34+
$0 --action new-release --version 1.23.0
35+
$0 -a new-patch -v 1.23.0
36+
$0 -a update-upstream-versions -v 1.24.0
37+
38+
Description:
39+
This script automates release version operations. It will call different
40+
internal functions based on the selected action:
41+
- create-new-release
42+
- create-new-patch
43+
- update-upstream-versions
44+
EOF
45+
exit 1
46+
}
47+
48+
# Parse named args
49+
while [[ $# -gt 0 ]]; do
50+
case "$1" in
51+
--action | -a)
52+
ACTION="$2"
53+
shift 2
54+
;;
55+
--version | -v)
56+
VERSION="$2"
57+
shift 2
58+
;;
59+
--env|--environment | -e)
60+
ENVIRONMENT="$2"
61+
shift 2
62+
;;
63+
--help|-h)
64+
help
65+
;;
66+
*)
67+
echo "Unknown parameter: $1"
68+
help
69+
;;
70+
esac
71+
done
72+
73+
# Validate required params
74+
if [[ -z "$ACTION" || -z "$VERSION" ]]; then
75+
echo "Missing required parameters!"
76+
help
77+
fi
78+
79+
# Call specific function based on ACTION
80+
case "$ACTION" in
81+
"new-release")
82+
create-new-release $VERSION
83+
;;
84+
"new-patch")
85+
create-new-patch $VERSION
86+
;;
87+
"update-upstream-versions")
88+
update-upstream-versions $VERSION
89+
;;
90+
*)
91+
echo "Invalid action: $ACTION"
92+
help
93+
;;
94+
esac

0 commit comments

Comments
 (0)