Add more debug #2
Workflow file for this run
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
name: Create plugin archive | ||
on: | ||
workflow_call: | ||
inputs: | ||
NODE_OPTIONS: | ||
description: Space-separated list of command-line Node options. | ||
type: string | ||
default: '' | ||
required: false | ||
NODE_VERSION: | ||
description: Node version with which the assets will be compiled. | ||
default: 18 | ||
required: false | ||
type: string | ||
NPM_REGISTRY_DOMAIN: | ||
description: Domain of the private npm registry. | ||
default: https://npm.pkg.github.com/ | ||
required: false | ||
type: string | ||
PACKAGE_MANAGER: | ||
description: Package manager with which the dependencies should be installed (`npm` or `yarn`). | ||
default: 'yarn' | ||
required: false | ||
type: string | ||
COMPOSER_ARGS: | ||
description: Set of arguments passed to Composer when gathering production dependencies. | ||
default: '--no-dev --prefer-dist --optimize-autoloader' | ||
required: false | ||
type: string | ||
PHP_VERSION: | ||
description: PHP version to use when gathering production dependencies. | ||
default: "8.0" | ||
required: false | ||
type: string | ||
PHP_VERSION_BUILD: | ||
description: PHP version to use when executing build tools. | ||
default: "8.2" | ||
required: false | ||
type: string | ||
ARCHIVE_NAME: | ||
description: The name of the zip archive (falls back to the repository name). | ||
default: '' | ||
required: false | ||
type: string | ||
PLUGIN_MAIN_FILE: | ||
description: The name of the main plugin file. | ||
required: false | ||
default: 'index.php' | ||
type: string | ||
PLUGIN_FOLDER_NAME: | ||
description: The name of the plugin folder (falls back to the archive name, if set, or the repository name). | ||
required: false | ||
default: '' | ||
type: string | ||
PLUGIN_VERSION: | ||
description: The new plugin version. | ||
required: true | ||
type: string | ||
PRE_SCRIPT: | ||
description: Run custom shell code before creating the release archive. | ||
default: '' | ||
required: false | ||
type: string | ||
COMPILE_ASSETS_ARGS: | ||
description: Set of arguments passed to Composer Asset Compiler. | ||
default: '-v --env=root' | ||
required: false | ||
type: string | ||
secrets: | ||
COMPOSER_AUTH_JSON: | ||
description: Authentication for privately hosted packages and repositories as a JSON formatted object. | ||
required: false | ||
NPM_REGISTRY_TOKEN: | ||
description: Authentication for the private npm registry. | ||
required: false | ||
ENV_VARS: | ||
description: Additional environment variables as a JSON formatted object. | ||
required: false | ||
outputs: | ||
artifact: | ||
description: The name of the generated release artifact | ||
value: ${{ jobs.create-plugin-archive.outputs.artifact }} | ||
jobs: | ||
checkout-dependencies: | ||
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 }}' | ||
# Disables symlinking of local path repositories. | ||
# During development, symlinking is preferable. | ||
# In resulting builds, you will likely want to ship the actual install location and remove the source directory. | ||
COMPOSER_MIRROR_PATH_REPOS: 1 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Set up custom environment variables | ||
if: ${{ env.ENV_VARS }} | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
JSON | ||
.parse(process.env.ENV_VARS) | ||
.forEach(envVar => core.exportVariable(envVar.name, envVar.value)); | ||
- name: Set up PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ inputs.PHP_VERSION }} | ||
tools: wp-cli | ||
- name: Install Composer dependencies without dev dependencies | ||
uses: ramsey/composer-install@v3 | ||
with: | ||
composer-options: ${{ inputs.COMPOSER_ARGS }} | ||
- name: Set artifact name | ||
id: set-artifact-name | ||
run: echo "artifact=interim-deps" >> $GITHUB_OUTPUT | ||
- name: Upload artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ steps.set-artifact-name.outputs.artifact }} | ||
path: | | ||
./* | ||
!./.git | ||
!./.ddev | ||
!./.github | ||
run-build-tools: | ||
name: Process build steps | ||
timeout-minutes: 5 | ||
runs-on: ubuntu-latest | ||
needs: checkout-dependencies | ||
env: | ||
NODE_OPTIONS: ${{ inputs.NODE_OPTIONS }} | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }} | ||
NODE_CACHE_MODE: '' | ||
outputs: | ||
artifact: ${{ steps.set-artifact-name.outputs.artifact }} | ||
steps: | ||
- name: Download Artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: ${{ needs.checkout-dependencies.outputs.artifact }} | ||
- name: Setup PHP with tools | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ inputs.PHP_VERSION_BUILD }} | ||
tools: humbug/php-scoper:dev-main | ||
- name: Check optional Composer build tools | ||
id: composer-tools | ||
run: | | ||
hasAssetConfig(){ | ||
test -f assets-compiler.json | ||
local EXIT=$? | ||
if [ ! $EXIT ]; then | ||
echo "$EXIT" | ||
exit 0 | ||
fi | ||
jq '.extra | has("composer-asset-compiler")' < composer.json >/dev/null 2>&1 | ||
local EXIT=$? | ||
echo "$EXIT" | ||
} | ||
hasTranslateConfig(){ | ||
jq '.extra | has("wp-translation-downloader")' < composer.json >/dev/null 2>&1 | ||
local EXIT=$? | ||
echo "$EXIT" | ||
} | ||
hasScoperConfig(){ | ||
test -f scoper.inc.php | ||
local EXIT=$? | ||
echo "$EXIT" | ||
} | ||
echo "assets-compiler=$( hasAssetConfig )" >> $GITHUB_OUTPUT | ||
echo "translation-downloader=$( hasTranslateConfig )" >> $GITHUB_OUTPUT | ||
echo "php-scoper=$( hasScoperConfig )" >> $GITHUB_OUTPUT | ||
- name: Set up node cache mode | ||
run: | | ||
if [ "${{ inputs.PACKAGE_MANAGER }}" == 'npm' ] && { [ -f "${GITHUB_WORKSPACE}/package-lock.json" ] || [ -f "${GITHUB_WORKSPACE}/npm-shrinkwrap.json" ]; }; then | ||
echo "NODE_CACHE_MODE=npm" >> $GITHUB_ENV | ||
elif [ "${{ inputs.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 | ||
if: steps.composer-tools.outputs.assets-compiler == '0' | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ inputs.NODE_VERSION }} | ||
registry-url: ${{ inputs.NPM_REGISTRY_DOMAIN }} | ||
cache: ${{ env.NODE_CACHE_MODE }} | ||
- name: Debug GITHUB_ENV | ||
run: echo "$GITHUB_ENV" | ||
- name: Install and run Composer Asset Compiler | ||
if: steps.composer-tools.outputs.assets-compiler == '0' | ||
run: | | ||
echo "Installing Composer Asset Compiler" | ||
composer global config --no-plugins --no-interaction allow-plugins.inpsyde/composer-assets-compiler true | ||
composer global require inpsyde/composer-assets-compiler | ||
composer compile-assets ${{ inputs.COMPILE_ASSETS_ARGS }} | ||
- name: Install and run WordPress Translation Downloader | ||
if: steps.composer-tools.outputs.translation-downloader == '0' | ||
run: | | ||
echo "Installing WordPress Translation Downloader" | ||
composer global config --no-plugins --no-interaction allow-plugins.composer/installers true | ||
composer global config --no-plugins --no-interaction allow-plugins.inpsyde/wp-translation-downloader true | ||
composer global require inpsyde/wp-translation-downloader | ||
composer wp-translation-downloader:download | ||
- name: Run PHP Scoper | ||
if: steps.composer-tools.outputs.php-scoper == '0' | ||
run: | | ||
echo "Installing PHP Scoper" | ||
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: Create build directory | ||
if: steps.composer-tools.outputs.php-scoper != '0' | ||
run: | | ||
echo "Creating build directory" | ||
mkdir -p build | ||
- name: Move unchanged code to build directory | ||
if: steps.composer-tools.outputs.php-scoper != '0' | ||
run: | | ||
echo "Moving unchanged code to build directory" | ||
mv * build 2>/dev/null | ||
- 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: | | ||
build/ | ||
!build/**/node_modules | ||
create-plugin-archive: | ||
name: Create build archive | ||
timeout-minutes: 5 | ||
runs-on: ubuntu-latest | ||
needs: run-build-tools | ||
env: | ||
ARCHIVE_NAME: ${{ inputs.ARCHIVE_NAME }} | ||
PLUGIN_FOLDER_NAME: ${{ inputs.PLUGIN_FOLDER_NAME }} | ||
GIT_SHA: ${{ github.sha }} | ||
PLUGIN_VERSION: ${{ inputs.PLUGIN_VERSION }} | ||
steps: | ||
- name: Download Artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: ${{ needs.run-build-tools.outputs.artifact }} | ||
- name: Set up plugin folder name | ||
id: plugin-folder-name | ||
run: echo "plugin-folder-name=${PLUGIN_FOLDER_NAME:-${ARCHIVE_NAME:-${{ github.event.repository.name }}}}" >> $GITHUB_OUTPUT | ||
- name: Set up archive name | ||
id: plugin-data | ||
run: echo "archive-name=${ARCHIVE_NAME:-${{ github.event.repository.name }}}" >> $GITHUB_OUTPUT | ||
- name: Add commit hash to plugin header | ||
run: 'sed -Ei "s/SHA: .*/SHA: ${GIT_SHA}/g" ${{ inputs.PLUGIN_MAIN_FILE }}' | ||
- name: Set plugin version header | ||
run: 'sed -Ei "s/Version: .*/Version: ${PLUGIN_VERSION}/g" ${{ inputs.PLUGIN_MAIN_FILE }}' | ||
- name: Set up PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ inputs.PHP_VERSION_BUILD }} | ||
tools: wp-cli | ||
- name: Install dist-archive command | ||
run: wp package install wp-cli/dist-archive-command | ||
- name: Execute custom code before archive creation | ||
run: | | ||
${{ inputs.PRE_SCRIPT }} | ||
- name: Run WP-CLI command | ||
run: | | ||
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/ | ||
run: unzip archive.zip -d dist | ||
- name: Set artifact name | ||
id: set-artifact-name | ||
run: echo "artifact=${{ steps.plugin-data.outputs.archive-name }}" >> $GITHUB_OUTPUT | ||
- name: Upload artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ steps.set-artifact-name.outputs.artifact }} | ||
path: ./dist/* |