Skip to content

Create Release Branch Workflow #8

Create Release Branch Workflow

Create Release Branch Workflow #8

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 }}
# Make sure the value of GITHUB_TOKEN will not be persisted in repo's config
persist-credentials: false
- name: Checkout repository (${{ github.event.inputs.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 }}
# Make sure the value of GITHUB_TOKEN will not be persisted in repo's config
persist-credentials: false
- 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
git commit -m "Update release.json with version ${{ github.event.inputs.version }}"
git push origin ${{ github.event.inputs.branch_name }}
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}