Skip to content

Commit

Permalink
Merge pull request #40 from jmetrikat/gh-9-automatic-zip-errors
Browse files Browse the repository at this point in the history
GH-9 Throw automatic error if zip is uploaded incorrectly or missing
  • Loading branch information
fuksman authored Jan 29, 2024
2 parents 1d780d4 + f11a392 commit 987f57a
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions .github/workflows/parse-new-experience.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ jobs:
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: |
Expand All @@ -45,8 +55,11 @@ jobs:
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" != *.png* ]]; then
screenshot_format_comments+=("Screenshot $screenshot has incorrect format. Please use PNG format.")
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
Expand All @@ -57,37 +70,38 @@ jobs:
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Comment and add label to issue
if: ${{ env.restrictions_exceeded == 'true' || env.incorrect_screen_format == 'true' }}
run: gh issue comment "$NUMBER" --body "$BODY" && gh issue edit "$NUMBER" --add-label "$LABELS"
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.restrictions_exceeded == 'false' && env.incorrect_screen_format == 'false' }}
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.restrictions_exceeded == 'false' && env.incorrect_screen_format == 'false' }}
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.restrictions_exceeded == 'false' && env.incorrect_screen_format == 'false' }}
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.restrictions_exceeded == 'false' && env.incorrect_screen_format == 'false' }}
if: ${{ env.zip_file_missing == 'false' && env.restrictions_exceeded == 'false' && env.incorrect_screen_format == 'false' }}
run: |
node tools/prepare-experience.js
rm issue.json
Expand All @@ -103,7 +117,7 @@ jobs:
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.restrictions_exceeded == 'false' && env.incorrect_screen_format == 'false' }}
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 }}"
Expand All @@ -113,7 +127,7 @@ jobs:
title: "Add experience ${{ steps.issue-parser.outputs.issueparser_title }}"
body: "Based on issue #${{ github.event.issue.number }}"
- name: Comment on Issue
if: ${{ env.restrictions_exceeded == 'false' && env.incorrect_screen_format == 'false' }}
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 }}
Expand Down

0 comments on commit 987f57a

Please sign in to comment.