|
| 1 | +name: Update Requests library |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 3 * * 1' # Run every Monday at 03:00 UTC. |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: update-requests |
| 10 | + cancel-in-progress: true |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + update-requests: |
| 17 | + name: Check and update Requests library |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Check out repository |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Get the latest Requests release tag |
| 24 | + id: latest_release |
| 25 | + env: |
| 26 | + GH_TOKEN: ${{ github.token }} |
| 27 | + run: | |
| 28 | + LATEST_TAG=$(gh api repos/WordPress/Requests/releases/latest --jq '.tag_name') |
| 29 | + if [[ -z "${LATEST_TAG}" || "${LATEST_TAG}" == "null" ]]; then |
| 30 | + echo "Failed to retrieve latest Requests release tag." >&2 |
| 31 | + exit 1 |
| 32 | + fi |
| 33 | + echo "tag=${LATEST_TAG}" >> "$GITHUB_OUTPUT" |
| 34 | +
|
| 35 | + - name: Get the current Requests version from install script |
| 36 | + id: current_version |
| 37 | + run: | |
| 38 | + CURRENT_TAG=$(grep -oP 'REQUESTS_TAG="\K[^"]+' utils/install-requests.sh) |
| 39 | + if [[ -z "${CURRENT_TAG}" ]]; then |
| 40 | + echo "Failed to determine current Requests version from utils/install-requests.sh." >&2 |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | + echo "tag=${CURRENT_TAG}" >> "$GITHUB_OUTPUT" |
| 44 | +
|
| 45 | + - name: Update install script and bundle if versions differ |
| 46 | + if: steps.latest_release.outputs.tag != steps.current_version.outputs.tag |
| 47 | + env: |
| 48 | + LATEST_TAG: ${{ steps.latest_release.outputs.tag }} |
| 49 | + CURRENT_TAG: ${{ steps.current_version.outputs.tag }} |
| 50 | + run: | |
| 51 | + sed -i "s/REQUESTS_TAG=\"${CURRENT_TAG}\"/REQUESTS_TAG=\"${LATEST_TAG}\"/" utils/install-requests.sh |
| 52 | + grep -q "REQUESTS_TAG=\"${LATEST_TAG}\"" utils/install-requests.sh || { echo "Failed to update REQUESTS_TAG in install script." >&2; exit 1; } |
| 53 | + bash utils/install-requests.sh |
| 54 | +
|
| 55 | + - name: Validate modified files |
| 56 | + if: steps.latest_release.outputs.tag != steps.current_version.outputs.tag |
| 57 | + run: | |
| 58 | + mapfile -t changed_files < <(git diff --name-only) |
| 59 | +
|
| 60 | + if [ "${#changed_files[@]}" -eq 0 ]; then |
| 61 | + echo "No files changed by update; nothing to validate." |
| 62 | + exit 0 |
| 63 | + fi |
| 64 | +
|
| 65 | + allowed_regex='^(utils/install-requests\.sh|bundle/rmccue/requests(/|$))' |
| 66 | + disallowed=() |
| 67 | +
|
| 68 | + for f in "${changed_files[@]}"; do |
| 69 | + if ! [[ "$f" =~ $allowed_regex ]]; then |
| 70 | + disallowed+=("$f") |
| 71 | + fi |
| 72 | + done |
| 73 | +
|
| 74 | + if [ "${#disallowed[@]}" -ne 0 ]; then |
| 75 | + echo "Error: Unexpected files were modified by utils/install-requests.sh:" |
| 76 | + printf ' %s\n' "${disallowed[@]}" |
| 77 | + exit 1 |
| 78 | + fi |
| 79 | +
|
| 80 | + echo "All modified files are within the allowed paths." |
| 81 | + - name: Create pull request |
| 82 | + if: steps.latest_release.outputs.tag != steps.current_version.outputs.tag |
| 83 | + uses: peter-evans/create-pull-request@v7 |
| 84 | + with: |
| 85 | + commit-message: "Update bundled Requests library to ${{ steps.latest_release.outputs.tag }}" |
| 86 | + branch: "update/requests-${{ steps.latest_release.outputs.tag }}" |
| 87 | + delete-branch: true |
| 88 | + title: "Update bundled Requests library to ${{ steps.latest_release.outputs.tag }}" |
| 89 | + body: | |
| 90 | + This automated PR updates the bundled [Requests](https://github.com/WordPress/Requests) library from `${{ steps.current_version.outputs.tag }}` to `${{ steps.latest_release.outputs.tag }}`. |
| 91 | +
|
| 92 | + Please review the [Requests changelog](https://github.com/WordPress/Requests/releases/tag/${{ steps.latest_release.outputs.tag }}) before merging. |
| 93 | + labels: "Requests" |
0 commit comments