Skip to content

Commit

Permalink
Merge branch 'main' into refactor/default-php-8-2
Browse files Browse the repository at this point in the history
Signed-off-by: Philipp Bammes <[email protected]>
  • Loading branch information
tyrann0us authored Sep 5, 2024
2 parents fdbb450 + db67323 commit 3735857
Show file tree
Hide file tree
Showing 13 changed files with 18,311 additions and 39 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/_lint-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Lint documentation

on:
push:
paths:
- '**.md'
pull_request:
workflow_dispatch:

jobs:
wp-scripts-lint:
uses: inpsyde/reusable-workflows/.github/workflows/wp-scripts-lint.yml@main
with:
LINT_TOOLS: '["md-docs"]'
17 changes: 3 additions & 14 deletions .github/workflows/build-and-push-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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' }}
Expand Down Expand Up @@ -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
Expand All @@ -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 }}
Expand Down
60 changes: 52 additions & 8 deletions .github/workflows/build-plugin-archive.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}'
Expand Down Expand Up @@ -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:
Expand All @@ -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: |
Expand All @@ -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: |
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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/
Expand All @@ -276,3 +319,4 @@ jobs:
with:
name: ${{ steps.set-artifact-name.outputs.artifact }}
path: ./dist/*
include-hidden-files: true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
## PhpStorm
.idea/

## npm
/node_modules/
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ groups here:
* [Create plugin archive](./docs/archive-creation.md)
* [Automatic release](./docs/automatic-release.md)
* [DDEV Playwright](./docs/ddev-playwright.md)

**Note:**

Workflow files prefixed with `_` are specific to the repository and cannot be reused.
12 changes: 7 additions & 5 deletions docs/archive-creation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ 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:
## Simple usage example

```yml
name: Create release package
Expand Down
8 changes: 4 additions & 4 deletions docs/assets-compilation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This workflow utilizes
the [Composer Asset Compiler](https://github.com/inpsyde/composer-asset-compiler) to compile assets.
For details, refer to https://github.com/inpsyde/composer-asset-compiler#pre-compilation.
For details, refer to [Pre-compilation](https://github.com/inpsyde/composer-asset-compiler#pre-compilation).

**Simplest possible example:**

Expand All @@ -16,9 +16,9 @@ jobs:
uses: inpsyde/reusable-workflows/.github/workflows/build-assets-compilation.yml@main
```
### Configuration parameters
## Configuration parameters
#### Inputs
### Inputs
| Name | Default | Description |
|-----------------------|-------------------------------|-----------------------------------------------------------------------------------|
Expand All @@ -30,7 +30,7 @@ jobs:
| `COMPOSER_ARGS` | `'--prefer-dist'` | Set of arguments passed to Composer |
| `COMPILE_ASSETS_ARGS` | `'-v --env=root'` | Set of arguments passed to Composer Asset Compiler |

#### Secrets
### Secrets

| Name | Description |
|-----------------------|------------------------------------------------------------------------------------------|
Expand Down
11 changes: 5 additions & 6 deletions docs/build-and-push-assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ is moved** to point to the commit that contains the compiled assets.
to avoid running the workflow when no asset sources are changed. However, it should not be used
for built branches and release branch strategies because the sync should happen on every push.

## Simple usage example:
## Simple usage example

```yml
name: Build and push assets
Expand Down Expand Up @@ -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.2'` | PHP version with which the PHP tools are to be executed |
Expand Down Expand Up @@ -192,8 +191,8 @@ The following table provides an overview when `COMPILE_SCRIPT_DEV` or `COMPILE_S
|--------|--------------------|-----------------------|
| `''` | push to branch | `COMPILE_SCRIPT_DEV` |
| `''` | create release/tag | `COMPILE_SCRIPT_PROD` |
| `dev` | _not evaluated_ | `COMPILE_SCRIPT_DEV` |
| `prod` | _not evaluated_ | `COMPILE_SCRIPT_PROD` |
| `dev` | *not evaluated* | `COMPILE_SCRIPT_DEV` |
| `prod` | *not evaluated* | `COMPILE_SCRIPT_PROD` |

**Example:** I want to push to a branch `production` and "production"-ready assets should be
compiled:
Expand Down Expand Up @@ -260,7 +259,7 @@ same as the two commits would have been made as a single commit including both.
> commit belongs to which "real" commit?

As a side effect of using the
recommended [concurrency settings] (https://docs.github.com/en/actions/using-jobs/using-concurrency)
recommended [concurrency settings](https://docs.github.com/en/actions/using-jobs/using-concurrency)
, the git history will be linear. The compilation commit would normally refer to the previous
commit, whatever that is. In the case of cherry-picking or another non-linear branch merging, this "
linearity" could be compromised. For this reason, the workflow adds to the commit message the commit
Expand Down Expand Up @@ -308,7 +307,7 @@ By passing a key associated with the GitHub user defined in the required `GITHUB
workflow can install these packages.

Please note that in such cases it is a good practice not to use a "personal" GitHub user, but an
_ad-hoc_ "bot" user with an _ad-hoc_ private SSH key used only for the scope.
*ad-hoc* "bot" user with an *ad-hoc* private SSH key used only for the scope.

---

Expand Down
2 changes: 1 addition & 1 deletion docs/ddev-playwright.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Use the DDEV env variables (`DDEV_ENV_VARS`) for debug flags of your project nee

Also, it is possible to change some DDEV config values, such as the PHP version (`PHP_VERSION`).

## Usage example:
## Usage example

```yml
name: Run Playwright tests via DDEV
Expand Down
2 changes: 2 additions & 0 deletions docs/php.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- markdownlint-disable MD024 -->

# Reusable workflows – PHP

## Coding standards analysis
Expand Down
2 changes: 1 addition & 1 deletion docs/wp-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
```

---
**Note**
**Note:**

Stylelint [requires quotes](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-scripts/#lint-style)
around file glob patterns.
Expand Down
Loading

0 comments on commit 3735857

Please sign in to comment.