Skip to content

Commit

Permalink
Merge pull request #5 from sidecartridge/v2.0.0
Browse files Browse the repository at this point in the history
V2.0.0
  • Loading branch information
diegoparrilla authored Nov 22, 2024
2 parents 039aead + 02c365a commit ca7441d
Show file tree
Hide file tree
Showing 18 changed files with 635 additions and 235 deletions.
26 changes: 0 additions & 26 deletions .github/workflows/build.yml

This file was deleted.

156 changes: 156 additions & 0 deletions .github/workflows/post-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
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 "${{ env.crc32_value }}" "${{ steps.parse_pr.outputs.title }}" "${{ 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: 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.'
});
74 changes: 74 additions & 0 deletions .github/workflows/process_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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: Comment on Pull Request
if: failure()
uses: actions/github-script@v6
with:
script: |
github.issues.createComment({
issue_number: ${{ github.event.pull_request.number }},
owner: context.repo.owner,
repo: context.repo.repo,
body: 'The pull request description is missing required fields or contains errors. Please ensure all fields are present and correctly formatted.'
})
- name: Stop Job on Failure
if: failure()
run: |
echo "Stopping job due to failure in parsing."
exit 1 # This will cause the job to fail and prevent further steps from running
- 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 "The Floppy Image file does not exist in the repository."
exit 1
fi
46 changes: 0 additions & 46 deletions .github/workflows/release.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.history
catalog.txt
secrets.sh
!images.log
1 change: 0 additions & 1 deletion CRACKTROS/list.txt

This file was deleted.

2 changes: 0 additions & 2 deletions DEMOS/list.txt

This file was deleted.

5 changes: 0 additions & 5 deletions HOMEBREW_GAMES/list.txt

This file was deleted.

6 changes: 0 additions & 6 deletions INTROS/list.txt

This file was deleted.

Loading

0 comments on commit ca7441d

Please sign in to comment.