Skip to content
Draft
Changes from all commits
Commits
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
61 changes: 59 additions & 2 deletions .github/workflows/test-playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ on:
default: ''
required: false
type: string
BUILD_WORKFLOW_FILENAME:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is odd in my opinion. It seems to be used as a fallback when no TESTED_ARTIFACT_SLUG is passed (because it is optional).

But the fallback hinges on the assumption that whatever other (non-build-and-distribute) build workflow also produces an artifact. And that said artifact cannot be referenced with a predictable name (convention or workflow output)

Is there even a second build workflow where these constraints apply?

Maybe I lack the full picture, but my gut feeling would be to make this "named artifact only" and reduce the complexity.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Mollie repo the WF which calls B&D is:

Name: Create release package
Filename: release.yml

description: Workflow filename to resolve the build run ID from when triggered outside of a workflow_run event.
default: 'build-and-distribute.yml'
required: false
type: string
ARTIFACT_NAME:
description: >
Name of the artifact produced by the build workflow to download and repack as a zip for plugin installation.
Expects the artifact to contain `<name>/` inside, produces `<name>.zip` with `<name>/` at the zip root.
When provided, the workflow resolves the producing run ID from the triggering workflow_run event or
the latest successful run of BUILD_WORKFLOW_FILENAME on the current branch.
default: ''
required: false
type: string
secrets:
ENV_FILE_DATA:
description: Additional environment variables for the tests.
Expand Down Expand Up @@ -189,8 +203,7 @@ jobs:
rsync -av ./build/ . && rm -rf ./build/

- name: Install Playwright dependencies
run: |
npx playwright install ${{ inputs.PLAYWRIGHT_BROWSER_ARGS }}
run: npx playwright install ${{ inputs.PLAYWRIGHT_BROWSER_ARGS }}

- name: Create environment file
env:
Expand Down Expand Up @@ -267,6 +280,50 @@ jobs:
npx wp-env run tests-cli wp config set WP_HOME "$NGROK_URL"
sed -i "s|WP_BASE_URL=.*|WP_BASE_URL=$NGROK_URL|" .env.ci

- name: Resolve artifact run ID
id: resolve-artifact-run-id
if: ${{ inputs.ARTIFACT_NAME != '' }}
env:
GH_TOKEN: ${{ github.token }}
run: |
if [ "${{ github.event_name }}" = "workflow_run" ]; then
RUN_ID="${{ github.event.workflow_run.id }}"
echo "Using workflow_run event run ID: $RUN_ID"
else
RUN_ID=$(gh run list \
--repo "${{ github.repository }}" \
--workflow="${{ inputs.BUILD_WORKFLOW_FILENAME }}" \
--branch="${{ github.ref_name }}" \
--status=success \
--limit=1 \
--json databaseId \
-q '.[0].databaseId')
if [ -z "$RUN_ID" ]; then
echo "::error::No successful ${{ inputs.BUILD_WORKFLOW_FILENAME }} run found on branch ${{ github.ref_name }}"
exit 1
fi
echo "Resolved run ID from gh run list: $RUN_ID"
fi
echo "run_id=$RUN_ID" >> "$GITHUB_OUTPUT"

- name: Download artifact
if: ${{ inputs.ARTIFACT_NAME != '' }}
env:
GH_TOKEN: ${{ github.token }}
run: |
gh run download ${{ steps.resolve-artifact-run-id.outputs.run_id }} \
-p "${{ inputs.ARTIFACT_NAME }}-*" \
-D "tests/qa/resources/files"

- name: Zip artifact
if: ${{ inputs.ARTIFACT_NAME != '' }}
working-directory: tests/qa/resources/files
run: |
cd "${{ inputs.ARTIFACT_NAME }}-"*/
zip -rq "../${{ inputs.ARTIFACT_NAME }}.zip" "${{ inputs.ARTIFACT_NAME }}"
cd ..
rm -rf "${{ inputs.ARTIFACT_NAME }}-"*/

- name: Execute custom code before executing the test script
env:
GH_TOKEN: ${{ github.token }}
Expand Down
Loading