From bce805a4651092e2dd661e02aa980fcaaf33b817 Mon Sep 17 00:00:00 2001 From: madhusudhand Date: Tue, 24 Sep 2024 13:45:49 +0530 Subject: [PATCH 1/5] fix theme validation workflow --- .github/workflows/validate-theme.yml | 2 ++ theme-utils.mjs | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/validate-theme.yml b/.github/workflows/validate-theme.yml index e1262bab7c..1344d965d7 100644 --- a/.github/workflows/validate-theme.yml +++ b/.github/workflows/validate-theme.yml @@ -6,12 +6,14 @@ on: - '**/theme.json' - '**/styles/*.json' - '**/assets/fonts/*.json' + - '**/style.css' env: PR_PATHS: >- '**/theme.json' '**/styles/*.json' '**/assets/fonts/*.json' + '**/style.css' HUSKY: 0 jobs: diff --git a/theme-utils.mjs b/theme-utils.mjs index ceac229148..1ffdfbff79 100644 --- a/theme-utils.mjs +++ b/theme-utils.mjs @@ -180,7 +180,7 @@ const commands = { run: async ( args ) => { args.shift(); const options = {}; - while ( args[ 0 ].startsWith( '--' ) ) { + while ( args[ 0 ] && args[ 0 ].startsWith( '--' ) ) { const flag = args.shift().slice( 2 ); const [ key, value ] = flag.split( '=' ); const camelCaseKey = key.replace( /-([a-z])/g, ( [ , c ] ) => @@ -188,8 +188,10 @@ const commands = { ); options[ camelCaseKey ] = value ?? true; } - const themes = args[ 0 ].split( /[ ,]+/ ); - await validateThemes( themes, options ); + const themes = args[ 0 ] ? args[ 0 ].split( /[ ,]+/ ) : []; + if ( themes.length ) { + await validateThemes( themes, options ); + } }, }, help: { From e8b7c6511e7092eb6f149c92b2778123985c6333 Mon Sep 17 00:00:00 2001 From: madhusudhand Date: Tue, 24 Sep 2024 16:14:27 +0530 Subject: [PATCH 2/5] fix directory finding logic in theme check workflow --- .github/workflows/theme-check.yml | 38 +++---------------------------- 1 file changed, 3 insertions(+), 35 deletions(-) diff --git a/.github/workflows/theme-check.yml b/.github/workflows/theme-check.yml index cf7561d352..f50da4a867 100644 --- a/.github/workflows/theme-check.yml +++ b/.github/workflows/theme-check.yml @@ -41,41 +41,9 @@ jobs: wp-env run cli wp plugin install https://github.com/WordPress/theme-check/archive/refs/pull/458/head.zip --activate - name: Get changed root folders - uses: actions/github-script@v6 - with: - script: | - const { owner, repo, number } = context.issue; - let allFiles = []; - let page = 1; - - while (true) { - const { data: files } = await github.rest.pulls.listFiles({ - owner, - repo, - pull_number: number, - per_page: 100, - page: page - }); - - allFiles = allFiles.concat(files); - - if (files.length < 100) break; - page++; - } - - console.log('files', allFiles.map(file => file.filename)); - - const rootFolders = new Set(); - for (const file of allFiles) { - const parts = file.filename.split('/'); - if (parts.length > 1) { - rootFolders.add(parts[0]); - } - } - - const rootFoldersArray = Array.from(rootFolders); - core.exportVariable('THEME_FOLDERS', rootFoldersArray.join(',')); - console.log(`Changed root folders: ${rootFoldersArray.join(', ')}`); + run: | + THEME_FOLDERS=$(git diff --name-only HEAD^ | awk '!/^\./ && /\//' | awk -F/ '{print $1}' | uniq | paste -s -d, -) + echo "THEME_FOLDERS=${THEME_FOLDERS}" >> $GITHUB_ENV - name: Debug THEME_FOLDERS run: echo "THEME_FOLDERS is ${{ env.THEME_FOLDERS }}" From 49e4c14448513ada8953d8275d6623af13fad07c Mon Sep 17 00:00:00 2001 From: madhusudhand Date: Mon, 30 Sep 2024 15:16:38 +0530 Subject: [PATCH 3/5] revert theme check workflow --- .github/workflows/theme-check.yml | 38 ++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/.github/workflows/theme-check.yml b/.github/workflows/theme-check.yml index f50da4a867..cf7561d352 100644 --- a/.github/workflows/theme-check.yml +++ b/.github/workflows/theme-check.yml @@ -41,9 +41,41 @@ jobs: wp-env run cli wp plugin install https://github.com/WordPress/theme-check/archive/refs/pull/458/head.zip --activate - name: Get changed root folders - run: | - THEME_FOLDERS=$(git diff --name-only HEAD^ | awk '!/^\./ && /\//' | awk -F/ '{print $1}' | uniq | paste -s -d, -) - echo "THEME_FOLDERS=${THEME_FOLDERS}" >> $GITHUB_ENV + uses: actions/github-script@v6 + with: + script: | + const { owner, repo, number } = context.issue; + let allFiles = []; + let page = 1; + + while (true) { + const { data: files } = await github.rest.pulls.listFiles({ + owner, + repo, + pull_number: number, + per_page: 100, + page: page + }); + + allFiles = allFiles.concat(files); + + if (files.length < 100) break; + page++; + } + + console.log('files', allFiles.map(file => file.filename)); + + const rootFolders = new Set(); + for (const file of allFiles) { + const parts = file.filename.split('/'); + if (parts.length > 1) { + rootFolders.add(parts[0]); + } + } + + const rootFoldersArray = Array.from(rootFolders); + core.exportVariable('THEME_FOLDERS', rootFoldersArray.join(',')); + console.log(`Changed root folders: ${rootFoldersArray.join(', ')}`); - name: Debug THEME_FOLDERS run: echo "THEME_FOLDERS is ${{ env.THEME_FOLDERS }}" From f1a5330e80ee10057be99bd5bd137b758f21195e Mon Sep 17 00:00:00 2001 From: madhusudhand Date: Mon, 30 Sep 2024 15:17:43 +0530 Subject: [PATCH 4/5] add condition to exclude non theme directories such as .github, .husky --- .github/workflows/theme-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/theme-check.yml b/.github/workflows/theme-check.yml index cf7561d352..64731d41e9 100644 --- a/.github/workflows/theme-check.yml +++ b/.github/workflows/theme-check.yml @@ -68,7 +68,7 @@ jobs: const rootFolders = new Set(); for (const file of allFiles) { const parts = file.filename.split('/'); - if (parts.length > 1) { + if (parts.length > 1 && !parts[0].startsWith('.')) { rootFolders.add(parts[0]); } } From c13b757ff3939097e0f373af4b1de8f8f81974d4 Mon Sep 17 00:00:00 2001 From: madhusudhand Date: Mon, 30 Sep 2024 15:43:09 +0530 Subject: [PATCH 5/5] add conditions to add comment only if there are theme changes --- .github/workflows/theme-check.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/theme-check.yml b/.github/workflows/theme-check.yml index 64731d41e9..091b89cc26 100644 --- a/.github/workflows/theme-check.yml +++ b/.github/workflows/theme-check.yml @@ -81,6 +81,7 @@ jobs: run: echo "THEME_FOLDERS is ${{ env.THEME_FOLDERS }}" - name: Run Theme Check for each folder + if: env.THEME_FOLDERS != '' run: | IFS=',' read -ra FOLDERS <<< "${{ env.THEME_FOLDERS }}" for THEME_FOLDER in "${FOLDERS[@]}"; do @@ -128,6 +129,7 @@ jobs: } - name: Comment PR + if: env.THEME_FOLDERS != '' uses: actions/github-script@v6 with: github-token: ${{secrets.GITHUB_TOKEN}}