Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional tools for plugin archives: php-scoper, rector #134

Merged
merged 50 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
94be548
feat: declare workflow outputs from job outputs
Biont Feb 28, 2024
e100109
Update to actions/upload-artifact@v4
Biont Feb 28, 2024
5a6722b
Split into three jobs.
Biont Mar 19, 2024
fe7f453
Set up job dependencies
Biont Mar 19, 2024
852ecfd
Fix upload directory
Biont Mar 19, 2024
a6ed282
Test for build tool configs
Biont Mar 19, 2024
77b17d8
Improve artifact naming
Biont Mar 19, 2024
134d063
Allow composer plugins prior to installation
Biont Mar 19, 2024
9a55296
Allow composer plugins prior to installation
Biont Mar 19, 2024
b69e951
Allow composer plugins prior to installation
Biont Mar 19, 2024
d16d060
Set up php for wp-cli
Biont Mar 19, 2024
102504a
remove some clutter from deps artifact already
Biont Mar 19, 2024
1078279
improve artifact naming
Biont Mar 19, 2024
5c8b9fa
Move required data for final archive step
Biont Mar 19, 2024
520353b
Add missing path config for final artifact upload
Biont Mar 19, 2024
c615353
Move env vars where they belong
Biont Mar 19, 2024
741d772
Merge branch 'main' into feature/multi-step-plugin-archive
Biont Mar 19, 2024
607a5e2
Move PLUGIN_FOLDER_NAME as well
Biont Mar 20, 2024
9206bd8
Introduce php-scoper
Biont Mar 20, 2024
7ecaeba
Introduce php-scoper via shivammathur/setup-php
Biont Mar 20, 2024
2451d0e
Update .github/workflows/build-plugin-archive.yml
Biont Mar 21, 2024
8839d57
Update .github/workflows/build-plugin-archive.yml
Biont Mar 21, 2024
251fea6
Update .github/workflows/build-plugin-archive.yml
Biont Mar 21, 2024
058508e
Introduce PHP_VERSION_BUILD
Biont Mar 21, 2024
c59e12e
Remove somewhat redundant check for package.json files
Biont Mar 21, 2024
1b99b6e
Merge branch 'feature/multi-step-plugin-archive' into feature/prefixe…
Biont Mar 21, 2024
5019427
Merge upstream changes and fix required php version
Biont Mar 21, 2024
946f4e4
temporarily require main branch of php-scoper
Biont Apr 30, 2024
81bc444
Force '__composer_autoload_files' to be unique
Biont Jun 18, 2024
a78738a
Use github.sha for now
Biont Jun 18, 2024
b20f5ad
One more try
Biont Jun 18, 2024
d19fcbb
Merge branch 'refs/heads/main' into feature/prefixed-archives
Biont Jun 20, 2024
4ca3067
Fix usage of artifact name
Biont Jun 24, 2024
df4b49b
Debug a little
Biont Jun 24, 2024
717326e
Remove working_dir configs since actions/download-artifact@v4 apparen…
Biont Jun 24, 2024
67b8ac0
Fix job output
Biont Jun 24, 2024
9ee5dc5
Declare job output of final archive creation
Biont Jul 3, 2024
1791b79
Fix variable name
Biont Jul 3, 2024
2975185
Add Rector in archive creation (#135)
AlexP11223 Sep 3, 2024
5c9ca82
Update .github/workflows/build-plugin-archive.yml
Biont Sep 3, 2024
47b51bc
Update .github/workflows/build-plugin-archive.yml
Biont Sep 3, 2024
240dbc2
Update .github/workflows/build-plugin-archive.yml
Biont Sep 3, 2024
3a9d6a6
Merge branch 'main' into feature/prefixed-archives
Biont Sep 3, 2024
bbddb40
Include hidden files in upload
AlexP11223 Sep 3, 2024
4b7a858
Merge branch 'main' into feature/prefixed-archives
Biont Sep 4, 2024
f3ba405
Update .github/workflows/build-plugin-archive.yml
Biont Sep 4, 2024
a9a9db5
Update .github/workflows/build-plugin-archive.yml
Biont Sep 4, 2024
adb611a
Update .github/workflows/build-plugin-archive.yml
Biont Sep 4, 2024
3765dc4
Update .github/workflows/build-plugin-archive.yml
Biont Sep 4, 2024
095ab16
Update .github/workflows/build-plugin-archive.yml
Biont Sep 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 53 additions & 9 deletions .github/workflows/build-plugin-archive.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
tyrann0us marked this conversation as resolved.
Show resolved Hide resolved
required: false
type: string
ARCHIVE_NAME:
Expand Down 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:
Biont marked this conversation as resolved.
Show resolved Hide resolved
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"
tyrann0us marked this conversation as resolved.
Show resolved Hide resolved

- 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:
Biont marked this conversation as resolved.
Show resolved Hide resolved
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
10 changes: 6 additions & 4 deletions docs/archive-creation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down