add: Added medal #6
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Upload Images to PostgreSQL (Docker) | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| types: | |
| - closed | |
| jobs: | |
| upload-images: | |
| if: github.event.pull_request.merged == true | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Get added image files from PR (GitHub API) | |
| id: changed | |
| run: | | |
| FILES=$(curl -s \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
| "${{ github.event.pull_request.url }}/files" \ | |
| | jq -r '.[] | select(.status=="added") | .filename' \ | |
| | grep -Ei '\.(png|jpg|jpeg|webp)$' || true) | |
| echo "FILES FOUND:" | |
| echo "$FILES" | |
| echo "files<<EOF" >> $GITHUB_OUTPUT | |
| echo "$FILES" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Setup SSH | |
| if: steps.changed.outputs.files != '' | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.VPS_SSH_KEY }}" > ~/.ssh/id_rsa | |
| chmod 600 ~/.ssh/id_rsa | |
| ssh-keyscan -H 135.181.82.75 >> ~/.ssh/known_hosts | |
| - name: Insert images into PostgreSQL (Docker) | |
| if: steps.changed.outputs.files != '' | |
| run: | | |
| IFS=$'\n' | |
| { | |
| for file in ${{ steps.changed.outputs.files }} | |
| do | |
| filename=$(basename "$file" | sed 's/_/ /g') | |
| # escape quotes for SQL safety | |
| safe_filename=$(printf "%s" "$filename" | sed "s/'/''/g") | |
| url="https://raw.githubusercontent.com/${{ github.repository }}/main/$file" | |
| echo "INSERT INTO badges (name, description, image_url, is_permanent) VALUES ('$safe_filename', '$safe_filename', '$url', true);" | |
| done | |
| } | ssh ${{ secrets.VPS_USER }}@135.181.82.75 \ | |
| "docker exec -i badges_db psql -U badges_user -d badges" |