Skip to content

Commit

Permalink
build: output new release version in the built files
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Oct 16, 2023
1 parent 96fe2b7 commit 8645387
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 29 deletions.
39 changes: 21 additions & 18 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ outputs:
description: 'GitHub Token'
value: ${{ steps.credentials.outputs.token }}

image:
description: 'Docker image to use'
value: ${{ steps.setup.outputs.image }}

runs:
using: composite
steps:
Expand All @@ -33,43 +37,42 @@ runs:
fetch-depth: 0
token: ${{ steps.credentials.outputs.token }}

- uses: ./.github/actions/setup
id: setup
with:
composer-flags: --no-dev

- name: 'Cache php-scoper'
uses: actions/cache@v3
id: php-scoper-cache
with:
path: .cache/php-scoper
key: php-scoper-${{ inputs.php-scoper-version }}
restore-keys: php-scoper-

- name: 'Install php-scoper'
if: steps.php-scoper-cache.outputs.cache-hit != 'true'
shell: bash
# language=sh
run: |
mkdir -p .cache/php-scoper
mkdir -p .cache/build
composer require --no-interaction --no-progress --no-suggest --no-scripts --no-plugins \
--working-dir=.cache/php-scoper \
"humbug/php-scoper:${{ inputs.php-scoper-version }}"
- uses: ./.github/actions/setup
with:
composer-flags: --no-dev
docker run \
--volume $PWD/.cache/php-scoper:/app \
${{ steps.setup.outputs.image }} \
composer require \
--no-interaction \
--no-plugins \
--no-progress \
--no-scripts \
"humbug/php-scoper:${{ inputs.php-scoper-version }}"
# The actual compilation is done in pdk.config.js
- name: 'Cache compiled php'
uses: actions/cache@v3
id: compiled-php-cache
with:
path: .cache/build
key: compiled-php-${{ hashFiles('**/composer.lock', 'src/**/*', 'config/**/*', '*.php') }}

- name: 'Compile php'
if: steps.compiled-php-cache.outputs.cache-hit != 'true'
shell: bash
# language=sh
run: |
php -d memory_limit=-1 ./.cache/php-scoper/vendor/bin/php-scoper add-prefix --output-dir=.cache/build --force --no-ansi --no-interaction
composer dump-autoload --working-dir .cache/build --classmap-authoritative
key: compiled-php-${{ hashFiles('**/composer.json', '**/composer.lock', 'src/**/*', 'config/**/*', '*.php') }}

- name: 'Build frontend'
shell: bash
Expand Down
8 changes: 7 additions & 1 deletion .github/actions/release/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ inputs:
description: 'Version to release'
required: true

image:
description: 'Docker image to use'
required: true

runs:
using: composite
steps:
- name: 'Create release packages'
shell: bash
#language=sh
run: |
yarn pdk-builder release --version ${{ inputs.version }} -vvv
yarn pdk-builder release \
--root-command="docker run --rm -v $PWD:/app -w /app ${{ inputs.image }}" \
--version ${{ inputs.version }} -vvv
- name: 'Upload build artifacts'
uses: actions/upload-artifact@v3
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ jobs:
id: release
with:
version: ${{ steps.version.outputs.version }}
image: ${{ steps.build.outputs.image }}
4 changes: 3 additions & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ jobs:
#language=sh
run: |
version=$(npm pkg get version | sed 's/"//g')
releaseVersion="$version-${{ github.sha }}"
commitsSinceTag=$(git log --oneline v$version.. | wc -l)
releaseVersion="$version-$commitsSinceTag"
echo "version=$releaseVersion" >> $GITHUB_OUTPUT
- uses: ./.github/actions/release
id: release
with:
version: ${{ steps.version.outputs.version }}
image: ${{ steps.build.outputs.image }}

rebase-prs:
if: github.event_name == 'push'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:

- uses: myparcelnl/actions/semantic-release@v3
id: release
env:
PDK_ROOT_COMMAND: 'docker run --rm -v $PWD:/app -w /app ${{ steps.build.outputs.image }}'
with:
token: ${{ steps.build.outputs.token }}
write-summary: true
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ version: '3.9'

services:
php:
image: ghcr.io/myparcelnl/php-xd:7.4-alpine
image: ghcr.io/myparcelnl/php-xd:7.4-cli-alpine
volumes:
- .:/app
command: ['composer', 'install']

test:
image: ghcr.io/myparcelnl/php-xd:7.4-alpine
image: ghcr.io/myparcelnl/php-xd:7.4-cli-alpine
volumes:
- .:/app
command: ['php', 'vendor/bin/pest']
49 changes: 47 additions & 2 deletions pdk.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import glob from 'fast-glob';
import {getPlatformDistPath, executePromises} from '@myparcel-pdk/app-builder';
import {getPlatformDistPath, executePromises, executeCommand} from '@myparcel-pdk/app-builder';
import path from 'path';

/**
Expand Down Expand Up @@ -42,16 +42,61 @@ export default {
{path: 'woocommerce-myparcel.php', regex: /Version:\s*(.+)/},
// TODO: Uncomment when this version is stable.
// {path: 'readme.txt', regex: /Stable tag:\s*(.+)/},
{path: 'dist/*/composer.json'},
{path: 'dist/*/package.json'},
{path: 'dist/wc-myparcel-belgium/wc-myparcel-belgium.php', regex: /Version:\s*(.+)/},
{path: 'dist/woocommerce-myparcel/woocommerce-myparcel.php', regex: /Version:\s*(.+)/},
],

composerCommand: 'docker compose run --rm -T php composer',
rootCommand: 'docker compose run --rm -T php',

translations: {
// eslint-disable-next-line no-magic-numbers
additionalSheet: 535277615,
},

hooks: {
/**
* Prefix the vendor and source php files.
*/
async beforeCopy(args) {
const { debug } = args.context;

debug('Prefixing build files...');

if (fs.existsSync('.cache/build/composer.json')) {
debug('Build files already exist, skipping prefixing.');
return;
}

if (!args.dryRun) {
await executeCommand(args.context,
'php',
[
'-d memory_limit=-1',
'.cache/php-scoper/vendor/bin/php-scoper',
'add-prefix',
'--output-dir=.cache/build',
'--force',
'--no-ansi',
'--no-interaction',
],
{ stdio: 'inherit' },
);

await executeCommand(args.context, 'composer',
[
'dump-autoload',
'--working-dir=.cache/build',
'--classmap-authoritative',
],
{ stdio: 'inherit' },
);
}

debug('Finished prefixing build files.');
},

async afterCopy(args) {
const {config, env, debug} = args.context;

Expand Down
2 changes: 1 addition & 1 deletion release.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
// TODO: Uncomment when this version is stable.
// '@myparcel/semantic-release-wordpress-readme-generator',
addExecPlugin({
prepareCmd: 'yarn pdk-builder release --version ${nextRelease.version} -vvv',
prepareCmd: `yarn pdk-builder release --root-command "${process.env.PDK_ROOT_COMMAND}" --version $\{nextRelease.version} -vvv`,
}),
addGitHubPlugin({
assets: [
Expand Down
3 changes: 2 additions & 1 deletion scoper.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
'exclude-namespaces' => [
// Exclude global namespace
'/^$/',
'WP',
'Automattic',
'Composer',
'MyParcelNL',
'WP',
],
];
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -931,8 +931,8 @@ __metadata:
linkType: hard

"@myparcel-pdk/app-builder@npm:^1.0.0-alpha.1":
version: 1.0.0-alpha.41
resolution: "@myparcel-pdk/app-builder@npm:1.0.0-alpha.41"
version: 1.0.0-alpha.42
resolution: "@myparcel-pdk/app-builder@npm:1.0.0-alpha.42"
dependencies:
"@edielemoine/google-docs-importer": ^1.1.1
"@yarnpkg/parsers": ^3.0.0-rc.48.1
Expand All @@ -946,7 +946,7 @@ __metadata:
supports-color: ^9.3.1
bin:
pdk-builder: ./bin/index.js
checksum: aee863d94afb4fbe87f5d1024eb43454a444106a92b9b7b38d5f7b01d95af4a8c2d771aeeae7a7fa9541d88f5efc1668a503d6c4775531890ebc2e2107278c87
checksum: 1c6c28654881e9cee8cc826c0669108b63bfe81ebd9f8579d878280f8a73fa8dc47caafad44b9f37133584c545f67d92243dc5e413f5bd9fd20caeeace29791e
languageName: node
linkType: hard

Expand Down

0 comments on commit 8645387

Please sign in to comment.