Skip to content

Create release branch GitHub workflow #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions .github/workflows/create_release_branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Create Release Branch Workflow
on:
workflow_dispatch:
inputs:
version:
description: "Release version"
required: true
type: string
branch_name:
description: "Release branch name"
required: true
type: string
commit_sha:
description: "Optional commit SHA to start release branch from. By default, it will use the latest commit on the main branch."
required: false
type: string

jobs:
create-release-branch:
runs-on: ubuntu-latest
steps:

- name: Create GitHub App Token
uses: actions/create-github-app-token@v2
id: app-token
with:
app-id: ${{ vars.MONGODB_KUBERNETES_APP_ID }}
private-key: ${{ secrets.MONGODB_KUBERNETES_APP_PRIVATE_KEY }}

- name: Checkout repository (master)
if: ${{ github.event.inputs.commit_sha == '' }}
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
ref: ${{ github.head_ref }}

- name: Checkout repository (commit SHA))
if: ${{ github.event.inputs.commit_sha != '' }}
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
ref: ${{ github.event.inputs.commit_sha }}

- name: Get GitHub App User ID
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}

- name: Set up Git
id: setup-git
run: |
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'

- name: Check if release branch already exists
id: check-branch
run: |
if git show-ref --verify --quiet refs/heads/${{ github.event.inputs.branch_name }}; then
echo "Release branch ${{ github.event.inputs.branch_name }} already exists."
git checkout ${{ github.event.inputs.branch_name }}
else
echo "create_new_branch=true" >> $GITHUB_ENV
fi

- name: Create release branch
id: create-branch
if: env.create_new_branch == 'true'
run: |
git checkout -b ${{ github.event.inputs.branch_name }}
git push --set-upstream origin ${{ github.event.inputs.branch_name }}
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}

- name: Replace version in release.json
id: replace-version
run: |
jq --arg version "${{ github.event.inputs.version }}" '.mongodbOperator=$version' release.json > tmp_release.json
mv tmp_release.json release.json
git add release.json

- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
token: ${{ steps.app-token.outputs.token }}
sign-commits: true
commit-message: Release version `${{ github.event.inputs.version }}`
title: Release version `${{ github.event.inputs.version }}`
signoff: false
delete-branch: false
branch: bump-${{ github.event.inputs.version }}-version
draft: true