mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 13:01:38 +00:00
* fix: pin 19 unpinned action(s),extract 2 unsafe expression(s) to env vars * fix: correct SHA pins for rust-toolchain and esigner-codesign * fix: correct SHA pins for rust-toolchain and esigner-codesign --------- Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com>
75 lines
3.3 KiB
YAML
Vendored
75 lines
3.3 KiB
YAML
Vendored
name: Branch Name Check
|
|
|
|
on:
|
|
pull_request:
|
|
branches:
|
|
- develop
|
|
- main
|
|
types: [opened, synchronize, edited]
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
check-branch-name:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
pull-requests: write
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Get branch names.
|
|
id: branch-names
|
|
uses: tj-actions/branch-names@5250492686b253f06fa55861556d1027b067aeb5 # v9
|
|
|
|
- name: Show Output result for source-branch and target-branch
|
|
run: |
|
|
echo "source-branch=${{ steps.branch-names.outputs.head_ref_branch }}"
|
|
echo "target-branch=${{ steps.branch-names.outputs.base_ref_branch }}"
|
|
|
|
- name: Check branch name for develop PRs
|
|
id: check-develop-branch
|
|
if: ${{ steps.branch-names.outputs.base_ref_branch == 'develop' && !github.event.pull_request.head.repo.fork }}
|
|
run: |
|
|
if ! [[ "${{ steps.branch-names.outputs.head_ref_branch }}" =~ ^(feature/.*|docs/.*|bugfix/.*|hotfix/.*|release/([a-zA-Z-]+-)?[0-9]+\.[0-9]+\.[0-9]+(rc[0-9]+)?)$ ]]; then
|
|
echo "reason=Invalid branch name for a Pull Request to be merged to `${{ steps.branch-names.outputs.base_ref_branch }}` branch. Branches must follow the GitFlow naming convention." >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Check branch name for main PRs
|
|
id: check-main-branch
|
|
if: ${{ steps.branch-names.outputs.base_ref_branch == 'main' }}
|
|
run: |
|
|
if ! [[ "${{ steps.branch-names.outputs.head_ref_branch }}" =~ ^(hotfix/.*|docs/.*|release/([a-zA-Z-]+-)?[0-9]+\.[0-9]+\.[0-9]+(rc[0-9]+)?)$ ]]; then
|
|
echo "reason=Invalid branch name for a Pull Request to be merged to `${{ steps.branch-names.outputs.base_ref_branch }}` branch. Pull requests must be from a hotfix or release branch." >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Check for existing comment
|
|
if: ${{ steps.check-develop-branch.outputs.reason || steps.check-main-branch.outputs.reason }}
|
|
id: check-comment
|
|
run: |
|
|
commentExists=$(gh pr view ${{ github.event.pull_request.number }} --json comments -q '.comments[].body' | grep -F "Invalid branch name" || echo '')
|
|
if [[ -n "$commentExists" ]]; then
|
|
echo "commentExists=true" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "commentExists=false" >> $GITHUB_OUTPUT
|
|
fi
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Comment on PR for invalid branch name
|
|
if: steps.check-comment.outputs.commentExists == 'false'
|
|
run: |
|
|
reason="${{ steps.check-develop-branch.outputs.reason }}${{ steps.check-main-branch.outputs.reason }}"
|
|
gh pr comment ${{ github.event.pull_request.number }} --body "$reason Please review our [branch naming guidelines](https://docs.openbb.co/platform/developer_guide/github#branch-naming-conventions)."
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Fail if branch name is invalid
|
|
if: ${{ steps.check-develop-branch.outputs.reason || steps.check-main-branch.outputs.reason }}
|
|
run: |
|
|
echo "Invalid branch name. Please review our branch naming guidelines."
|
|
exit 1
|