Skip to content

Commit

Permalink
limit branch name to 20 characters (#14977)
Browse files Browse the repository at this point in the history
  • Loading branch information
britt-mo authored Dec 13, 2024
1 parent 1561827 commit bb8f494
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
5 changes: 3 additions & 2 deletions .github/branchNameValidation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set -e

local_branch=${1}
[ -z "${1}" ] && local_branch=$(git rev-parse --abbrev-ref HEAD)

valid_branch='^[a-z][a-z0-9-]*$'

Expand All @@ -15,7 +16,7 @@ join_by() { local IFS='|'; echo "$*"; }
#creates glob match to check for reserved words used in branch names which would trigger failures
glob=$(join_by $(for i in ${reserved_words[@]}; do echo "^$i-|-$i$|-$i-|^$i$"; done;))

if [[ ! $local_branch =~ $valid_branch ]] || [[ $local_branch =~ $glob ]] || [[ ${#local_branch} -gt 64 ]]; then
if [[ ! $local_branch =~ $valid_branch ]] || [[ $local_branch =~ $glob ]] || [[ ${#local_branch} -gt 20 ]]; then
echo """
------------------------------------------------------------------------------------------------------------------------------
ERROR: Please read below
Expand All @@ -28,7 +29,7 @@ if [[ ! $local_branch =~ $valid_branch ]] || [[ $local_branch =~ $glob ]] || [[
Therefore, the branch name must be a valid service name. Branch name must be all lower case with no spaces and no underscores.
From Serverless:
A service name should only contain alphanumeric (case sensitive) and hyphens. It should start with an alphabetic character and shouldnt exceed 128 characters.
A service name should only contain alphanumeric (case sensitive) and hyphens. It should start with an alphabetic character and shouldnt exceed 20 characters.
For Github Actions support, please push your code to a new branch with a name that meets Serverless' service name requirements.
So, make a new branch with a name that begins with a letter and is made up of only letters, numbers, and hyphens... then delete this branch.
------------------------------------------------------------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ name: Pull Request
on: [pull_request]

jobs:
prchecks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure pre-commit to skip branch name validation
run: |
echo "SKIP=branch-name-validation" >> $GITHUB_ENV
assignAuthor:
runs-on: ubuntu-latest
steps:
Expand Down
9 changes: 8 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ repos:
- repo: https://github.com/zricethezav/gitleaks
rev: v8.12.0
hooks:
- id: gitleaks
- id: gitleaks
- repo: local
hooks:
- id: branch-name-validation
name: branch-name-validation
entry: .github/branchNameValidation.sh
language: script
pass_filenames: false

0 comments on commit bb8f494

Please sign in to comment.