Commit 234e323743a48c3818313c887d029233fd210a15
1 parent
3f567ae0
Use authenticated API call for github API for better rate limits
Showing
3 changed files
with
24 additions
and
10 deletions
.github/workflows/main.yml
| ... | ... | @@ -26,7 +26,7 @@ jobs: |
| 26 | 26 | steps: |
| 27 | 27 | - uses: actions/checkout@v3 |
| 28 | 28 | - name: 'Run pre-build steps' |
| 29 | - run: build-scripts/prebuild | |
| 29 | + run: build-scripts/prebuild ${{ secrets.GITHUB_TOKEN }} | |
| 30 | 30 | - name: 'Upload documentation for later build steps' |
| 31 | 31 | uses: actions/upload-artifact@v3 |
| 32 | 32 | with: | ... | ... |
build-scripts/download-external-libs
| ... | ... | @@ -30,16 +30,23 @@ src_name = 'qpdf-external-libs-src.zip' |
| 30 | 30 | dir_name = 'external-libs-dist' |
| 31 | 31 | os.makedirs(dir_name, exist_ok=True) |
| 32 | 32 | |
| 33 | -r = requests.get( | |
| 34 | - 'https://api.github.com/repos/qpdf/external-libs/releases') | |
| 35 | -releases = json.loads(r.text) | |
| 33 | +github_headers = { | |
| 34 | + 'content-type': 'application/json', | |
| 35 | +} | |
| 36 | +try: | |
| 37 | + token = sys.argv[1] | |
| 38 | + github_headers['authorization'] = f'Bearer {token}' | |
| 39 | +except IndexError: | |
| 40 | + print('WARNING: unauthenticated call to github API' | |
| 41 | + ' will be subject to more stringent rate limits.') | |
| 36 | 42 | |
| 37 | -# Help diagnose occasional failure where some releases don't have | |
| 38 | -# 'prerelease'. I've never seen this in attempts to reproduce. | |
| 39 | -print("---- github API output for external-libs releaes ----") | |
| 40 | -print(json.dumps(releases, indent=2, separators=(',', ': '))) | |
| 41 | -print("--------") | |
| 43 | +r = requests.get( | |
| 44 | + 'https://api.github.com/repos/qpdf/external-libs/releases', | |
| 45 | + headers=github_headers) | |
| 46 | +if r.status_code >= 400: | |
| 47 | + exit(f'GitHub API call returned status {r.status_code}: {r.text}') | |
| 42 | 48 | |
| 49 | +releases = json.loads(r.text) | |
| 43 | 50 | by_tag = sorted( |
| 44 | 51 | [(r['tag_name'], r) for r in releases |
| 45 | 52 | if r['prerelease'] is False], | ... | ... |
build-scripts/prebuild
| 1 | 1 | #!/bin/bash |
| 2 | 2 | set -e |
| 3 | 3 | cd $(dirname $0)/.. |
| 4 | + | |
| 5 | +token=$1 | |
| 6 | +if [ "$token" = "" ]; then | |
| 7 | + echo 1>&2 "Usage: $0 github-token" | |
| 8 | + exit 2 | |
| 9 | +fi | |
| 10 | + | |
| 4 | 11 | if ! ./generate_auto_job --check; then |
| 5 | 12 | cat 1>&2 <<EOF |
| 6 | 13 | |
| ... | ... | @@ -18,4 +25,4 @@ EOF |
| 18 | 25 | exit 2 |
| 19 | 26 | fi |
| 20 | 27 | build-scripts/build-doc |
| 21 | -build-scripts/download-external-libs | |
| 28 | +build-scripts/download-external-libs $token | ... | ... |