-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically manage pre-release branches
We need to automatically create k8s-snap branches for upstream pre-releases such as v1.33.0-alpha.1. Whenever a new pre-release or stable release comes out, the old pre-release branches become obsolete and are automatically removed. Note that these branches are used by the Launchpad recipes to produce and publish k8s-snap builds.
- Loading branch information
1 parent
3f30d5b
commit f81a49d
Showing
3 changed files
with
96 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: Auto-update pre-release branches | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
paths: | ||
- .github/workflows/update-pre-release-branches.yaml | ||
schedule: | ||
- cron: "0 0 * * *" # Runs every midnight | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
update-branches: | ||
permissions: | ||
contents: write # for Git to git push | ||
runs-on: ubuntu-latest | ||
outputs: | ||
preRelease: ${{ steps.determine.outputs.preRelease }} | ||
branch: ${{ steps.determine.outputs.branch }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
ssh-key: ${{ secrets.BOT_SSH_KEY }} | ||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.10' | ||
- name: Install Python dependencies | ||
run: pip3 install packaging requests | ||
- name: Determine outstanding pre-release | ||
id: determine | ||
run: | | ||
preRelease=`python3 ./build-scripts/k8s_releases.py get_outstanding_prerelease` | ||
echo "preRelease=$preRelease" >> "$GITHUB_OUTPUT" | ||
if [[ -n "$preRelease" ]]; then | ||
branch="autoupdate/$preRelease" | ||
fi | ||
echo "branch=$branch" >> "$GITHUB_OUTPUT" | ||
- name: Define git credentials | ||
run: | | ||
# Needed to create commits. | ||
git config --global user.name "Github Actions" | ||
git config --global user.email "worker@org.com" | ||
- name: 'Update k8s component version: ${{ steps.determine.outputs.preRelease }}' | ||
if: ${{ steps.determine.outputs.preRelease }} != '' | ||
run: | | ||
echo ${{ steps.determine.outputs.preRelease }} > ./build-scripts/components/kubernetes/version | ||
git add ./build-scripts/components/kubernetes/version | ||
git commit -m "Update k8s version to ${{ steps.determine.outputs.preRelease }}" | ||
- name: Create pre-release branch ${{ steps.determine.outputs.branch }} | ||
if: ${{ steps.determine.outputs.preRelease }} != '' | ||
run: | | ||
git checkout -b ${{ steps.determine.outputs.branch }} | ||
git push origin --force ${{ steps.determine.outputs.branch }} | ||
- name: Clean obsolete branches | ||
run: | | ||
git fetch origin | ||
# Log the latest release for reference. | ||
latestRelease=`python3 ./build-scripts/k8s_releases.py get_latest_release` | ||
echo "Latest k8s release: $latestRelease" | ||
for outstandingPreRelease in `python3 ./build-scripts/k8s_releases.py get_obsolete_prereleases`; do | ||
branch="autoupdate/${outstandingPreRelease}" | ||
if git branch -r | grep "origin/$branch"; then | ||
echo "Cleaning up obsolete pre-release branch: $branch" | ||
git push origin --delete $branch | ||
else | ||
echo "Obsolete branch not found, skpping: $branch" | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters