Skip to content

Commit

Permalink
Merge pull request #845 from ivanvc/add-github-action-to-keep-release…
Browse files Browse the repository at this point in the history
…-up-to-date

github/workflows: introduce action to update version tag
  • Loading branch information
jmhbnz authored Jun 13, 2024
2 parents 64b98a4 + 5d78a53 commit 9c6be95
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/update-release-version-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: Reusable Template to Update Release

on:
workflow_call:
inputs:
release:
type: string
required: true

jobs:
update-release:
name: Update Release
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- id: latest-release
env:
GH_TOKEN: ${{ github.token }}
run: |
echo version="$(gh release list --repo etcd-io/etcd --json 'tagName' -q 'map(select(.tagName | test("^'"$(echo "${{ inputs.release }}." | sed s/\\./\\\./g)"'"))) | .[0].tagName')" >> "$GITHUB_OUTPUT"
- env:
GH_TOKEN: ${{ github.token }}
run: |
make update-release-version LATEST_VERSION="${{ steps.latest-release.outputs.version }}"
19 changes: 19 additions & 0 deletions .github/workflows/update-release-version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Update Latest Release Versions Nightly
permissions:
contents: write
pull-requests: write
on:
schedule:
- cron: '25 9 * * *' # runs every day at 09:25 UTC
workflow_dispatch:

jobs:
v3_4:
uses: ./.github/workflows/update-release-version-template.yaml
with:
release: v3.4
v3_5:
uses: ./.github/workflows/update-release-version-template.yaml
with:
release: v3.5
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ get-link-checker:

clean:
rm -rf $(HTMLTEST_DIR) public/* resources

.PHONY: update-release-version
update-release-version:
ifndef LATEST_VERSION
@echo "LATEST_VERSION needs to be specified" && exit 1
else
./scripts/update_release_version.sh "$(LATEST_VERSION)"
endif
60 changes: 60 additions & 0 deletions scripts/update_release_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
# This script updates the version of the release in the release file
# Usage: ./update_release_version.sh <new_version>

set -eo pipefail

if [ "$#" -ne 1 ]; then
echo "Usage: $0 <new_version>"
exit 1
fi

new_version="$1"
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
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"
fi

# Check for prerequisites to run the script.
if ! which gh >/dev/null; then
echo "gh needs to be installed for this script to work"
exit 1
fi
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"
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"
exit 0
fi

# Switch to a new branch.
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"

# 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
[${release_minor}] Update installation version to latest tag (${new_version})
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}"

0 comments on commit 9c6be95

Please sign in to comment.