Skip to content

Commit 219479b

Browse files
author
James Amner
authored
Merge pull request #306 from boxuk/BWP-122
[BWP-122] Triggering the Test Workflows
2 parents 79743e6 + 3e83872 commit 219479b

File tree

5 files changed

+84
-12
lines changed

5 files changed

+84
-12
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Checkout WP Deps Branch
2+
description: Checkout a branch for the WP Deps update action
3+
4+
# Based on example https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#using-data-from-the-triggering-workflow
5+
6+
runs:
7+
using: composite
8+
steps:
9+
- name: 'Download artifact'
10+
uses: actions/github-script@v6
11+
with:
12+
script: |
13+
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
14+
owner: context.repo.owner,
15+
repo: context.repo.repo,
16+
run_id: context.payload.workflow_run.id,
17+
});
18+
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
19+
return artifact.name == "pr_number"
20+
})[0];
21+
let download = await github.rest.actions.downloadArtifact({
22+
owner: context.repo.owner,
23+
repo: context.repo.repo,
24+
artifact_id: matchArtifact.id,
25+
archive_format: 'zip',
26+
});
27+
const fs = require('fs');
28+
const path = require('path');
29+
const temp = '${{ runner.temp }}/artifacts';
30+
if (!fs.existsSync(temp)){
31+
fs.mkdirSync(temp);
32+
}
33+
fs.writeFileSync(path.join(temp, 'pr_number.zip'), Buffer.from(download.data));
34+
35+
- name: Parse PR Number
36+
shell: bash
37+
id: parse-pr-number
38+
run: |
39+
unzip pr_number.zip -d "${{ runner.temp }}/artifacts"
40+
echo "PR_NUMBER=$(cat ${{ runner.temp }}/artifacts/pr/pr_number)" >> $GITHUB_ENV
41+
42+
- name: Checkout
43+
uses: actions/checkout@v4
44+
with:
45+
ref: refs/pull/${{ steps.parse-pr-number.outputs.PR_NUMBER }}/merge

.github/workflows/test-php.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@ jobs:
3333
steps:
3434
- name: Checkout
3535
uses: actions/checkout@v4
36-
with:
37-
ref: ${{ github.event.pull_request.head.sha }}
38-
if: github.event_name == 'pull_request'
36+
if: github.event_name != 'workflow_run'
37+
3938
- name: Checkout
40-
uses: actions/checkout@v4
41-
with:
42-
ref: ${{ github.event.workflow_run.head_sha }}
39+
uses: ./.github/checkout-deps-auto-update
4340
if: github.event_name == 'workflow_run'
41+
4442
- name: Set up PHP
4543
uses: setup-php/setup-php@v2
4644
with:

.github/workflows/tests-js.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,20 @@ jobs:
2626
steps:
2727
- name: Checkout
2828
uses: actions/checkout@v4
29-
with:
30-
ref: ${{ github.event.pull_request.head.sha }}
31-
if: github.event_name == 'pull_request'
29+
if: github.event_name != 'workflow_run'
30+
3231
- name: Checkout
33-
uses: actions/checkout@v4
34-
with:
35-
ref: ${{ github.event.workflow_run.head_sha }}
32+
uses: ./.github/checkout-deps-auto-update
3633
if: github.event_name == 'workflow_run'
34+
3735
- name: Setup Node
3836
uses: actions/setup-node@v4
3937
with:
4038
node-version: ${{ matrix.node-version }}
4139
cache: npm
4240
- name: Setup dependencies
4341
run: npm ci
42+
4443
- name: Lint JS
4544
run: npm run lint
4645
- name: Unit Test

.github/workflows/wordpress-deps.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,18 @@ jobs:
1919
fetch-depth: 0
2020
persist-credentials: false
2121
- name: Run Update
22+
id: update
2223
uses: 'boxuk/wp-deps-auto-update@main'
2324
with:
2425
WP_VERSION: ${{ env.WORDPRESS_VERSION }}
2526
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
- name: Save PR number
28+
env:
29+
PR_NUMBER: ${{ steps.update.outputs.pull-request-number }}
30+
run: |
31+
mkdir -p ./pr
32+
echo $PR_NUMBER > ./pr/pr_number
33+
- uses: actions/upload-artifact@v4
34+
with:
35+
name: pr_number
36+
path: pr/

packages/deps-auto-update/action.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ inputs:
77
GITHUB_TOKEN:
88
description: 'GitHub Token'
99
required: true
10+
11+
outputs:
12+
pull-request-number:
13+
description: 'The pull request number'
14+
value: ${{ steps.create-pull-request.outputs.pull-request-number }}
15+
pull-request-url:
16+
description: 'The URL of the pull request.'
17+
value: ${{ steps.create-pull-request.outputs.pull-request-url }}
18+
pull-request-operation:
19+
description: 'The pull request operation performed by the action, `created`, `updated` or `closed`.'
20+
value: ${{ steps.create-pull-request.outputs.pull-request-operation }}
21+
pull-request-head-sha:
22+
description: 'The commit SHA of the pull request branch.'
23+
value: ${{ steps.create-pull-request.outputs.pull-request-head-sha }}
24+
pull-request-branch:
25+
description: 'The pull request branch name'
26+
value: ${{ steps.create-pull-request.outputs.pull-request-branch }}
27+
1028
runs:
1129
using: composite
1230
steps:
@@ -33,6 +51,7 @@ runs:
3351

3452
# Create a PR
3553
- name: Create Pull Request
54+
id: create-pull-request
3655
uses: peter-evans/create-pull-request@v7
3756
with:
3857
title: "[DEPS] Update WP Packages for WP ${{ inputs.WP_VERSION }}"

0 commit comments

Comments
 (0)