Skip to content

[UPDATE_GAME] Contra Operation Galuga #56

[UPDATE_GAME] Contra Operation Galuga

[UPDATE_GAME] Contra Operation Galuga #56

name: Issue Templates automated Tasks
on:
issues:
types: [opened, edited]
jobs:
check_issue:
runs-on: ubuntu-latest
outputs:
issue_type: ${{ steps.detect_issue_type.outputs.issue_type }}
template_file: ${{ steps.set_template_file.outputs.template_file }}
steps:
- name: πŸ›ŽοΈ Checkout
uses: actions/checkout@v4
- id: detect_issue_type
name: πŸ” Scan issue type
env:
ISSUE_TYPE: ${{
contains(github.event.issue.labels.*.name, '[ADD_GAME]') && 'ADD_GAME' ||
contains(github.event.issue.labels.*.name, '[UPDATE_GAME]') && 'UPDATE_GAME' ||
contains(github.event.issue.labels.*.name, '[DELETE_GAME]') && 'DELETE_GAME' ||
contains(github.event.issue.labels.*.name, '[ADD_BACKLOG]') && 'ADD_BACKLOG' ||
contains(github.event.issue.labels.*.name, '[DELETE_BACKLOG]') && 'DELETE_BACKLOG' ||
contains(github.event.issue.labels.*.name, '[ADD_COVER]') && 'ADD_COVER' ||
'UNKNOWN' }}
run: echo "issue_type=${{ env.ISSUE_TYPE }}" >> $GITHUB_OUTPUT
- id: set_template_file
name: πŸ‘‰ Select the correct template for this issue
run: |
case "${{ steps.detect_issue_type.outputs.issue_type }}" in
ADD_GAME)
echo "template_file=01-add-game.yml" >> $GITHUB_OUTPUT
;;
UPDATE_GAME)
echo "template_file=02-update-game.yml" >> $GITHUB_OUTPUT
;;
DELETE_GAME)
echo "template_file=03-delete-game.yml" >> $GITHUB_OUTPUT
;;
ADD_BACKLOG)
echo "template_file=04-add-backlog.yml" >> $GITHUB_OUTPUT
;;
DELETE_BACKLOG)
echo "template_file=05-delete-backlog.yml" >> $GITHUB_OUTPUT
;;
ADD_COVER)
echo "template_file=06-add-cover.yml" >> $GITHUB_OUTPUT
;;
esac
process_issue:
runs-on: ubuntu-latest
needs: check_issue
if: ${{ needs.check_issue.outputs.issue_type != 'UNKNOWN' }}
outputs:
issue_json: ${{ steps.processed.outputs.json }}
issue_type: ${{ needs.check_issue.outputs.issue_type }}
env:
ISSUE_TYPE: ${{ needs.check_issue.outputs.issue_type }}
TEMPLATE_FILE: ${{ needs.check_issue.outputs.template_file }}
steps:
- name: πŸ›ŽοΈ Checkout
uses: actions/checkout@v4
- id: parse-issue
name: πŸ“ IssueOps Form Parser
uses: issue-ops/[email protected]
with:
issue-form-template: ${{ env.TEMPLATE_FILE }}
body: ${{ github.event.issue.body }}
- name: πŸ’Ύ Save result into a json file
run: |
echo '${{ steps.parse-issue.outputs.json }}' | jq '.' > original_answers.json
- name: πŸ“₯ Sent result to github outputs
id: processed
run: |
json_content=$(cat original_answers.json | jq -c)
echo "json=$json_content" >> $GITHUB_OUTPUT
magic_time:
needs: process_issue
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
env:
OPERATION: ${{ needs.process_issue.outputs.issue_type }}
REQUEST: ${{ needs.process_issue.outputs.issue_json }}
steps:
- name: πŸ›ŽοΈ Checkout
uses: actions/checkout@v4
- name: Setup Node.js ✨
uses: actions/[email protected]
with:
node-version: "lts/*"
- name: πŸ’» Install npm packages
run: npm install better-sqlite3 --no-save
- name: πŸ“• Add cover
if: ${{ env.OPERATION == 'ADD_COVER' }}
run: |
# Extract URL and folder path from the JSON environment variable
REQUEST_URL=$(echo $REQUEST | jq -r '.imageURL')
REQUEST_FOLDER=$(echo $REQUEST | jq -r '.folder[0]')
REQUEST_ID=$(echo $REQUEST | jq -r '.identifierValue')
# Define the folder path variable
FOLDER_PATH="./public/$REQUEST_FOLDER/$REQUEST_ID"
# Create the target folder if it doesn't exist
sudo mkdir -p "$FOLDER_PATH"
# Download the image without worrying about the extension
curl -L -o image_file "$REQUEST_URL"
# Resize the image and convert to WebP format using npx sharp-cli
sudo npx --yes sharp-cli -i ./image_file -o "$FOLDER_PATH/cover.webp" -f webp resize 250 250 --fit inside
# Change the permissions to make creation of pull request possible
# Check https://github.com/peter-evans/create-pull-request/issues/783
sudo chown -R $USER:$USER .
# Clean up the original file
sudo rm image_file
- name: βœ‚οΈ Delete cover
if: ${{ env.OPERATION == 'DELETE_GAME' }}
run: |
# Extract folder name from the JSON environment variable
REQUEST_ID=$(echo $REQUEST | jq -r '.identifierValue')
# Define the folder path variable
FOLDER_PATH="./public/covers/$REQUEST_ID"
# Clean up the original file
sudo rm -rf "$FOLDER_PATH"
- name: πŸ’Ώ Do actions in database
run: |
node automatedTasks.mjs "$OPERATION" "$REQUEST"
- name: πŸ€– Update JSON files after this change
run: npm run generate-api-json-files
- name: πŸ’… Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v7
with:
title: "πŸ€– ${{ github.event.issue.title }}"
body: |
### Automated ${{ env.OPERATION }} Change Details
The following changes were made to the JSON files based on the issue template :
```json
${{ toJson(fromJson(env.REQUEST)) }}
```
Please review the changes. Closes #${{ github.event.issue.number }}
- name: πŸ’¬ Create comment with PR Link
if: ${{ steps.cpr.outputs.pull-request-number }}
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number }}
body: |
πŸš€ A pull request has been created to address this issue:
**PR Title**: πŸ€– ${{ github.event.issue.title }}
**Link**: ${{ steps.cpr.outputs.pull-request-url }}
Please review the changes and provide your feedback.
reactions: rocket