Skip to content

only display on screen no comment #22

only display on screen no comment

only display on screen no comment #22

Workflow file for this run

name: Post-Merge Processing
on:
push:
branches:
- main
jobs:
process_merge:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: read
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Git Safe Directory
run: |
git config --global --add safe.directory $GITHUB_WORKSPACE
- name: Set up Git user
run: |
git config user.name "GitHub Action"
git config user.email "[email protected]"
- name: Set up Python 3.x
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
pip install boto3
- name: Check if Latest Commit is a Merge Commit
id: check_merge
run: |
PARENT_COUNT=$(git show -s --format=%P HEAD | wc -w)
echo "Parent count: $PARENT_COUNT"
if [ "$PARENT_COUNT" -gt 1 ]; then
echo "is_merge=true" >> $GITHUB_OUTPUT
else
echo "is_merge=false" >> $GITHUB_OUTPUT
fi
- name: Show HEAD Commit Details
run: |
git show --no-patch --format=fuller HEAD
- name: Get Associated Pull Request
if: steps.check_merge.outputs.is_merge == 'true'
id: get_pr
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const commit_sha = '${{ github.sha }}';
const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: commit_sha,
});
if (prs.data.length > 0) {
const pr = prs.data[0];
core.setOutput('pr_number', pr.number.toString());
core.setOutput('pr_body', pr.body || '');
} else {
core.setFailed('No pull request found for this commit.');
core.setOutput('pr_number', '');
core.setOutput('pr_body', '');
}
- name: Parse Pull Request Description
if: steps.get_pr.outputs.pr_number != ''
uses: actions/github-script@v6
id: parse_pr
with:
script: |
const prBody = process.env.PR_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());
env:
PR_BODY: ${{ steps.get_pr.outputs.pr_body }}
- name: Ensure Scripts are Executable
if: steps.get_pr.outputs.pr_number != ''
run: |
chmod +x ./append_floppy ./calc_crc32 ./upload_image
- name: Calculate CRC32 of the floppy image
if: steps.get_pr.outputs.pr_number != ''
id: calculate_crc32
run: |
# Run the CRC32 calculation and capture the output
crc32_value=$(./calc_crc32 "${{ steps.parse_pr.outputs.filename }}")
# Save the CRC32 value to an environment variable for further use
echo "crc32_value=$crc32_value" >> $GITHUB_ENV
- name: Update the database
if: steps.get_pr.outputs.pr_number != ''
run: |
./append_floppy "${{ steps.parse_pr.outputs.title }}" "${{ env.crc32_value }}" "${{ steps.parse_pr.outputs.category }}"
env:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
- name: Upload the image if it does not exist
if: (steps.get_pr.outputs.pr_number != '') && (env.crc32_value == steps.parse_pr.outputs.filename)
run: |
./upload_image "${{ steps.parse_pr.outputs.filename }}" "MISC"
env:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
- name: Delete the Floppy Image and remove it from the repository
if: steps.get_pr.outputs.pr_number != ''
run: |
rm "${{ steps.parse_pr.outputs.filename }}"
git rm "${{ steps.parse_pr.outputs.filename }}"
git add images_crc32.csv
git add images.log
git commit -m "Add ${{steps.parse_pr.outputs.title}}"
git push
- name: Discord notification
if: steps.get_pr.outputs.pr_number != ''
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: "The floppy image \"${{ steps.parse_pr.outputs.title }}\" (category: ${{ steps.parse_pr.outputs.category }}) has been successfully processed and added to the database. You can download the file from: http://ataristdb.sidecartridge.com/MISC/${{ steps.parse_pr.outputs.filename }}"
- name: Notify Maintainers
if: failure() && steps.get_pr.outputs.pr_number != ''
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issueNumber = parseInt('${{ steps.get_pr.outputs.pr_number }}');
github.issues.createComment({
issue_number: issueNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'An error occurred while processing your Floppy image submission. Please check the repository logs for more details.'
});