Skip to content

Commit

Permalink
Simplest possible workflow_run trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed Dec 8, 2023
1 parent 702f003 commit bb99260
Showing 1 changed file with 3 additions and 88 deletions.
91 changes: 3 additions & 88 deletions .github/workflows/pull-request-comments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,100 +2,15 @@
name: Pull Request Comments

on:
pull_request:
types: [ 'opened' ]
pull_request_target:
types: [ 'opened' ]
workflow_run:
workflows:
- TestBuildProcesses
types:
- completed

# Disable permissions for all available scopes by default.
# Any needed permissions should be configured at the job level.
permissions: {}

jobs:
# Leaves a comment on a pull request with a link to test the changes in a WordPress Playground instance.
playground-details:
name: Comment on a pull request with Playground details
test-job:
name: Test Step
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
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 }},
});
/*
github.repository: ${{github.repository}}
github.event_name: ${{github.event_name}}
github.event.workflow_run.event: ${{github.event.workflow_run.event}}
github.event.workflow_run.conclusion: ${{github.event.workflow_run.conclusion}}
*/
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,
};
const comments = ( await github.rest.issues.listComments( commentInfo ) ).data;
for ( const currentComment of comments ) {
if ( currentComment.user.type === 'Bot' && currentComment.body.includes( 'Test using WordPress Playground' ) ) {
// return;
}
};
// No comment was found. Create one.
commentInfo.body = `## Test using WordPress Playground
The changes in this pull request can previewed and tested using a [WordPress Playground](https://developer.wordpress.org/playground/) instance.
github.repository: ${{github.repository}}
github.event_name: ${{github.event_name}}
github.event.workflow_run.event: ${{github.event.workflow_run.event}}
github.event.workflow_run.conclusion: ${{github.event.workflow_run.conclusion}}
[WordPress Playground](https://developer.wordpress.org/playground/) is an experimental project that creates a full WordPress instance entirely within the browser.
### Some things to be aware of
- The Plugin and Theme Directories cannot be accessed within Playground.
- All changes will be lost when closing a tab with a Playground instance.
- All changes will be lost when refreshing the page.
- A fresh instance is created each time the link below is clicked.
- Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
it's possible that the most recent build failed, or has not completed. Check the [list of workflow runs to be sure](https://github.com/WordPress/wordpress-develop/actions/workflows/wordpress-playground.yml).
For more details about these limitations and more, check out the [Limitations page](https://wordpress.github.io/wordpress-playground/limitations/) in the WordPress Playground documentation.
[Test this pull request with WordPress Playground](https://playground.wordpress.net/wordpress.html?pr=${{ github.event.number }}).
`;
github.rest.issues.createComment( commentInfo );
- run: env

0 comments on commit bb99260

Please sign in to comment.