add: EsLibre Badge #11
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 Badge to PostgreSQL | |
| 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 | |
| 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 ${{ vars.VPS_HOST }} >> ~/.ssh/known_hosts | |
| - name: Insert badge into PostgreSQL | |
| if: steps.changed.outputs.files != '' | |
| run: | | |
| IFS=$'\n' | |
| { | |
| for file in ${{ steps.changed.outputs.files }} | |
| do | |
| filename=$(basename "$file" | sed 's/_/ /g' | sed -E 's/\.(png|jpg|jpeg|webp)//g' ) | |
| 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 }}@${{ vars.VPS_HOST }} \ | |
| "docker exec -i badges_db psql -U badges_user -d badges" |