diff --git a/.github/workflows/test-playwright.yml b/.github/workflows/test-playwright.yml index 371d8bb4a..fa4e14417 100644 --- a/.github/workflows/test-playwright.yml +++ b/.github/workflows/test-playwright.yml @@ -87,6 +87,20 @@ on: default: '' required: false type: string + BUILD_WORKFLOW_FILENAME: + 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 `/` inside, produces `.zip` with `/` 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. @@ -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: @@ -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 }}