|
| 1 | +name: Canvas Paint Engine (8x8) |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: [opened] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + issues: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + paint: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout repo |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Parse Issue Title |
| 20 | + id: parse |
| 21 | + run: | |
| 22 | + TITLE="${{ github.event.issue.title }}" |
| 23 | + echo "Title: $TITLE" |
| 24 | +
|
| 25 | + # 8x8 VALIDATION |
| 26 | + if [[ "$TITLE" =~ ^Paint\ \[([A-H][1-8])\]\ \#([A-Fa-f0-9]{6})$ ]]; then |
| 27 | + COORD=$(echo "$TITLE" | sed -E 's/^Paint \[([A-H][1-8])\].*/\1/') |
| 28 | + COLOR=$(echo "$TITLE" | sed -E 's/.*(#([A-Fa-f0-9]{6})).*/\1/') |
| 29 | + echo "coord=$COORD" >> $GITHUB_OUTPUT |
| 30 | + echo "color=$COLOR" >> $GITHUB_OUTPUT |
| 31 | + else |
| 32 | + echo "invalid=true" >> $GITHUB_OUTPUT |
| 33 | + fi |
| 34 | +
|
| 35 | + - name: Handle Invalid Format |
| 36 | + if: steps.parse.outputs.invalid == 'true' |
| 37 | + env: |
| 38 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 39 | + run: | |
| 40 | + gh issue comment ${{ github.event.issue.number }} \ |
| 41 | + --body $'❌ Invalid format.\n\nUse exactly:\nPaint [A5] #FF5733\n\nValid coordinates: A1–H8' |
| 42 | +
|
| 43 | + gh issue edit ${{ github.event.issue.number }} --add-label "Invalid" |
| 44 | +
|
| 45 | + - name: Update SVG |
| 46 | + if: steps.parse.outputs.invalid != 'true' |
| 47 | + run: | |
| 48 | + COORD="${{ steps.parse.outputs.coord }}" |
| 49 | + COLOR="${{ steps.parse.outputs.color }}" |
| 50 | +
|
| 51 | + echo "Painting $COORD with $COLOR" |
| 52 | +
|
| 53 | + sed -i.bak "s/\(id=\"$COORD\"[^>]*fill=\)\"#[A-Fa-f0-9]\{6\}\"/\1\"$COLOR\"/" map.svg |
| 54 | + rm map.svg.bak |
| 55 | +
|
| 56 | + - name: Append History |
| 57 | + if: steps.parse.outputs.invalid != 'true' |
| 58 | + run: | |
| 59 | + echo "$(date -u +"%Y-%m-%dT%H:%M:%SZ"),${{ github.actor }},${{ steps.parse.outputs.coord }},${{ steps.parse.outputs.color }}" >> history.log |
| 60 | +
|
| 61 | + - name: Update Cache Buster |
| 62 | + if: steps.parse.outputs.invalid != 'true' |
| 63 | + run: | |
| 64 | + TS=$(date +%s) |
| 65 | + sed -i.bak "s/map\.svg?ts=[0-9]*/map.svg?ts=$TS/" README.md |
| 66 | + rm README.md.bak |
| 67 | +
|
| 68 | + - name: Commit Changes |
| 69 | + if: steps.parse.outputs.invalid != 'true' |
| 70 | + run: | |
| 71 | + git config user.name "canvas-bot" |
| 72 | + git config user.email "actions@github.com" |
| 73 | + git add map.svg history.log README.md |
| 74 | + git commit -m "Paint ${{ steps.parse.outputs.coord }} ${{ steps.parse.outputs.color }}" || echo "No changes to commit" |
| 75 | + git push |
| 76 | +
|
| 77 | + - name: Comment Success |
| 78 | + if: steps.parse.outputs.invalid != 'true' |
| 79 | + env: |
| 80 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 81 | + run: | |
| 82 | + gh issue comment ${{ github.event.issue.number }} \ |
| 83 | + --body "🎨 Successfully painted **${{ steps.parse.outputs.coord }}** with **${{ steps.parse.outputs.color }}**." |
| 84 | +
|
| 85 | + gh issue edit ${{ github.event.issue.number }} --add-label "Completed" |
0 commit comments