-
Notifications
You must be signed in to change notification settings - Fork 3
99 lines (84 loc) · 3.24 KB
/
process_pr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Process Pull Request
on:
pull_request:
types: [opened, edited, reopened]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write # Needed to push changes
steps:
- name: Checkout the code
uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: '3.10'
- name: Install dependencies
run: |
pip install boto3
- name: Parse Pull Request Description
uses: actions/github-script@v6
id: parse_pr
with:
script: |
const prBody = context.payload.pull_request.body;
const filenameMatch = prBody.match(/^Filename:\s*(.+)$/m);
const nameMatch = prBody.match(/^Name:\s*(.+)$/m);
const categoryMatch = prBody.match(/^Category:\s*(.+)$/m);
if (!filenameMatch) throw new Error('Filename not found or invalid in PR description.');
if (!nameMatch) throw new Error('Name not found or invalid in PR description.');
if (!categoryMatch) throw new Error('Category not found or invalid in PR description.');
core.setOutput('filename', filenameMatch[1].trim());
core.setOutput('title', nameMatch[1].trim());
core.setOutput('category', categoryMatch[1].trim());
- name: Validate Filename
id: validate_filename
run: |
# Validate Filename
FILENAME="${{ steps.parse_pr.outputs.filename }}"
if [[ -z "$FILENAME" ]]; then
echo "Error: Filename is empty."
exit 1
fi
INVALID_CHARS="[!@#$%^&*()+=\[\]{}|;:'\",<>/? ]"
if echo "$FILENAME" | grep -qE "$INVALID_CHARS"; then
echo "Invalid characters detected in filename: $FILENAME"
exit 1
fi
if ! echo "$FILENAME" | grep -qiE "\.st$"; then
echo "Error: Filename must end with '.st' or '.ST'."
exit 1
fi
# Validate Title
TITLE="${{ steps.parse_pr.outputs.title }}"
if [[ -z "$TITLE" ]]; then
echo "Error: Title is empty."
exit 1
fi
# Validate Category
CATEGORY="${{ steps.parse_pr.outputs.category }}"
if [[ -z "$CATEGORY" ]]; then
echo "Error: Category is empty."
exit 1
fi
- name: Stop Job on Failure
if: failure()
run: |
echo "Stopping job due to failure in parsing."
exit 1
- name: Display Parsed Data
run: |
echo "Filename: ${{ steps.parse_pr.outputs.filename }}"
echo "Title: ${{ steps.parse_pr.outputs.title }}"
echo "Category: ${{ steps.parse_pr.outputs.category }}"
- name: Check if the Floppy Image file exists in the repository
run: |
if [ ! -f "${{ steps.parse_pr.outputs.filename }}" ]; then
echo "Error: The file '${{ steps.parse_pr.outputs.filename }}' does not exist in the repository."
exit 1
fi
- name: Continue with Further Actions
if: success()
run: echo "All validations passed. Now wait for the approval of the pull request."