Skip to content

Commit

Permalink
feat: adding automatic WP JS dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
luislard committed Nov 11, 2024
1 parent d3cda33 commit 9001131
Showing 1 changed file with 128 additions and 0 deletions.
128 changes: 128 additions & 0 deletions .github/workflows/update-wordpress-js-dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
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.6
default: wp-6.6

Check failure on line 7 in .github/workflows/update-wordpress-js-dependencies.yml

View workflow job for this annotation

GitHub Actions / actionlint

input "WP_SCRIPT_DIST_TAG" of workflow_call event has the default value "wp-6.6", but it is also required. if an input is marked as required, its default value will never be used
required: true
type: string
secrets:
GITHUB_USER_EMAIL:
description: Email address for the GitHub user configuration.
required: false
GITHUB_USER_NAME:
description: Username for the GitHub user configuration.
required: false
GITHUB_USER_SSH_KEY:
description: Private SSH key associated with the GitHub user for the token passed as `GITHUB_USER_TOKEN`.
required: false
GITHUB_USER_SSH_PUBLIC_KEY:
description: Public SSH key associated with the GitHub user for the token passed as `GITHUB_USER_TOKEN`.
required: false

jobs:
update-dependencies:
runs-on: ubuntu-latest
timeout-minutes: 10
env:
PACKAGE_MANAGER: npm
GITHUB_USER_EMAIL: ${{ secrets.DEPLOYBOT_EMAIL }}

Check failure on line 30 in .github/workflows/update-wordpress-js-dependencies.yml

View workflow job for this annotation

GitHub Actions / actionlint

property "deploybot_email" is not defined in object type {actions_runner_debug: string; actions_step_debug: string; github_token: string; github_user_email: string; github_user_name: string; github_user_ssh_key: string; github_user_ssh_public_key: string}
GITHUB_USER_NAME: ${{ secrets.DEPLOYBOT_USER }}

Check failure on line 31 in .github/workflows/update-wordpress-js-dependencies.yml

View workflow job for this annotation

GitHub Actions / actionlint

property "deploybot_user" is not defined in object type {actions_runner_debug: string; actions_step_debug: string; github_token: string; github_user_email: string; github_user_name: string; github_user_ssh_key: string; github_user_ssh_public_key: string}
GITHUB_USER_SSH_KEY: ${{ secrets.DEPLOYBOT_SSH_PRIVATE_KEY }}

Check failure on line 32 in .github/workflows/update-wordpress-js-dependencies.yml

View workflow job for this annotation

GitHub Actions / actionlint

property "deploybot_ssh_private_key" is not defined in object type {actions_runner_debug: string; actions_step_debug: string; github_token: string; github_user_email: string; github_user_name: string; github_user_ssh_key: string; github_user_ssh_public_key: string}
GITHUB_USER_SSH_PUBLIC_KEY: ${{ secrets.DEPLOYBOT_SSH_PUBLIC_KEY }}

Check failure on line 33 in .github/workflows/update-wordpress-js-dependencies.yml

View workflow job for this annotation

GitHub Actions / actionlint

property "deploybot_ssh_public_key" is not defined in object type {actions_runner_debug: string; actions_step_debug: string; github_token: string; github_user_email: string; github_user_name: string; github_user_ssh_key: string; github_user_ssh_public_key: string}
WP_SCRIPT_DIST_TAG: ${{ github.event.client_payload.wp_version || inputs.WP_SCRIPT_DIST_TAG }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ssh-key: ${{ env.GITHUB_USER_SSH_KEY }}

- name: Set global variables
run: |
echo "TEMP_BRANCH_NAME=update/${{ env.WP_SCRIPT_DIST_TAG }}" >> $GITHUB_ENV
echo "CURRENT_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
- name: Set up SSH
if: ${{ env.GITHUB_USER_SSH_KEY != '' }}
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ env.GITHUB_USER_SSH_KEY }}

- name: Set up Git
run: |
git config --global user.email "${{ env.GITHUB_USER_EMAIL }}"
git config --global user.name "${{ env.GITHUB_USER_NAME }}"
git config --global advice.addIgnoredFile false
git config --global push.autoSetupRemote true
- name: Set up signing commits
if: ${{ env.GITHUB_USER_SSH_PUBLIC_KEY != '' }}
run: |
: # Create empty SSH private key file so Git does not complain.
touch "${{ runner.temp }}/signingkey"
echo "${{ env.GITHUB_USER_SSH_PUBLIC_KEY }}" > "${{ runner.temp }}/signingkey.pub"
git config --global commit.gpgsign true
git config --global gpg.format ssh
git config --global user.signingkey "${{ runner.temp }}/signingkey.pub"
- name: Checkout to temporary branch
run: |
git show-ref -q refs/remotes/origin/${{ env.TEMP_BRANCH_NAME }} && git checkout ${{ env.TEMP_BRANCH_NAME }} || git checkout -b ${{ env.TEMP_BRANCH_NAME }}
- name: Set up node cache mode
run: |
if [ "${{ env.PACKAGE_MANAGER }}" == 'npm' ] && { [ -f "${GITHUB_WORKSPACE}/package-lock.json" ] || [ -f "${GITHUB_WORKSPACE}/npm-shrinkwrap.json" ]; }; then
echo "NODE_CACHE_MODE=npm" >> $GITHUB_ENV
elif [ "${{ env.PACKAGE_MANAGER }}" == 'yarn' ] && [ -f "${GITHUB_WORKSPACE}/yarn.lock" ]; then
echo "NODE_CACHE_MODE=yarn" >> $GITHUB_ENV
else
echo "No lock files found or unknown package manager"
fi
- name: Set up node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: ${{ env.NODE_CACHE_MODE }}


- name: Install dependencies
env:
ARGS: ${{ env.NODE_CACHE_MODE == 'yarn' && '--frozen-lockfile' || env.NODE_CACHE_MODE == 'npm' && 'ci' || 'install' }}
run: ${{ format('{0} {1} --ignore-scripts', env.PACKAGE_MANAGER, env.ARGS) }}

- name: Running the update
env:
SCRIPT_START: ${{ env.PACKAGE_MANAGER == 'yarn' && 'yarn' || env.PACKAGE_MANAGER == 'npm' && 'npm run' }}
run: |
./node_modules/.bin/wp-scripts packages-update --dist-tag=${{ env.WP_SCRIPT_DIST_TAG }}
- name: Git add and commit
run: |
git add -A
git commit -m "[BOT] Add dependencies changes for #${{ github.ref }}" --no-verify || ((echo "HAS_GIT_CHANGES=no" >> $GITHUB_ENV) && (echo "No changes to commit"))
- name: Git push
if: ${{ env.HAS_GIT_CHANGES != 'no' }}
run: git push


- name: Create Pull Request
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create \
--base ${{ github.event.repository.default_branch }} \
--head ${{ env.TEMP_BRANCH_NAME }} \
--title "Align WP Dependencies to meet dist tag ${{ env.WP_SCRIPT_DIST_TAG }} - ${{ env.CURRENT_DATE }}" \
--body "This PR updates the WordPress dependencies to meet the version ${{ env.WP_SCRIPT_DIST_TAG }}." \
--label "dependencies"
- name: Delete signing key files
if: ${{ always() && env.GITHUB_USER_SSH_PUBLIC_KEY != '' }}
run: |
rm -f "${{ runner.temp }}/signingkey"
rm -f "${{ runner.temp }}/signingkey.pub"

0 comments on commit 9001131

Please sign in to comment.