From 87feea58d2f4457879559c1a66426299a7587e41 Mon Sep 17 00:00:00 2001 From: Luis Rosales Date: Wed, 15 Jan 2025 17:04:32 +0100 Subject: [PATCH] Adds an orchestrator to trigger js dependencies updates --- ...wordpress-js-dependencies-orchestrator.yml | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .github/workflows/update-wordpress-js-dependencies-orchestrator.yml diff --git a/.github/workflows/update-wordpress-js-dependencies-orchestrator.yml b/.github/workflows/update-wordpress-js-dependencies-orchestrator.yml new file mode 100644 index 00000000..65c8e2a0 --- /dev/null +++ b/.github/workflows/update-wordpress-js-dependencies-orchestrator.yml @@ -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 + 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 }} + 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 + \ No newline at end of file