From ea7af4103be58958381ec7a25e693856cab7f890 Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Thu, 19 Dec 2024 06:52:49 +0000 Subject: [PATCH] Automatically manage pre-release branches A k8s-snap PR automatically creates and cleans up git branches for upstream k8s pre-releases: https://github.com/canonical/k8s-snap/pull/916 Here we're adding an almost identical job that picks up these git branches and prepares launchpad recipes. TODOs: * clean up obsolete pre-releases that were superseeded by a new pre-release or stable release * promote beta and rc pre-releases to the corresponding snap risk level --- .../update-pre-release-branches.yaml | 66 +++++++++++++++++++ scripts/requirements.txt | 2 + test_requirements.txt | 1 + 3 files changed, 69 insertions(+) create mode 100755 .github/workflows/update-pre-release-branches.yaml diff --git a/.github/workflows/update-pre-release-branches.yaml b/.github/workflows/update-pre-release-branches.yaml new file mode 100755 index 0000000..df5daee --- /dev/null +++ b/.github/workflows/update-pre-release-branches.yaml @@ -0,0 +1,66 @@ +name: Auto-update pre-release branches + +on: + pull_request: + paths: + - .github/workflows/update-pre-release-branches.yaml + schedule: + # Run 20 minutes after midnight, giving the k8s-snap nightly job + # enough time to pick up new k8s releases and setup the git branches. + - cron: "20 0 * * *" + +permissions: + contents: read + +jobs: + update-branches: + permissions: + contents: write # for Git to git push + runs-on: ubuntu-latest + outputs: + preRelease: ${{ steps.determine.outputs.preRelease }} + gitBranch: ${{ steps.determine.outputs.gitBranch }} + steps: + - name: Harden Runner + uses: step-security/harden-runner@v2 + with: + egress-policy: audit + - 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.12' + cache: 'pip' + - name: Install Python dependencies + run: pip3 install -r ./scripts/requirements.txt + - name: Determine outstanding pre-release + id: determine + run: | + preRelease=`python3 ./scripts/k8s_releases.py get_outstanding_prerelease` + echo "preRelease=$preRelease" >> "$GITHUB_OUTPUT" + + if [[ -n "$preRelease" ]]; then + gitBranch="autoupdate/$preRelease" + fi + echo "gitBranch=$gitBranch" >> "$GITHUB_OUTPUT" + - name: Create pre-release branch ${{ steps.determine.outputs.gitBranch }} + if: ${{ steps.determine.outputs.preRelease }} != '' + uses: ./.github/workflows/create-release-branch.yaml + with: + branches: ${{ steps.determine.outputs.gitBranch }} + - 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 + gitBranch="autoupdate/${outstandingPreRelease}" + echo "Cleaning up obsolete pre-release branch: $gitBranch" + # TODO + done diff --git a/scripts/requirements.txt b/scripts/requirements.txt index 9261e98..db6c9e9 100644 --- a/scripts/requirements.txt +++ b/scripts/requirements.txt @@ -4,6 +4,8 @@ httplib2==0.22.0 launchpadlib==1.11.0 lazr-restfulclient==0.14.6 lazr-uri==1.0.6 +packaging==24.2 +requests==2.32.3 semver==3.0.2 six==1.16.0 tox==4.20.0 diff --git a/test_requirements.txt b/test_requirements.txt index 031ed92..920b206 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -1,2 +1,3 @@ freezegun pytest +types-requests