diff --git a/.github/workflows/build-and-push-assets.yml b/.github/workflows/build-and-push-assets.yml index f51a6009..47d73452 100644 --- a/.github/workflows/build-and-push-assets.yml +++ b/.github/workflows/build-and-push-assets.yml @@ -53,11 +53,6 @@ on: default: '' required: false type: string - BUILT_BRANCH_SUFFIX: - description: Suffix to calculate the target branch for pushing assets on the `branch` event (deprecated). - type: string - default: '' - required: false BUILT_BRANCH_NAME: description: Sets the target branch for pushing assets on the `branch` event. type: string @@ -149,14 +144,8 @@ jobs: COMPILE_SCRIPT: '' TAG_NAME: '' # we'll override if the push is for tag TAG_BRANCH_NAME: '' # we'll override if the push is for tag - LOCK_FILE: '' # we'll override after checking files NO_CHANGES: '' # we'll override if no changes to commit steps: - - name: Deprecation warning - if: ${{ inputs.BUILT_BRANCH_SUFFIX != '' }} - run: | - echo '::warning::The BUILT_BRANCH_SUFFIX input is deprecated and will be removed soon. Please update your workflow to use BUILT_BRANCH_NAME with ${{ github.ref_name }}-built.' - - name: Checkout uses: actions/checkout@v4 with: @@ -212,7 +201,7 @@ jobs: - name: Set branch environment variables if: ${{ github.ref_type == 'branch' }} run: | - echo "BUILT_BRANCH_NAME=${{ inputs.BUILT_BRANCH_NAME && inputs.BUILT_BRANCH_NAME || format('{0}{1}', github.ref_name, inputs.BUILT_BRANCH_SUFFIX) }}" >> $GITHUB_ENV + echo "BUILT_BRANCH_NAME=${{ inputs.BUILT_BRANCH_NAME && inputs.BUILT_BRANCH_NAME || github.ref_name }}" >> $GITHUB_ENV - name: Set tag environment variables if: ${{ github.ref_type == 'tag' }} @@ -290,7 +279,7 @@ jobs: git commit -m "[BOT] Add compiled assets for #${{ github.ref }}" --no-verify || ((echo "NO_CHANGES=yes" >> $GITHUB_ENV) && (echo "No changes to commit")) - name: Git push for branch - if: ${{ github.ref_type == 'branch' && (env.NO_CHANGES != 'yes' || inputs.BUILT_BRANCH_SUFFIX != '' || inputs.BUILT_BRANCH_NAME != '') }} + if: ${{ github.ref_type == 'branch' }} run: git push - name: Git push for tag @@ -306,7 +295,7 @@ jobs: git push origin --tags - name: Delete temporary tag branch - if: ${{ always() && (env.TAG_BRANCH_NAME != '' && env.NO_CHANGES != 'yes') }} + if: ${{ always() && env.TAG_BRANCH_NAME != '' && env.NO_CHANGES != 'yes' }} run: | git checkout --detach git branch -d ${{ env.TAG_BRANCH_NAME }} diff --git a/.github/workflows/build-plugin-archive.yml b/.github/workflows/build-plugin-archive.yml index 6416f20c..8e3eac33 100644 --- a/.github/workflows/build-plugin-archive.yml +++ b/.github/workflows/build-plugin-archive.yml @@ -35,7 +35,7 @@ on: type: string PHP_VERSION_BUILD: description: PHP version to use when executing build tools. - default: "8.0" + default: "8.2" required: false type: string ARCHIVE_NAME: @@ -87,6 +87,8 @@ jobs: name: Install production dependencies timeout-minutes: 5 runs-on: ubuntu-latest + outputs: + artifact: ${{ steps.set-artifact-name.outputs.artifact }} env: ENV_VARS: ${{ secrets.ENV_VARS }} COMPOSER_AUTH: '${{ secrets.COMPOSER_AUTH_JSON }}' @@ -131,9 +133,11 @@ jobs: !./.git !./.ddev !./.github + include-hidden-files: true + run-build-tools: name: Process build steps - timeout-minutes: 5 + timeout-minutes: 10 runs-on: ubuntu-latest needs: checkout-dependencies env: @@ -147,6 +151,13 @@ jobs: uses: actions/download-artifact@v4 with: name: ${{ needs.checkout-dependencies.outputs.artifact }} + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ inputs.PHP_VERSION_BUILD }} + tools: humbug/php-scoper, rector + - name: Check optional Composer build tools id: composer-tools run: | @@ -157,17 +168,29 @@ jobs: echo "$EXIT" exit 0 fi - jq '.extra | has("composer-asset-compiler")' < composer.json >/dev/null 2>&1 + jq '.extra | has("composer-asset-compiler")' --exit-status < composer.json >/dev/null 2>&1 local EXIT=$? echo "$EXIT" } hasTranslateConfig(){ - jq '.extra | has("wp-translation-downloader")' < composer.json >/dev/null 2>&1 + jq '.extra | has("wp-translation-downloader")' --exit-status < composer.json >/dev/null 2>&1 + local EXIT=$? + echo "$EXIT" + } + hasScoperConfig(){ + test -f scoper.inc.php + local EXIT=$? + echo "$EXIT" + } + hasRectorConfig(){ + test -f rector.php local EXIT=$? echo "$EXIT" } echo "assets-compiler=$( hasAssetConfig )" >> $GITHUB_OUTPUT echo "translation-downloader=$( hasTranslateConfig )" >> $GITHUB_OUTPUT + echo "php-scoper=$( hasScoperConfig )" >> $GITHUB_OUTPUT + echo "rector=$( hasRectorConfig )" >> $GITHUB_OUTPUT - name: Set up node cache mode run: | @@ -202,16 +225,38 @@ jobs: composer global require inpsyde/wp-translation-downloader composer wp-translation-downloader:download + - name: Run Rector + if: steps.composer-tools.outputs.rector == '0' + run: | + rector + + - name: Run PHP-Scoper + if: steps.composer-tools.outputs.php-scoper == '0' + run: | + php-scoper add-prefix --force --output-dir=build + composer --working-dir=build dump-autoload -o + sed -i "s/'__composer_autoload_files'/\'__composer_autoload_files_${{ github.sha }}'/g" "build/vendor/composer/autoload_real.php" + + - name: Move code to the `build/` directory + if: steps.composer-tools.outputs.php-scoper != '0' + run: | + shopt -s extglob dotglob + mkdir build + mv !(build) build + - name: Set artifact name id: set-artifact-name run: echo "artifact=interim-built" >> $GITHUB_OUTPUT + - name: Upload artifact uses: actions/upload-artifact@v4 with: name: ${{ steps.set-artifact-name.outputs.artifact }} path: | - . - !**/node_modules + build/ + !build/**/node_modules + include-hidden-files: true + create-plugin-archive: name: Create build archive timeout-minutes: 5 @@ -239,11 +284,9 @@ jobs: run: echo "archive-name=${ARCHIVE_NAME:-${{ github.event.repository.name }}}" >> $GITHUB_OUTPUT - name: Add commit hash to plugin header - working-directory: interim-deps run: 'sed -Ei "s/SHA: .*/SHA: ${GIT_SHA}/g" ${{ inputs.PLUGIN_MAIN_FILE }}' - name: Set plugin version header - working-directory: interim-deps run: 'sed -Ei "s/Version: .*/Version: ${PLUGIN_VERSION}/g" ${{ inputs.PLUGIN_MAIN_FILE }}' - name: Set up PHP @@ -261,7 +304,7 @@ jobs: - name: Run WP-CLI command run: | - wp dist-archive ./interim-deps ./archive.zip --plugin-dirname=${{ steps.plugin-folder-name.outputs.plugin-folder-name }} + wp dist-archive . ./archive.zip --plugin-dirname=${{ steps.plugin-folder-name.outputs.plugin-folder-name }} # GitHub Action artifacts would otherwise produce a zip within a zip - name: Unzip archive to dist/ @@ -276,3 +319,4 @@ jobs: with: name: ${{ steps.set-artifact-name.outputs.artifact }} path: ./dist/* + include-hidden-files: true diff --git a/docs/archive-creation.md b/docs/archive-creation.md index f636faa2..02341788 100644 --- a/docs/archive-creation.md +++ b/docs/archive-creation.md @@ -7,10 +7,12 @@ To achieve that, the reusable workflow: 1. Installs dependencies (including dev-dependencies) defined in `composer.json` 2. Executes `inpsyde/composer-assets-compiler` if required & configured by the package 3. Executes `inpsyde/wp-translation-downloader` if required & configured by the package -4. Re-installs dependencies without dev-dependencies -5. Sets current commit hash and plugin version in the plugin's main file -6. Runs `wp dist-archive` to create the final archive (with builtin support for a `.distignore` file) -7. Uploads it as an artifact for download or further processing +4. Executes PHP-Scoper if configured by the package +5. Executes Rector if configured by the package +6. Re-installs dependencies without dev-dependencies +7. Sets current commit hash and plugin version in the plugin's main file +8. Runs `wp dist-archive` to create the final archive (with builtin support for a `.distignore` file) +9. Uploads it as an artifact for download or further processing ## Simple usage example diff --git a/docs/build-and-push-assets.md b/docs/build-and-push-assets.md index f06784f8..73968087 100644 --- a/docs/build-and-push-assets.md +++ b/docs/build-and-push-assets.md @@ -106,7 +106,6 @@ This is not the simplest possible example, but it showcases all the recommendati | `MODE` | `''` | Mode for compiling assets (`prod` or `dev`) | | `ASSETS_TARGET_PATHS` | `'./assets'` | Space-separated list of target directory paths for compiled assets | | `ASSETS_TARGET_FILES` | `''` | Space-separated list of target file paths for compiled assets | -| `BUILT_BRANCH_SUFFIX` | `''` | :warning: deprecated - Suffix to calculate the target branch for pushing assets on the `branch` event | | `BUILT_BRANCH_NAME` | `''` | Sets the target branch for pushing assets on the `branch` event | | `RELEASE_BRANCH_NAME` | `''` | On tag events, target branch where compiled assets are pushed and the tag is moved to | | `PHP_VERSION` | `'8.0'` | PHP version with which the PHP tools are to be executed | diff --git a/package-lock.json b/package-lock.json index 18f2cac9..115430e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3360,21 +3360,13 @@ "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-9.6.0.tgz", "integrity": "sha512-gi6WQJ7cHRgZxtkQEoyHMppPjq9Kxo5Tjn2prSKDSmZrCz8TZ3jSRCeTJm+WoM+oB0WG37bRqLzaaU3q7JypGg==", "dev": true, + "optional": true, + "peer": true, "dependencies": { "@types/estree": "*", "@types/json-schema": "*" } }, - "node_modules/@types/eslint-scope": { - "version": "3.7.7", - "resolved": "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.7.tgz", - "integrity": "sha512-MzMFlSLBqNF2gcHWO0G1vP/YQyfvrxZ0bF+u7mzUdZ1/xK4A4sru+nraZz5i3iEIk1l1uyicaDVTB4QbbEkAYg==", - "dev": true, - "dependencies": { - "@types/eslint": "*", - "@types/estree": "*" - } - }, "node_modules/@types/estree": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", @@ -17514,12 +17506,11 @@ } }, "node_modules/webpack": { - "version": "5.93.0", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.93.0.tgz", - "integrity": "sha512-Y0m5oEY1LRuwly578VqluorkXbvXKh7U3rLoQCEO04M97ScRr44afGVkI0FQFsXzysk5OgFAxjZAb9rsGQVihA==", + "version": "5.94.0", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.94.0.tgz", + "integrity": "sha512-KcsGn50VT+06JH/iunZJedYGUJS5FGjow8wb9c0v5n1Om8O1g4L6LjtfxwlXIATopoQu+vOXXa7gYisWxCoPyg==", "dev": true, "dependencies": { - "@types/eslint-scope": "^3.7.3", "@types/estree": "^1.0.5", "@webassemblyjs/ast": "^1.12.1", "@webassemblyjs/wasm-edit": "^1.12.1", @@ -17528,7 +17519,7 @@ "acorn-import-attributes": "^1.9.5", "browserslist": "^4.21.10", "chrome-trace-event": "^1.0.2", - "enhanced-resolve": "^5.17.0", + "enhanced-resolve": "^5.17.1", "es-module-lexer": "^1.2.1", "eslint-scope": "5.1.1", "events": "^3.2.0",