Skip to content

Commit

Permalink
Add a new workflow to create a dev branch
Browse files Browse the repository at this point in the history
  • Loading branch information
eg-ayoub committed Nov 29, 2024
1 parent 14a55a3 commit bc63a63
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 0 deletions.
146 changes: 146 additions & 0 deletions .github/workflows/create-dev-branch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: "Create Development Branch"
run-name: Create a new development branch

on:
workflow_dispatch:
inputs:
bump-type:
description: "bump type"
required: true
type: choice
default: "major"
options:
- "major"
- "minor"

jobs:
create-branch:
runs-on: ubuntu-24.04
steps:
# validate branch
- name: Validate running branch
run: |
# we want to stop if this is not running on development branch
[[ "${{github.ref_name}}" =~ ^development/[0-9.]+$ ]] || exit 1
# create app token
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.ACTIONS_APP_ID }}
private-key: ${{ secrets.ACTIONS_APP_PRIVATE_KEY }}
# checkout
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
# calculate new version
- name: Calculate new version
run: |
source VERSION
if [[ "${{ inputs.bump-type }}" == "major" ]]; then
NEW_VERSION_MAJOR=$(($VERSION_MAJOR+1))
NEW_VERSION_MINOR=0
else
NEW_VERSION_MAJOR=$VERSION_MAJOR
NEW_VERSION_MINOR=$(($VERSION_MINOR+1))
fi
NEW_SHORT_VERSION="$NEW_VERSION_MAJOR.$NEW_VERSION_MINOR"
echo "NEW_SHORT_VERSION=$NEW_SHORT_VERSION" >> $GITHUB_ENV
echo "NEW_VERSION_MAJOR=$NEW_VERSION_MAJOR" >> $GITHUB_ENV
echo "NEW_VERSION_MINOR=$NEW_VERSION_MINOR" >> $GITHUB_ENV
# calculate new branch name
- name: Calculate new branch name
run: |
NEW_BRANCH_NAME="development/${{ env.NEW_SHORT_VERSION }}"
INIT_BRANCH_NAME="feature/init-dev-${{ env.NEW_SHORT_VERSION }}"
echo "NEW_BRANCH_NAME=$NEW_BRANCH_NAME" >> $GITHUB_ENV
echo "INIT_BRANCH_NAME=$INIT_BRANCH_NAME" >> $GITHUB_ENV
# create development branch
- name: Create new branch
run: |
git ls-remote --exit-code --heads origin refs/heads/${{ env.NEW_BRANCH_NAME }}
if [[ $? = 0 ]]; then
echo "${{ env.NEW_BRANCH_NAME }} already exists, exiting"
exit 1
fi
git checkout -b "${{ env.NEW_BRANCH_NAME }}"
# push development branch
- name: Push new branch
run: |
git config --global user.email ${{ github.actor }}@scality.com
git config --global user.name ${{ github.actor }}
git push --set-upstream origin ${{ env.NEW_BRANCH_NAME }}
# create new branch
- name: Create an init branch
run: |
git checkout -b "${{ env.INIT_BRANCH_NAME }}"
# find mentions of new version: warn user
- name: Look for important messages
id: warn_user
run: |
link="https://github.com/${{ github.repository }}/blob/${{ env.NEW_BRANCH_NAME }}/"
{
echo 'COMMENT<<EOF'
echo "# Mentions of ${{ env.NEW_SHORT_VERSION }} in ${{ env.NEW_BRANCH_NAME }}"
git grep -rHFn "${{ env.NEW_SHORT_VERSION }}" | sed -E "s;(.*):([0-9]+):.*;$link\1#L\2;"
echo EOF
} >> "$GITHUB_ENV"
# bump version
- name: Bump VERSION
run: |
cat << EOF > VERSION
VERSION_MAJOR=${{ env.NEW_VERSION_MAJOR }}
VERSION_MINOR=${{ env.NEW_VERSION_MINOR }}
VERSION_PATCH=0
VERSION_SUFFIX=-dev
EOF
# edit CHANGELOG
- name: add new entry to changelog
run: |
sed -i "s/# CHANGELOG/# CHANGELOG\n\n## Release ${{ env.NEW_SHORT_VERSION }}.0 (in development)/" CHANGELOG.md
# edit cron jobs
- name: bump version in cron jobs
run: |
current=$(grep current .github/workflows/crons.yaml | sed -E "s/\s*# current=//")
old=$(grep old .github/workflows/crons.yaml | sed -E "s/\s*# old=//")
sed -i "s/$current/${{ env.NEW_SHORT_VERSION }}/g" .github/workflows/crons.yaml
sed -i "s/$old/$current/g" .github/workflows/crons.yaml
# push
- name: push to init branch
run: |
git add VERSION
git add CHANGELOG.md
git add .github/workflows/crons.yaml
git commit -m "Update version to ${{ env.NEW_SHORT_VERSION }}"
git push --set-upstream origin ${{ env.INIT_BRANCH_NAME }}
# create PR
- name: create PR
uses: actions/github-script@v7
with:
script: |
const pr = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
head: "${{ env.INIT_BRANCH_NAME }}",
base: "${{ env.NEW_BRANCH_NAME }}",
title: "Initialize ${{ env.NEW_BRANCH_NAME }} branch"
});
await github.rest.issues.createComment({
issue_number: pr.data.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `/approve`
});
await github.rest.issues.createComment({
issue_number: pr.data.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${{ env.COMMENT }}`
});
4 changes: 4 additions & 0 deletions .github/workflows/crons.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ jobs:
fail-fast: false
matrix:
include:
# these helper comments are needed by the dev branch workflow
# please do not edit them unless you're changing the version as well
# current=129.0
- name: "Nightly for MetalK8s 129.0"
cron: "0 1 * * 1-5"
branch: "development/129.0"
workflow: "nightly.yaml"
# old=128.0
- name: "Nightly for MetalK8s 128.0"
cron: "0 2 * * 1-5"
branch: "development/128.0"
Expand Down

0 comments on commit bc63a63

Please sign in to comment.