Skip to content

Merge pull request #1342 from maqiuyujoyce/202403-stop-merging-sensit… #2

Merge pull request #1342 from maqiuyujoyce/202403-stop-merging-sensit…

Merge pull request #1342 from maqiuyujoyce/202403-stop-merging-sensit… #2

# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Upgrade Operator
on:
push:
# The action is only triggered when a new tag following the current
# convention is created.
tags: [ "v1.[0-9]+.[0-9]+" ]
jobs:
upgrade:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
with:
# This is to get all the commits.
fetch-depth: 0
- uses: actions/setup-go@v4
with:
go-version: "1.21.5"
- name: "Set env"
run: |
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
# ${{ env.RELEASE_VERSION }} is not accessible in the same step when it is
# set.
- name: "Check current state"
run: |
git config user.name "GitHub Actions Bot"
git config user.email "[email protected]"
echo "Checking the current state..."
echo "Release version: ${{ env.RELEASE_VERSION }}"
echo "Location: $(pwd)"
echo "Last 10 commits:"
git log --oneline -10
echo "Current branch:"
git branch
- name: "Upgrade KCC operator"
run: |
echo "Running 'make upgrade-kcc'..."
make -C operator upgrade-kcc
echo "Ensuring there is diff and committing the change..."
if [[ -z `git status --porcelain` ]]; then
echo "Exiting the workflow as there is no change to generate a PR."
exit 1
fi
git add -A .
git commit -m "Upgrade KCC operator to version ${{ env.RELEASE_VERSION }}"
- name: "Create PR"
run: |
echo "Adding a remote pointing to GoogleCloudPlatform/k8s-config-connector..."
git remote add target https://github.com/GoogleCloudPlatform/k8s-config-connector.git
export BRANCH=operator-upgrade-$(date +"%Y%m%d%H%M%S")
echo "Setting up branch '${BRANCH}'..."
git checkout -b ${BRANCH}
echo "Creating the PR against master branch of GoogleCloudPlatform/k8s-config-connector..."
git push -u target ${BRANCH}
gh repo set-default GoogleCloudPlatform/k8s-config-connector
gh pr create --head ${BRANCH} --title 'Upgrade KCC operator to version ${{ env.RELEASE_VERSION }}' --body 'Upgrade KCC operator to version ${{ env.RELEASE_VERSION }}.'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}