Created
April 7, 2026 20:05
-
-
Save yinheli/1b9307ea3d876e9f64b31e6671f06211 to your computer and use it in GitHub Desktop.
Shell script to update Docker Hub repository README via API
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
| #!/bin/sh | |
| set -e | |
| PAT="YOUR_PAT_HERE" | |
| REPO="yinheli/cpdf" | |
| README_FILE="$(dirname "$0")/note.md" | |
| # Get JWT token | |
| TOKEN=$(curl -sf -X POST "https://hub.docker.com/v2/users/login/" \ | |
| -H "Content-Type: application/json" \ | |
| -d "{\"username\":\"${REPO%%/*}\",\"password\":\"${PAT}\"}" | python3 -c "import sys,json; print(json.load(sys.stdin)['token'])") | |
| # Update README | |
| curl -sf -X PATCH "https://hub.docker.com/v2/repositories/${REPO}/" \ | |
| -H "Authorization: JWT ${TOKEN}" \ | |
| -H "Content-Type: application/json" \ | |
| --data-binary @- <<PAYLOAD | |
| {"full_description": $(python3 -c "import json,sys; print(json.dumps(open(sys.argv[1]).read()))" "$README_FILE")} | |
| PAYLOAD | |
| echo "Done. README updated for ${REPO}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment