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

Leave PR comments without workflow_dispatch #13

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
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
39 changes: 35 additions & 4 deletions .github/workflows/pull-request-comments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ name: Pull Request Comments
on:
pull_request_target:
types: [ 'opened' ]
branches:
- trunk

workflow_run:
workflows: ["Test Build Processes"]
types:
- completed

# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
Expand Down Expand Up @@ -82,17 +83,47 @@ jobs:
permissions:
issues: write
pull-requests: write
if: ${{ github.repository == 'adamziel/wordpress-develop' && github.event_name == 'pull_request_target' }}
if: >
github.repository == 'WordPress/wordpress-develop' &&
github.event_name == 'workflow_run' &&
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: 'Download artifact'
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
script: |
var artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr"
})[0];
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));

- run: unzip pr.zip

- uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
script: |
const issue_number = Number(fs.readFileSync('./NR'));

// Comments are only added after the first successful build. Check for the presence of a comment and bail early.
const commentInfo = {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.number }}
};

const comments = ( await github.rest.issues.listComments( commentInfo ) ).data;

for ( const currentComment of comments ) {
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/test-build-processes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@ jobs:
os: ${{ matrix.os }}
directory: ${{ matrix.directory }}

# Uploads the PR number as an artifact for the Pull Request Commenting workflow to download and then
# leave a comment detailing how to test the PR within WordPress Playground.
playground-comment:
name: Leave WordPress Playground details
runs-on: ubuntu-latest
permissions:
actions: write
continue-on-error: true
needs: [ test-core-build-process, test-core-build-process-macos, test-gutenberg-build-process, test-gutenberg-build-process-macos ]
if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name == 'pull_request' }}

steps:
- name: Save PR number
run: |
mkdir -p ./pr
echo ${{ github.event.number }} > ./pr/NR
- uses: actions/upload-artifact@v2
with:
name: pr
path: pr/

slack-notifications:
name: Slack Notifications
Expand Down
Loading