Skip to content

Commit

Permalink
chore(github-action): create release-<x> branches
Browse files Browse the repository at this point in the history
Based on k3s releases branches detection. It runs once a week on monday
  • Loading branch information
o-orand committed Jan 3, 2024
1 parent bee524e commit e581a5f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 7 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/create-release-branches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: create-release-branches

on:
workflow_call:
inputs:
force_push:
description: 'Force recreation of release branches from min version'
required: true
type: boolean
default: false
workflow_dispatch:
inputs:
force_push:
description: 'Force recreation of release branches from min version'
required: true
type: boolean
default: false
schedule:
- cron: "30 10 * * 1" # “At 10:30 on Monday.” https://crontab.guru/#30_10_*_*_1
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

# GH cli is already pre-install, see https://docs.github.com/en/actions/using-workflows/using-github-cli-in-workflows

- name: Install yq cli
#See https://github.com/marketplace/actions/install-a-binary-from-github-releases
uses: jaxxstorm/[email protected]
with:
repo: mikefarah/yq
tag: v4.34.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # reduce potential rate limiting

- name: create-missing-branches
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FORCE_PUSH: ${{ inputs.force_push}}
run: |
# configure git
git config --global user.name "actions/k3s-boshrelease"
git config --global user.email "<>"
git config --global --add safe.directory /github/workspace
./create-release-branches.bash
29 changes: 22 additions & 7 deletions create-release-branches.bash
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
#!/bin/bash
set -x
#set -x
set -e # exit on non-zero status

for v in 1.25 1.26 1.27 1.28 1.29 1.30 1.31 ; do
BRANCH_NAME="release-${v}"
git branch -d $BRANCH_NAME
git co -b $BRANCH_NAME
PUSH_OPTIONS=""
if [ $FORCE_PUSH = "true" ] ;then
PUSH_OPTIONS="$PUSH_OPTIONS --force"
fi
current_version=$(yq -r '.directories[0].contents[] | select (.path=="k3s-io/k3s") | .githubRelease.tag ' ./vendir.yml)
current_version=${current_version#v}
MIN_VERSION=$(echo "$current_version"|cut -d'.' -f1-2)
for ref in $(git ls-remote -h https://github.com/k3s-io/k3s "release-*" | sed 's/refs\/heads\///' | awk '{print $2}') ; do
v=${ref#release-}
BRANCH_NAME="${ref}"
echo "Extracted values - v: $v - BRANCH_NAME: $BRANCH_NAME"
if [ $(echo "$v <= $MIN_VERSION"|bc) -eq 1 ];then
echo "Skipping version $v"
continue
else
echo "Keeping $v as $v > $MIN_VERSION"
fi
continue
git branch -d "$BRANCH_NAME"
git co -b "$BRANCH_NAME"
sed -i.orig "s/tag: v.*/tag: v${v}.0/g" vendir.yml
! diff vendir.yml vendir.yml.orig
rm vendir.yml.orig
git add vendir.yml
git commit -m "Initial branch creation for k8s version $v"
git push --set-upstream origin $BRANCH_NAME --force
! gh pr create --base master --repo orange-cloudfoundry/k3s-packages-boshrelease --fill --body "Track divergence of release branches with master"
git push --set-upstream origin "$BRANCH_NAME" $PUSH_OPTIONS
git co master
done

0 comments on commit e581a5f

Please sign in to comment.