Skip to content

Commit

Permalink
Merge pull request #872 from ivanvc/skip-creating-a-pull-request-in-v…
Browse files Browse the repository at this point in the history
…ersion-automation

Improvements to the GitHub update release version workflow
  • Loading branch information
jmhbnz authored Jul 19, 2024
2 parents 65d06b4 + 8001a25 commit 44ccba9
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions scripts/update_release_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ if [ "$#" -ne 1 ]; then
fi

new_version="$1"
release_minor=$(echo "$new_version" | cut -d. -f1-2)
index_file=content/en/docs/"$release_minor"/_index.md
release_minor=$(echo "${new_version}" | cut -d. -f1-2)
index_file=content/en/docs/"${release_minor}"/_index.md
git_remote="${GIT_REMOTE:-origin}"
branch="release-${release_minor}-update-latest-release-to-${new_version}"
current_branch=$(git symbolic-ref HEAD --short)

if [ -z "$GITHUB_ACTOR" ]; then
if [ -z "${GITHUB_ACTIONS}" ]; then
git_author="$(git config user.name)"
git_email="$(git config user.email)"
else
git_author="$GITHUB_ACTOR"
git_email="$GITHUB_ACTOR@users.noreply.github.com"
# Refer to https://github.com/orgs/community/discussions/26560#discussioncomment-3252340
git_author="github-actions[bot]"
git_email="41898282+github-actions[bot]@users.noreply.github.com"
fi

# Check for prerequisites to run the script.
Expand All @@ -33,28 +34,33 @@ if ! gh auth status >/dev/null; then
echo "gh needs to be authenticated for this script to work"
exit 1
fi
if ! grep git_version_tag "$index_file" | grep -v -e "$new_version\$" >/dev/null; then
echo "nothing to do; file $index_file is already up to date with $new_version"
if ! grep git_version_tag "${index_file}" | grep -v -e "${new_version}\$" >/dev/null; then
echo "nothing to do; file ${index_file} is already up to date with ${new_version}"
exit 0
fi
if git ls-remote --exit-code "$git_remote" --heads refs/heads/"$branch" >/dev/null; then
echo "nothing to do; branch $branch already exists"
if git ls-remote --exit-code "${git_remote}" --heads refs/heads/"${branch}" >/dev/null; then
echo "nothing to do; branch ${branch} already exists"
exit 0
fi

# Switch to a new branch.
git checkout -b "$branch"
trap 'git checkout "$current_branch"' EXIT
git checkout -b "${branch}"
trap 'git checkout "${current_branch}"' EXIT

# Update the release version in the release file.
sed -i 's/git_version_tag:\sv\([0-9]\+\.\)\{2\}[0-9]\+/git_version_tag: '"$new_version"'/' "$index_file"
sed -i 's/git_version_tag:\sv\([0-9]\+\.\)\{2\}[0-9]\+/git_version_tag: '"${new_version}"'/' "${index_file}"

# Commit the changes, push and create a PR.
git add "$index_file"
git -c user.name="$git_author" -c user.email="$git_email" commit --file=- <<EOL
git add "${index_file}"
git -c user.name="${git_author}" -c user.email="${git_email}" commit --file=- <<EOL
[${release_minor}] Update installation version to latest tag (${new_version})
cc. @etcd-io/maintainers-website
Signed-off-by: ${git_author} <${git_email}>
EOL
git push "$git_remote" "$branch"
gh pr create --fill --body "Automated update for ${release_minor}: ${new_version}"
git push "${git_remote}" "${branch}"

if [ -n "${CREATE_PULL_REQUEST}" ]; then
gh pr create --fill --body "Automated update for ${release_minor}: ${new_version}"
fi

0 comments on commit 44ccba9

Please sign in to comment.