Update Pinned Repos #32
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: Update Pinned Repos | |
| on: | |
| schedule: | |
| - cron: "0 0 * * 0" # weekly | |
| workflow_dispatch: | |
| jobs: | |
| update-pinned: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| - name: Install jq | |
| run: sudo apt-get update && sudo apt-get install -y jq | |
| - name: Fetch pinned repos | |
| run: | | |
| curl -s -H "Authorization: bearer ${{ secrets.GH_TOKEN }}" \ | |
| -H "Content-Type: application/json" \ | |
| -X POST \ | |
| -d '{"query":"{ user(login: \"ARC345\") { pinnedItems(first: 6, types: REPOSITORY) { nodes { ... on Repository { nameWithOwner } } } } }"}' \ | |
| https://api.github.com/graphql \ | |
| | jq -r '.data.user.pinnedItems.nodes[].nameWithOwner' > pinned.txt | |
| - name: Update github_repos in repositories.yml | |
| run: | | |
| # remove old github_repos section | |
| awk '/^github_repos:/ {flag=1; next} /^$/ {flag=0} !flag {print}' _data/repositories.yml > tmp.yml | |
| # append new github_repos section | |
| echo "github_repos:" >> tmp.yml | |
| sed 's/^/ - /' pinned.txt >> tmp.yml | |
| # overwrite the original file | |
| mv tmp.yml _data/repositories.yml | |
| - name: Commit changes | |
| run: | | |
| git config user.name "github-actions" | |
| git config user.email "github-actions@github-actions.github.com" | |
| git add _data/repositories.yml | |
| git diff --cached --quiet || git commit -m "Update github_repos with pinned repos" | |
| git push |