-
Notifications
You must be signed in to change notification settings - Fork 5
145 lines (140 loc) · 7.93 KB
/
parse-new-experience.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
on:
issues:
types: [labeled, edited]
name: Parse New Experience
jobs:
new_experience:
if: github.event.label.name == 'experience' || github.event.action == 'edited'
runs-on: ubuntu-latest
permissions:
issues: write
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: stefanbuck/github-issue-parser@v3
id: issue-parser
with:
template-path: .github/ISSUE_TEMPLATE/new_experience.yml
- name: Create issue.json
run: |
cat <<EOF > issue.json
${{ steps.issue-parser.outputs.jsonString }}
EOF
- name: Check experience field
id: check-experience-field
run: |
experience=$(jq -r '.experience' issue.json)
if [[ "$experience" != *.zip* ]]; then
echo "zip_file_missing=true" >> "$GITHUB_ENV"
echo "zip_file_comment=Experience field doesn't contain a link to a .zip file." >> "$GITHUB_OUTPUT"
else
echo "zip_file_missing=false" >> "$GITHUB_ENV"
fi
- name: Check length restriction for title and description
id: check-restrictions
run: |
title_length=$(jq '.title | length' issue.json)
description_length=$(jq '.description | length' issue.json)
if [ $title_length -gt 40 ]; then
echo "title_length_comment=Title is too long: $title_length characters, but only 40 are allowed." >> $GITHUB_OUTPUT
echo "restrictions_exceeded=true" >> $GITHUB_ENV
fi
if [ $description_length -gt 260 ]; then
echo "description_length_comment=Description is too long: $description_length characters, but only 260 are allowed." >> $GITHUB_OUTPUT
echo "restrictions_exceeded=true" >> $GITHUB_ENV
fi
if [ $title_length -le 40 ] && [ $description_length -le 260 ]; then
echo "restrictions_exceeded=false" >> $GITHUB_ENV
fi
- name: Check screenshot format
id: check-screenshot-format
run: |
echo "incorrect_screen_format=false" >> "$GITHUB_ENV"
screenshot_list=$(jq -r '.screenshots' issue.json | awk -F '[()]' '{print $2}')
for screenshot in $screenshot_list; do
location_url=$(curl -sI "$screenshot" | grep -i location | awk '{print $2}')
if [[ "$location_url" == *.zip* ]]; then
screenshot_format_comments+=("$screenshot is not allowed under Screenshots field because it's a .zip file. . Upload it to the Experience field instead.")
echo "incorrect_screen_format=true" >> "$GITHUB_ENV"
elif [[ "$location_url" != *.png* ]]; then
screenshot_format_comments+=("$screenshot has incorrect screenshot format. Please use .png instead.")
echo "incorrect_screen_format=true" >> "$GITHUB_ENV"
fi
done
screenshot_format_comment=$(IFS=$'\n'; echo "${screenshot_format_comments[*]}")
{
echo 'screenshot_format_comment<<EOF'
echo "$screenshot_format_comment"
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Comment and add label to issue
if: ${{ env.zip_file_missing == 'true' || env.restrictions_exceeded == 'true' || env.incorrect_screen_format == 'true' }}
run: gh issue edit "$NUMBER" --add-label "$LABELS" && gh issue comment "$NUMBER" --body "$BODY"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ github.event.issue.number }}
LABELS: changes_requested
BODY: "I've noticed a problem with your submission. Please fix it by editing your issue:\n\n
${{ steps.check-experience-field.outputs.zip_file_comment }}\n
${{ steps.check-restrictions.outputs.title_length_comment }}\n
${{ steps.check-restrictions.outputs.description_length_comment }}\n
${{ steps.check-screenshot-format.outputs.screenshot_format_comment }}"
- name: Remove label from issue if restrictions are not exceeded
if: ${{ env.zip_file_missing == 'false' && env.restrictions_exceeded == 'false' && env.incorrect_screen_format == 'false' }}
run: gh issue edit "$NUMBER" --remove-label "$LABELS"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ github.event.issue.number }}
LABELS: changes_requested
- name: Create experience name and id
if: ${{ env.zip_file_missing == 'false' && env.restrictions_exceeded == 'false' && env.incorrect_screen_format == 'false' }}
run: |
echo "experience_name=$(echo '${{ steps.issue-parser.outputs.issueparser_title }}' | sed -e 's/[^[:alnum:]]/_/g' | tr -s '_' | tr A-Z a-z)" >> "$GITHUB_ENV"
echo "id=$(uuidgen)" >> "$GITHUB_ENV"
- name: Add author, name and id to issue.json
if: ${{ env.zip_file_missing == 'false' && env.restrictions_exceeded == 'false' && env.incorrect_screen_format == 'false' }}
run: |
jq '. + {"author": "${{ github.event.issue.user.login }}", "name": "${{ env.experience_name }}", "id": "${{ env.id }}"}' issue.json > tmp && mv tmp issue.json
- name: Build manifest
id: manifest-builder
if: ${{ env.zip_file_missing == 'false' && env.restrictions_exceeded == 'false' && env.incorrect_screen_format == 'false' }}
run: |
node tools/prepare-experience.js
rm issue.json
sudo apt update
sudo apt install snapd
sudo snap install pngquant
pngquant --force --ext=.png experiences/${{ env.experience_name }}/screenshots/*.png
file_size=$(stat -c %s "experiences/${{ env.experience_name }}/${{ env.experience_name }}.zip")
jq --arg file_size $file_size '.fileSize = ($file_size|tonumber)' "experiences/${{ env.experience_name }}/manifest.json" > temp.json && mv temp.json "experiences/${{ env.experience_name }}/manifest.json"
rm -f temp.json
jq --arg file_size $file_size '.fileSize = ($file_size|tonumber)' "experiences/${{ env.experience_name }}/test-manifest.json" > temp.json && mv temp.json "experiences/${{ env.experience_name }}/test-manifest.json"
rm -f temp.json
echo "test-manifest=anytype://main/import/?type=experience&source=https%3A%2F%2Fgithub.com%2Fanyproto%2Fgallery%2Fraw%2F${{ env.experience_name }}%2Fexperiences%2F${{ env.experience_name }}%2Ftest-manifest.json" >> "$GITHUB_ENV"
- name: Create Pull Request
id: cpr
if: ${{ env.zip_file_missing == 'false' && env.restrictions_exceeded == 'false' && env.incorrect_screen_format == 'false' }}
uses: peter-evans/create-pull-request@v5
with:
commit-message: "Add preview for ${{ steps.issue-parser.outputs.issueparser_title }}"
committer: "Any Association <[email protected]>"
branch: ${{ env.experience_name }}
delete-branch: true
title: "Add experience ${{ steps.issue-parser.outputs.issueparser_title }}"
body: "Based on issue #${{ github.event.issue.number }}"
- name: Comment on Issue
if: ${{ env.zip_file_missing == 'false' && env.restrictions_exceeded == 'false' && env.incorrect_screen_format == 'false' }}
run: gh issue comment "$NUMBER" --body "$BODY"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ github.event.issue.number }}
BODY: >
Thanks for your contribution! :tada:
I have created a pull request #${{ steps.cpr.outputs.pull-request-number }} based on data you provided.
If everything worked correctly, you can test the Experience:
[${{ env.test-manifest }}](${{ env.test-manifest }})
The Experience will be added to the Gallery after someone from the Any team reviews it.