-
Notifications
You must be signed in to change notification settings - Fork 0
184 lines (169 loc) Β· 7.65 KB
/
issuesAutomatedTasks.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
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' ||
contains(github.event.issue.labels.*.name, '[ADD_SERIE]') && 'ADD_SERIE' ||
contains(github.event.issue.labels.*.name, '[MANAGE_SERIE]') && 'MANAGE_SERIE' ||
contains(github.event.issue.labels.*.name, '[MANAGE_DLCS]') && 'MANAGE_DLCS' ||
'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
;;
ADD_SERIE)
echo "template_file=07-add-serie.yml" >> $GITHUB_OUTPUT
;;
MANAGE_SERIE)
echo "template_file=08-manage-serie.yml" >> $GITHUB_OUTPUT
;;
MANAGE_DLCS)
echo "template_file=09-manage-game-dlcs.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 ${{ toJson(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: "latest"
- name: π» Install npm packages
run: npm ci
- 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"
FILE_PATH="$FOLDER_PATH/cover.webp"
# Delete the target folder (if existing)
sudo rm -rf "$FOLDER_PATH"
# Create the target folder
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 "$FILE_PATH" -f webp resize 250 250 --fit inside
# 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: π Fix corner cases to make creation of pull request possible
run: |
# 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 .
- name: π
Create Pull Request
id: cpr
uses: peter-evans/[email protected]
with:
title: "π€ ${{ github.event.issue.title }}"
branch: "automated/${{ env.OPERATION }}-issue-${{ github.event.issue.number }}"
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