mirror #2582
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: mirror | |
| on: | |
| schedule: | |
| - cron: '0 */12 * * *' | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| persist-credentials: false | |
| fetch-depth: 0 | |
| - name: Read api.github.com and filter response | |
| run: | | |
| set -euo pipefail | |
| cd docs/mirror | |
| TOKEN="${{ secrets.GITHUB_TOKEN }}" | |
| # Function to fetch ALL releases for a repo using pagination | |
| fetch_releases () { | |
| local repo="$1" # e.g. "mozilla/geckodriver" | |
| local outfile="$2" # e.g. "geckodriver" | |
| local page=1 | |
| local tmpfile | |
| tmpfile="$(mktemp)" | |
| # Empty the tmp file | |
| : > "$tmpfile" | |
| while true; do | |
| echo "Fetching $repo page $page..." | |
| # Get one page of releases (up to 100 per page) | |
| resp=$(curl -fsSL \ | |
| -H "Authorization: Bearer $TOKEN" \ | |
| "https://api.github.com/repos/$repo/releases?per_page=100&page=${page}") | |
| # Stop when the page is empty: [] | |
| if [ "$(echo "$resp" | jq 'length')" -eq 0 ]; then | |
| break | |
| fi | |
| # Transform each release on this page and append as separate JSON objects | |
| echo "$resp" \ | |
| | jq '.[] | {tag_name: .tag_name, assets: [.assets[] | {browser_download_url: .browser_download_url}]}' \ | |
| >> "$tmpfile" | |
| page=$((page+1)) | |
| done | |
| # Combine all objects into one JSON array | |
| jq -s '.' "$tmpfile" > "$outfile" | |
| rm "$tmpfile" | |
| } | |
| fetch_releases "mozilla/geckodriver" geckodriver | |
| fetch_releases "operasoftware/operachromiumdriver" operadriver | |
| fetch_releases "SeleniumHQ/selenium" selenium | |
| - name: Commit files | |
| id: git | |
| run: | | |
| export CHANGES=$(git status -s) | |
| if [ -n "$CHANGES" ]; then | |
| git config --local user.email "boni.garcia@uc3m.es" | |
| git config --local user.name "Boni Garcia" | |
| git add * | |
| git commit -m "Update mirror info (`date`)" -a | |
| echo "::set-output name=commit::true" | |
| fi | |
| - name: Push changes | |
| if: steps.git.outputs.commit == 'true' | |
| uses: ad-m/github-push-action@master | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| branch: ${{ github.ref }} |