-
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.
feat: adding automatic WP JS dependencies
- Loading branch information
Showing
1 changed file
with
128 additions
and
0 deletions.
There are no files selected for viewing
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,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 GitHub Actions / actionlint
|
||
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 GitHub Actions / actionlint
|
||
GITHUB_USER_NAME: ${{ secrets.DEPLOYBOT_USER }} | ||
Check failure on line 31 in .github/workflows/update-wordpress-js-dependencies.yml GitHub Actions / actionlint
|
||
GITHUB_USER_SSH_KEY: ${{ secrets.DEPLOYBOT_SSH_PRIVATE_KEY }} | ||
Check failure on line 32 in .github/workflows/update-wordpress-js-dependencies.yml GitHub Actions / actionlint
|
||
GITHUB_USER_SSH_PUBLIC_KEY: ${{ secrets.DEPLOYBOT_SSH_PUBLIC_KEY }} | ||
Check failure on line 33 in .github/workflows/update-wordpress-js-dependencies.yml GitHub Actions / actionlint
|
||
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" |