SILLYVENTURE-1-S2024.st #25
Workflow file for this run
This file contains 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: 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." |