Resources: Update work of chongqing #2251
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: Issue bot | |
| on: | |
| issues: | |
| types: [opened, edited] | |
| jobs: | |
| updateGallery: | |
| runs-on: ubuntu-latest | |
| if: contains(github.event.issue.body, 'Paste or Upload below. They are meant for BOTS ONLY!!!') | |
| outputs: | |
| sanityCheck: ${{ steps.sanity_check.outputs.message }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| token: ${{ secrets.RMG_BUILD_AND_RELEASE }} | |
| fetch-depth: 0 # Fetch all to get authors of every template. | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '24' | |
| - run: npm ci | |
| working-directory: scripts | |
| - name: Configure git | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| - name: Save issue into a file | |
| run: | | |
| gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/railmapgen/rmp-gallery/issues/${{ github.event.issue.number }} > $HOME/issue.json | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| - name: Sanity check | |
| id: sanity_check | |
| run: node --loader ts-node/esm ./sanity-check.ts | |
| working-directory: scripts | |
| - name: Setup firefox | |
| uses: browser-actions/setup-firefox@v1 | |
| with: | |
| firefox-version: latest | |
| - name: Install Noto CJK fonts | |
| run: sudo apt install -y fonts-noto-cjk | |
| - name: Make metadata and SVG | |
| run: node --loader ts-node/esm ./issuebot.ts | |
| working-directory: scripts | |
| env: | |
| ISSUE_NUMBER: ${{ github.event.issue.number }} | |
| ISSUE_TITLE: ${{ github.event.issue.title }} | |
| USER_LOGIN: ${{ github.event.issue.user.login }} | |
| USER_ID: ${{ github.event.issue.user.id }} | |
| id: bot | |
| - name: Download resvg | |
| run: | | |
| wget https://github.com/linebender/resvg/releases/download/v0.45.1/resvg-linux-x86_64.tar.gz | |
| tar -xzf resvg-linux-x86_64.tar.gz | |
| chmod +x resvg | |
| working-directory: scripts | |
| - name: Clone RMP | |
| uses: actions/checkout@v5 | |
| with: | |
| token: ${{ secrets.RMG_BUILD_AND_RELEASE }} | |
| repository: railmapgen/rmp | |
| path: rmp | |
| - name: Clone RMT | |
| uses: actions/checkout@v5 | |
| with: | |
| token: ${{ secrets.RMG_BUILD_AND_RELEASE }} | |
| repository: railmapgen/railmapgen.github.io | |
| path: rmt | |
| - name: Copy fonts | |
| run: | | |
| mkdir -p fonts | |
| cp -r ../rmp/public/fonts/* ./fonts/ | |
| cp ../rmt/public/fonts/*.ttf ./fonts/ | |
| echo "Copy system Noto CJK fonts for fallback" | |
| sudo find /usr/share/fonts -name "NotoSans*.ttf" -o -name "NotoSansCJK*.ttc" -o -name "NotoSerif*.ttf" -o -name "NotoSerifCJK*.ttc" | xargs -I {} sudo cp {} ./fonts/ || true | |
| echo "List fonts:" | |
| ./resvg --skip-system-fonts --use-fonts-dir fonts --list-fonts | |
| working-directory: scripts | |
| - name: Render SVG | |
| run: | | |
| SVG_FILE=$(ls $HOME/Downloads/RMP_*.svg | head -n 1) | |
| CITY_NAME=$(basename "$SVG_FILE" .svg | sed 's/RMP_//') | |
| ./resvg --skip-system-fonts --use-fonts-dir fonts --sans-serif-family "Noto Sans CJK SC" --background white -z 2 "$SVG_FILE" "$HOME/Downloads/${CITY_NAME}.png" | |
| cp "$HOME/Downloads/${CITY_NAME}.png" ../public/resources/thumbnails/ | |
| working-directory: scripts | |
| - name: Generate thumbnail | |
| run: node --loader ts-node/esm ./make-thumbnail.ts | |
| working-directory: scripts | |
| - name: Make logins | |
| run: | | |
| node ./loginbot.js | |
| git add ../public/resources/ | |
| git commit --amend --no-edit | |
| working-directory: scripts | |
| - name: Print diff and push | |
| run: | | |
| git --no-pager diff HEAD^ HEAD | |
| git push --set-upstream origin bot-${{ github.event.issue.number }} | |
| - name: pull-request-action | |
| uses: vsoch/pull-request-action@master | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| BRANCH_PREFIX: "bot-" | |
| PULL_REQUEST_FROM_BRANCH: bot-${{ github.event.issue.number }} | |
| PULL_REQUEST_BRANCH: "main" | |
| PULL_REQUEST_TOKEN: ${{ secrets.RMT_SVC }} | |
| PULL_REQUEST_TITLE: ${{ github.event.issue.title }} | |
| PULL_REQUEST_BODY: "Hi, I'm the rmp bot updating _${{ github.event.issue.title }}_ on behalf of @${{ github.event.issue.user.login }}.\nThis should fix #${{ github.event.issue.number }}" | |
| - name: Add label | |
| uses: actions/github-script@v4 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const labelsToAdd = ['resources']; | |
| await github.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| labels: labelsToAdd | |
| }); | |
| updateIssueIfFailed: | |
| runs-on: ubuntu-latest | |
| needs: updateGallery | |
| if: ${{ failure() && needs.updateGallery.outputs.sanityCheck != 'pass' && needs.updateGallery.outputs.sanityCheck != '' }} | |
| steps: | |
| - name: Comment if failed | |
| uses: peter-evans/create-or-update-comment@v4 | |
| with: | |
| issue-number: ${{ github.event.issue.number }} | |
| body: | | |
| Thank you for your contribution. However, upon review, your work did not pass the sanity check due to the following reason: | |
| - ${{ needs.updateGallery.outputs.sanityCheck }} | |
| This issue will be closed, and no further actions will be taken. Please revise your work accordingly and resubmit it as a new issue. | |
| - name: Add labels | |
| uses: actions/github-script@v4 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const labelsToAdd = ['resources', 'need fixing']; | |
| await github.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| labels: labelsToAdd | |
| }); | |
| - name: Close issue | |
| uses: actions/github-script@v4 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| await github.issues.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| state: 'closed', | |
| state_reason: 'not_planned' | |
| }); |