Skip to content

Commit f022b22

Browse files
authored
Fixing GH workflow (#1472)
1 parent 67c19ad commit f022b22

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

.github/workflows/spec-validate-pr.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,34 @@ jobs:
1313
- name: Check out code
1414
uses: actions/checkout@v2
1515

16+
- name: Validate branch names
17+
id: validate
18+
run: |
19+
echo "Validating branch names..."
20+
if ! [[ "${{ github.event.pull_request.head.ref }}" =~ ^[a-zA-Z0-9._/-]+$ ]]; then
21+
echo "Invalid characters in head ref"
22+
exit 1
23+
fi
24+
if ! [[ "${{ github.event.pull_request.base.ref }}" =~ ^[a-zA-Z0-9._/-]+$ ]]; then
25+
echo "Invalid characters in base ref"
26+
exit 1
27+
fi
28+
echo "::set-output name=head_ref::${{ github.event.pull_request.head.ref }}"
29+
echo "::set-output name=base_ref::${{ github.event.pull_request.base.ref }}"
30+
1631
- name: Fetch Base and Head References
1732
run: |
18-
git fetch origin ${{ github.base_ref }}:${{ github.base_ref }}
19-
git fetch origin ${{ github.head_ref }}:${{ github.head_ref }}
33+
git fetch origin ${{ steps.validate.outputs.head_ref }}:${{ steps.validate.outputs.head_ref }}
34+
git fetch origin ${{ steps.validate.outputs.base_ref }}:${{ steps.validate.outputs.base_ref }}
2035
if: github.event_name == 'pull_request'
2136

2237
- name: Validate Changes and Commit Message
2338
run: |
2439
# Check for changes in specification files inside the resources folder
25-
changed_files=$(git diff --name-only ${{ github.base_ref }} ${{ github.head_ref }})
40+
changed_files=$(git diff --name-only ${{ steps.validate.outputs.base_ref }} ${{ steps.validate.outputs.head_ref }})
2641
2742
# Fetch the commit messages from the PR
28-
commit_messages=$(git log --pretty=oneline ${{ github.base_ref }}..${{ github.head_ref }})
43+
commit_messages=$(git log --pretty=oneline ${{ steps.validate.outputs.base_ref }}..${{ steps.validate.outputs.head_ref }})
2944
3045
# Check if any commit message contains a specific keyword or pattern (e.g., "RTC")
3146
if echo "$commit_messages" | grep -q 'RTC' && echo "$changed_files" | grep -E 'resources/schema/.*\.json$'; then
@@ -34,4 +49,4 @@ jobs:
3449
echo "Either commit message doesn't contain 'RTC' keyword or specification files haven't changed. Build failed. Please check if your changes are working in visual rule editor"
3550
exit 1
3651
fi
37-
shell: bash
52+
shell: bash

0 commit comments

Comments
 (0)