Skip to content
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 static code analysis is to be executed.
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.
default: '--no-dev --no-scripts --prefer-dist --optimize-autoloader'
required: false
type: string
PHP_VERSION:
description: PHP version to use during packaging.
default: "8.0"
required: false
type: string
ARCHIVE_NAME:
description: The base name of the resulting zip archive. Falls back to the repository name.
default: ''
required: false
type: string
ARCHIVE_FULL_NAME:

Check failure on line 41 in .github/workflows/build-plugin-archive.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/build-plugin-archive.yml

Invalid workflow file

You have an error in your yaml syntax on line 41
description: The full name of the resulting zip archive. Falls back to the ARCHIVE_NAME-PLUGIN_VERSION template.
required: false
default: '',
type: string
PLUGIN_MAIN_FILE:
description: The name of the main plugin file.
required: false
default: 'index.php'
type: string
PLUGIN_DIR_NAME:
description: The name of the plugin directory inside the archive. Falls back to the archive name and 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
jobs:
create-plugin-archive:
timeout-minutes: 5
runs-on: ubuntu-latest
env:
NODE_OPTIONS: ${{ inputs.NODE_OPTIONS }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }}
NODE_CACHE_MODE: ''
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
outputs:
artifact: ${{ steps.set-artifact-name.outputs.artifact }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up plugin base name
env:
ARCHIVE_NAME: ${{ inputs.ARCHIVE_NAME }}
id: plugin-data
run: |
if [ ! -z "$ARCHIVE_NAME" ]; then
echo "archive-name=$ARCHIVE_NAME" >> $GITHUB_OUTPUT
else
echo "archive-name=${{ github.event.repository.name }}" >> $GITHUB_OUTPUT
fi
- name: Set up full archive name
env:
ARCHIVE_FULL_NAME: ${{ inputs.ARCHIVE_FULL_NAME }}
id: archive-full-name
run: |
if [ ! -z "$ARCHIVE_FULL_NAME" ]; then
echo "archive-full-name=$ARCHIVE_FULL_NAME" >> $GITHUB_OUTPUT
fi
- name: Set up plugin dir name
env:
PLUGIN_DIR_NAME: ${{ inputs.PLUGIN_DIR_NAME }}
id: plugin-dir-name
run: |
if [ ! -z "$PLUGIN_DIR_NAME" ]; then
echo "plugin-dir-name=$PLUGIN_DIR_NAME" >> $GITHUB_OUTPUT
elif [! -z "$ARCHIVE_NAME"]; then
echo "plugin-dir-name=$ARCHIVE_NAME"
else
echo "plugin-dir-name=${{ github.event.repository.name }}" >> $GITHUB_OUTPUT
- name: Set up custom environment variables
env:
ENV_VARS: ${{ secrets.ENV_VARS }}
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 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 PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.PHP_VERSION }}
tools: wp-cli
- name: Install Composer dependencies
# ⬑ The idea is to ensure we have non-production tools like Composer Asset Compiler and WordPress Translation Downloader available
uses: ramsey/composer-install@v2
with:
composer-options: --prefer-dist
- name: Check optional Composer build tools
id: composer-tools
run: |
hasDep(){
composer show -i -N -D --strict "${1}" >/dev/null 2>&1
local EXIT=$?
echo "$EXIT"
}
echo "assets-compiler=$( hasDep inpsyde/composer-assets-compiler )" >> $GITHUB_OUTPUT
echo "translation-downloader=$( hasDep inpsyde/wp-translation-downloader )" >> $GITHUB_OUTPUT
- name: Check for package.json
id: check-for-package
run: |
if [ -f package.json ]; then
echo "has_package=true" >> $GITHUB_OUTPUT
else
echo "has_package=false" >> $GITHUB_OUTPUT
fi
- name: Set up node
if: steps.check-for-package.outputs.has_package == 'true'
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.NODE_VERSION }}
registry-url: ${{ inputs.NPM_REGISTRY_DOMAIN }}
cache: ${{ env.NODE_CACHE_MODE }}
- name: Run Composer Asset Compiler
if: steps.composer-tools.outputs.assets-compiler == '0' && steps.check-for-package.outputs.has_package == 'true'
run: composer compile-assets ${{ inputs.COMPILE_ASSETS_ARGS }}
- name: Run WordPress Translation Downloader
if: steps.composer-tools.outputs.translation-downloader == '0'
run: composer wp-translation-downloader:download
- name: Install Composer dependencies without dev dependencies
# ⬑ Now we want to get rid of dev dependencies and most probably skip composer scripts
uses: ramsey/composer-install@v2
with:
composer-options: ${{ inputs.COMPOSER_ARGS }}
- name: Add commit hash to plugin header
env:
GIT_SHA: ${{ github.sha }}
run: 'sed -Ei "s/SHA: .*/SHA: ${GIT_SHA}/g" ${{ inputs.PLUGIN_MAIN_FILE }}'
- name: Set plugin version header
env:
PLUGIN_VERSION: ${{ inputs.PLUGIN_VERSION }}
run: 'sed -Ei "s/Version: .*/Version: ${PLUGIN_VERSION}/g" ${{ inputs.PLUGIN_MAIN_FILE }}'
- 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-data.outputs.archive-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: |
if [! -z ${{ steps.plugin-data.outputs.archive-full-name }}]; then
echo "artifact=${{ steps.plugin-data.outputs.archive-full-name }}" >> $GITHUB_OUTPUT
else
echo "artifact=${{ steps.plugin-data.outputs.archive-name }}-${{ inputs.PLUGIN_VERSION }}" >> $GITHUB_OUTPUT
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ steps.set-artifact-name.outputs.artifact }}
path: dist/*