Skip to content

Commit

Permalink
feat: allow configuring base/target branch for automatic release note…
Browse files Browse the repository at this point in the history
…s and image bump PRs (#5210)

Co-authored-by: Cameron Meissner <[email protected]>
  • Loading branch information
cameronmeissner and Cameron Meissner authored Nov 4, 2024
1 parent 0229dfc commit 69e31e4
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 26 deletions.
6 changes: 6 additions & 0 deletions .pipelines/.vsts-vhd-automation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ parameters:
- name: VHD_BUILD_ID
displayName: VHD Build ID
type: string
- name: PRTargetBranch
displayName: PR Target Branch
type: string
default: master
- name: ImageBump
displayName: Image Bump + Create Official Branch
type: boolean
Expand Down Expand Up @@ -43,6 +47,7 @@ stages:
GITHUB_PAT: $(GITHUB_PAT)
IMAGE_VERSION: $(IMAGE_VERSION)
VHD_BUILD_ID: ${{ parameters.VHD_BUILD_ID }}
PR_TARGET_BRANCH: ${{ parameters.PRTargetBranch }}
displayName: 'Bump image version and create official branch'
- stage: generate_release_notes
dependsOn: []
Expand All @@ -66,6 +71,7 @@ stages:
IMAGE_VERSION: $(IMAGE_VERSION)
VHD_BUILD_ID: ${{ parameters.VHD_BUILD_ID }}
SKIP_LATEST: $(SKIP_LATEST_RELEASE_NOTES_UPDATE)
PR_TARGET_BRANCH: ${{ parameters.PRTargetBranch }}
displayName: 'Generate release notes'
- stage: create_release
dependsOn: []
Expand Down
7 changes: 6 additions & 1 deletion .pipelines/templates/.set-image-version-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ parameters:

steps:
- bash: |
[ -n "$IMAGE_VERSION_OVERRIDE" ] && echo "IMAGE_VERSION_OVERRIDE is set to $IMAGE_VERSION_OVERRIDE" && exit 0
if [ -n "$IMAGE_VERSION_OVERRIDE" ]; then
echo "IMAGE_VERSION_OVERRIDE is set to $IMAGE_VERSION_OVERRIDE"
echo "##vso[task.setvariable variable=IMAGE_VERSION]$IMAGE_VERSION_OVERRIDE"
exit 0
fi
source vhdbuilder/scripts/automate_generate_version.sh
echo "setting image version to $GENERATED_IMAGE_VERSION"
echo "##vso[task.setvariable variable=IMAGE_VERSION]$GENERATED_IMAGE_VERSION"
Expand Down
59 changes: 38 additions & 21 deletions vhdbuilder/scripts/automate_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,65 @@ retrycmd_if_failure() {

set_git_config() {
# git config needs to be set in the agent
git config --global user.email "amaheshwari@microsoft.com"
git config --global user.name "anujmaheshwari1"
git config --global user.email "aks-node@microsoft.com"
git config --global user.name "aks-node"
git config --list
}

create_branch() {
local branch_name=$1
local base_branch=$2
if [ -z "$base_branch" ]; then
echo "create_branch: base_branch not specified, will default to master"
base_branch="master"
fi

# Create PR branch
echo "Create branch named $1"
git checkout master
echo "Create branch named $branch_name off of $base_branch"
git checkout $base_branch
git pull
git checkout -b $1
git checkout -b $branch_name
}

create_pull_request() {
local image_version=$1
local github_pat=$2
local branch_name=$3
local base_branch=$4
local target=$5
if [ -z "$base_branch" ]; then
echo "create_pull_request: base_branch not specified, will default to master"
base_branch="master"
fi

# Commit current changes and create PR using curl
echo "Image Version is $1"
echo "Branch Name is $3"
echo "PR is for $4"
echo "Image Version is $image_version"
echo "Branch Name is $branch_name"
echo "PR is for $target"

git remote set-url origin https://anujmaheshwari1:$2@github.com/Azure/AgentBaker.git # Set remote URL with PAT
set +x # to avoid logging PAT
git remote set-url origin https://${github_pat}@github.com/Azure/AgentBaker.git # Set remote URL with PAT
git add .

if [[ $4 == "ReleaseNotes" ]]; then
git commit -m "chore: release notes for release $1"
if [[ "$target" == "ReleaseNotes" ]]; then
git commit -m "chore: release notes for release $image_version"
else
git commit -m "chore: bumping image version to $1"
git commit -m "chore: bumping image version to $image_version"
fi

git push -u origin $3 -f
git push -u origin $branch_name -f

set +x # To avoid logging PAT during curl
curl \
-X POST \
-H "Authorization: Bearer $github_pat" \
https://api.github.com/repos/Azure/AgentBaker/pulls \
-d '{
"head" : "'$3'",
"base" : "master",
"title" : "chore: automated PR to update '$4' for '$1' VHD",
"body" : "This is an automated PR to bump '$4' for the VHD release with image version '$1'"
}' \
-u "anujmaheshwari1:$2"
"head" : "'$branch_name'",
"base" : "'$base_branch'",
"title" : "chore: automated PR to update '$target' for '$image_version' VHD",
"body" : "This is an automated PR to bump '$target' for the VHD release with image version '$image_version'"
}'

set -x

git checkout master # Checkout to master for subsequent stages of the pipeline
}
5 changes: 3 additions & 2 deletions vhdbuilder/scripts/automate_release_notes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set -x
IMAGE_VERSION="${IMAGE_VERSION:-""}"
VHD_BUILD_ID="${VHD_BUILD_ID:-""}"
SKIP_LATEST="${SKIP_LATEST:-false}"
PR_TARGET_BRANCH="${PR_TARGET_BRANCH:-master}"

generate_release_notes() {
included_skus=""
Expand Down Expand Up @@ -58,10 +59,10 @@ if [ `git branch --list $BRANCH_NAME` ]; then
git pull origin
git checkout master -- .
else
create_branch $BRANCH_NAME
create_branch $BRANCH_NAME $PR_TARGET_BRANCH
fi

retrycmd_if_failure 5 10 generate_release_notes || exit $?
git status
set +x
create_pull_request $IMAGE_VERSION $GITHUB_PAT $BRANCH_NAME $PR_TITLE
create_pull_request $IMAGE_VERSION $GITHUB_PAT $BRANCH_NAME $PR_TARGET_BRANCH $PR_TITLE
5 changes: 3 additions & 2 deletions vhdbuilder/scripts/automate_version_bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set -x

NEW_IMAGE_VERSION="${IMAGE_VERSION:-""}"
VHD_BUILD_ID="${VHD_BUILD_ID:-""}"
PR_TARGET_BRANCH="${PR_TARGET_BRANCH:-master}"

# This function takes the build ID and reads the queue time.
# It then sanitizes the queue time in the format that the Canonical snapshot endpoint expects, which is 20230727T000000Z
Expand Down Expand Up @@ -57,11 +58,11 @@ update_image_version() {
}

create_image_bump_pr() {
create_branch $BRANCH_NAME
create_branch $BRANCH_NAME $PR_TARGET_BRANCH
update_image_version

set +x
create_pull_request $NEW_IMAGE_VERSION $GITHUB_PAT $BRANCH_NAME $PR_TITLE
create_pull_request $NEW_IMAGE_VERSION $GITHUB_PAT $BRANCH_NAME $PR_TARGET_BRANCH $PR_TITLE
set -x
}

Expand Down

0 comments on commit 69e31e4

Please sign in to comment.