build: add medal #3
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: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Get changed image files | |
| id: changed | |
| run: | | |
| FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -E '\.(png|jpg|jpeg|webp)$' || true) | |
| 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') | |
| url="https://raw.githubusercontent.com/${{ github.repository }}/main/$file" | |
| echo "INSERT INTO badges (name,description,image_url,is_permanent) VALUES ('$filename','$filename', '$url',true);" | |
| done | |
| } | ssh ${{ secrets.VPS_USER }}@135.181.82.75 \ | |
| "docker exec -i badges_db psql -U badges_user -d badges" |