-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from antmicro/rkol/ext-pr-workflow
Replace double workflow setup with `target` workflow trigger
- Loading branch information
Showing
1 changed file
with
11 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,62 +74,25 @@ Automatic review on PRs from external repositories | |
|
||
In GitHub Actions, workflows triggered by external repositories may only have | ||
[read access to the main repository](https://docs.github.com/en/actions/reference/authentication-in-a-workflow#permissions-for-the-github_token). | ||
In order to have automatic reviews on external PRs, you need to create two workflows. | ||
One will be triggered on ``pull_request`` and upload the data needed by reviewdog as an artifact. | ||
The artifact shall store the file pointed by ``$GITHUB_EVENT_PATH`` as ``event.json``. | ||
The other workflow will download the artifact and use the Verible action. | ||
In order to have automatic reviews on external PRs, you need to change your workflow to trigger | ||
on ``pull_request_target`` event and manually check out changes from pull request: | ||
|
||
For example: | ||
```yaml | ||
name: upload-event-file | ||
on: | ||
pull_request: | ||
... | ||
- run: cp "$GITHUB_EVENT_PATH" ./event.json | ||
- name: Upload event file as artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: event.json | ||
path: event.json | ||
``` | ||
|
||
```yaml | ||
name: review-triggered | ||
name: Verible formatter example | ||
on: | ||
workflow_run: | ||
workflows: ["upload-event-file"] | ||
types: | ||
- completed | ||
pull_request_target: | ||
jobs: | ||
review_triggered: | ||
format: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
checks: write | ||
contents: read | ||
pull-requests: write | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: 'Download artifact' | ||
id: get-artifacts | ||
uses: actions/[email protected] | ||
- uses: actions/checkout@v3 | ||
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 == "event.json" | ||
})[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}}/event.json.zip', Buffer.from(download.data)); | ||
- run: | | ||
unzip event.json.zip | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
- name: Run Verible formatter action | ||
uses: chipsalliance/verible-formatter-action@main | ||
with: | ||
|