-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds an orchestrator to trigger js dependencies updates
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
.github/workflows/update-wordpress-js-dependencies-orchestrator.yml
This file contains 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,68 @@ | ||
name: Update WordPress JS Dependencies | ||
on: | ||
workflow_call: | ||
inputs: | ||
WP_SCRIPT_DIST_TAG: | ||
description: The tag to use for updating the dependencies. e.g. wp-6.7 | ||
default: wp-6.7 | ||
Check failure on line 7 in .github/workflows/update-wordpress-js-dependencies-orchestrator.yml
|
||
required: true | ||
type: string | ||
PACKAGES: | ||
description: Comma separated list of packages to call the update js wordpress dependencies. | ||
required: false | ||
type: string | ||
secrets: | ||
GH_API_TOKEN: | ||
description: An GH API Token capable of triggering repository_dispatch. | ||
required: true | ||
|
||
jobs: | ||
update-dependencies: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
env: | ||
GH_API_TOKEN: ${{ secrets.DEPLOYBOT_REPO_READ_WRITE_TOKEN }} | ||
Check failure on line 24 in .github/workflows/update-wordpress-js-dependencies-orchestrator.yml
|
||
WP_SCRIPT_DIST_TAG: ${{ inputs.WP_SCRIPT_DIST_TAG }} | ||
PACKAGES: ${{ inputs.PACKAGES }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Read composer.json and specified packages and call the workflows | ||
run: | | ||
# Initialize an array for packages | ||
packages=() | ||
# Add packages from composer.json if it exists | ||
if [ -f composer.json ]; then | ||
composer_packages=$(cat composer.json | jq -r '.require | keys[]') | ||
for pkg in $composer_packages; do | ||
packages+=("$pkg") | ||
done | ||
fi | ||
# Add packages from the PACKAGES environment variable | ||
IFS=',' read -r -a env_packages <<< "$PACKAGES" | ||
for pkg in "${env_packages[@]}"; do | ||
packages+=("$pkg") | ||
done | ||
# Process all unique packages | ||
unique_packages=$(echo "${packages[@]}" | tr ' ' '\n' | sort -u) | ||
for package in "unique_packages"; do | ||
echo "Processing package: $package" | ||
curl -L \ | ||
-X POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer ${{ env.GH_API_TOKEN }}" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
https://api.github.com/repos/$package/dispatches \ | ||
-d '{"event_type":"update_wp_dependencies","client_payload":{"wp_version":"${{ env.WP_SCRIPT_DIST_TAG }}"}}' | ||
done | ||