Create Release Branch Workflow #14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
git commit -S -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 }} |