Skip to content

YAPKMS - Yet Another PKM Space #210

YAPKMS - Yet Another PKM Space

YAPKMS - Yet Another PKM Space #210

on:
issues:
types: [labeled, edited]
name: Parse New Experience
jobs:
new_experience:
if: github.event.label.name == 'experience' || github.event.label.name == 'skip_validation' ||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: Create experience name and id
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: Install Go
if: github.event.label.name != 'skip_validation'
uses: actions/setup-go@v1
with:
go-version: '~1.22.1'
- name: Download validator
if: ${{ env.zip_file_missing == 'false' && env.restrictions_exceeded == 'false' && env.incorrect_screen_format == 'false' && github.event.label.name != 'skip_validation' }}
uses: actions/checkout@v4
with:
repository: anyproto/anytype-heart
path: anytype-heart
- name: Download validator dependencies
if: ${{ env.zip_file_missing == 'false' && env.restrictions_exceeded == 'false' && env.incorrect_screen_format == 'false' && github.event.label.name != 'skip_validation' }}
run: |
cd anytype-heart
make download-tantivy
- name: Run experience validator
id: experience-validator
if: ${{ env.zip_file_missing == 'false' && env.restrictions_exceeded == 'false' && env.incorrect_screen_format == 'false' && github.event.label.name != 'skip_validation' }}
run: |
cd anytype-heart/cmd/usecasevalidator
go build .
echo "Validator is built"
set +e
validation_output=$(./usecasevalidator -path ../../../experiences/${{ env.experience_name }}/${{ env.experience_name }}.zip -creator -r -validate -list -a)
validation_result="$?"
echo "${validation_output}"
if [ ${validation_result} -eq 0 ]; then
echo "Rewriting archive with the processed one"
echo "validation_error=false" >> "$GITHUB_ENV"
mv ../../../experiences/${{ env.experience_name }}/${{ env.experience_name }}_new.zip ../../../experiences/${{ env.experience_name }}/${{ env.experience_name }}.zip
else
echo "validation_error=true" >> "$GITHUB_ENV"
rm -rf ../../../experiences/${{ env.experience_name }}/
fi
rm -rf ../../../anytype-heart/
validation_comment=$(echo "<details><summary>Expand to see validator output</summary>${validation_output}</details>")
{
echo 'validation_comment<<EOF'
echo "$validation_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' || env.validation_error == '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 }}\n
${{ steps.experience-validator.outputs.validation_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' && env.validation_error == '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 Pull Request
id: cpr
if: ${{ (env.zip_file_missing == 'false' && env.restrictions_exceeded == 'false' && env.incorrect_screen_format == 'false' && env.validation_error == 'false') || github.event.label.name == 'skip_validation' }}
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' && env.validation_error == 'false') || github.event.label.name == 'skip_validation' }}
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.