PoC - Create Linked Branch Test #5
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: PoC - Create Linked Branch Test | |
| on: | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| issues: write | |
| jobs: | |
| create-branch: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 🧾 Set Test Variables | |
| id: vars | |
| run: | | |
| REPO="malikparvez/github_actions" # your repo | |
| BASE_BRANCH="main" | |
| ISSUE_ID="1" | |
| SHORT_SLUG="poc-branch-test" | |
| BRANCH_NAME="puppet-cds/${ISSUE_ID}/${SHORT_SLUG}" | |
| echo "repo=${REPO}" >> $GITHUB_OUTPUT | |
| echo "base_branch=${BASE_BRANCH}" >> $GITHUB_OUTPUT | |
| echo "issue_id=${ISSUE_ID}" >> $GITHUB_OUTPUT | |
| echo "short_slug=${SHORT_SLUG}" >> $GITHUB_OUTPUT | |
| echo "branch_name=${BRANCH_NAME}" >> $GITHUB_OUTPUT | |
| - name: 🔄 Checkout Base Branch | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ steps.vars.outputs.repo }} | |
| ref: ${{ steps.vars.outputs.base_branch }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: 🌿 Create New Branch | |
| run: | | |
| git checkout -b "${{ steps.vars.outputs.branch_name }}" | |
| echo "PoC commit for issue #${{ steps.vars.outputs.issue_id }}" > link.txt | |
| git add link.txt | |
| git commit -m "linking issue #${{ steps.vars.outputs.issue_id }}" | |
| git push origin "${{ steps.vars.outputs.branch_name }}" || echo "⚠️ Branch may already exist" | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: ✅ Verify Linkage | |
| run: | | |
| echo "✅ Branch '${{ steps.vars.outputs.branch_name }}' created and linked to issue #${{ steps.vars.outputs.issue_id }}." |