-
Notifications
You must be signed in to change notification settings - Fork 1k
Add workflow to automate Requests library updates #6262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d412e46
Initial plan
Copilot fe82bdb
Add GitHub Actions workflow to automate Requests library updates
Copilot 9116dac
Update .github/workflows/update-requests.yml
swissspidy b25b62d
Use gh CLI instead of curl for GitHub API request
Copilot f6f7ef0
Update .github/workflows/update-requests.yml
swissspidy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| name: Update Requests library | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '0 3 * * 1' # Run every Monday at 03:00 UTC. | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: update-requests | ||
| cancel-in-progress: true | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| update-requests: | ||
| name: Check and update Requests library | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Check out repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Get the latest Requests release tag | ||
| id: latest_release | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| LATEST_TAG=$(gh api repos/WordPress/Requests/releases/latest --jq '.tag_name') | ||
| if [[ -z "${LATEST_TAG}" || "${LATEST_TAG}" == "null" ]]; then | ||
| echo "Failed to retrieve latest Requests release tag." >&2 | ||
| exit 1 | ||
| fi | ||
| echo "tag=${LATEST_TAG}" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Get the current Requests version from install script | ||
| id: current_version | ||
| run: | | ||
| CURRENT_TAG=$(grep -oP 'REQUESTS_TAG="\K[^"]+' utils/install-requests.sh) | ||
| if [[ -z "${CURRENT_TAG}" ]]; then | ||
| echo "Failed to determine current Requests version from utils/install-requests.sh." >&2 | ||
| exit 1 | ||
| fi | ||
| echo "tag=${CURRENT_TAG}" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Update install script and bundle if versions differ | ||
| if: steps.latest_release.outputs.tag != steps.current_version.outputs.tag | ||
| env: | ||
| LATEST_TAG: ${{ steps.latest_release.outputs.tag }} | ||
| CURRENT_TAG: ${{ steps.current_version.outputs.tag }} | ||
| run: | | ||
| sed -i "s/REQUESTS_TAG=\"${CURRENT_TAG}\"/REQUESTS_TAG=\"${LATEST_TAG}\"/" utils/install-requests.sh | ||
| grep -q "REQUESTS_TAG=\"${LATEST_TAG}\"" utils/install-requests.sh || { echo "Failed to update REQUESTS_TAG in install script." >&2; exit 1; } | ||
swissspidy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| bash utils/install-requests.sh | ||
|
|
||
swissspidy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - name: Validate modified files | ||
| if: steps.latest_release.outputs.tag != steps.current_version.outputs.tag | ||
| run: | | ||
| mapfile -t changed_files < <(git diff --name-only) | ||
|
|
||
| if [ "${#changed_files[@]}" -eq 0 ]; then | ||
| echo "No files changed by update; nothing to validate." | ||
| exit 0 | ||
| fi | ||
|
|
||
| allowed_regex='^(utils/install-requests\.sh|bundle/rmccue/requests(/|$))' | ||
| disallowed=() | ||
|
|
||
| for f in "${changed_files[@]}"; do | ||
| if ! [[ "$f" =~ $allowed_regex ]]; then | ||
| disallowed+=("$f") | ||
| fi | ||
| done | ||
|
|
||
| if [ "${#disallowed[@]}" -ne 0 ]; then | ||
| echo "Error: Unexpected files were modified by utils/install-requests.sh:" | ||
| printf ' %s\n' "${disallowed[@]}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "All modified files are within the allowed paths." | ||
| - name: Create pull request | ||
| if: steps.latest_release.outputs.tag != steps.current_version.outputs.tag | ||
| uses: peter-evans/create-pull-request@v7 | ||
| with: | ||
| commit-message: "Update bundled Requests library to ${{ steps.latest_release.outputs.tag }}" | ||
| branch: "update/requests-${{ steps.latest_release.outputs.tag }}" | ||
| delete-branch: true | ||
| title: "Update bundled Requests library to ${{ steps.latest_release.outputs.tag }}" | ||
| body: | | ||
| 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 }}`. | ||
|
|
||
| Please review the [Requests changelog](https://github.com/WordPress/Requests/releases/tag/${{ steps.latest_release.outputs.tag }}) before merging. | ||
| labels: "Requests" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.