|
| 1 | +Verible Formatter Action |
| 2 | +======================== |
| 3 | + |
| 4 | +Usage |
| 5 | +----- |
| 6 | + |
| 7 | +See [action.yml](action.yml) |
| 8 | + |
| 9 | +This is a GitHub Action used to format Verilog and SystemVerilog source files |
| 10 | +and create change suggestions in Pull Requests automatically. |
| 11 | +The GitHub Token input is used to provide |
| 12 | +[reviewdog](https://github.com/reviewdog/reviewdog) |
| 13 | +access to the PR. |
| 14 | + |
| 15 | +Here's a basic example to format all ``*.v`` and ``*.sv`` files: |
| 16 | +```yaml |
| 17 | +name: Verible formatter example |
| 18 | +on: |
| 19 | + pull_request: |
| 20 | +jobs: |
| 21 | + lint: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@master |
| 25 | + - uses: chipsalliance/verible-format-action@main |
| 26 | + with: |
| 27 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 28 | +``` |
| 29 | +
|
| 30 | +You can provide ``paths`` argument to point files to format. |
| 31 | +Directories will be searched recursively for ``*.v`` and ``*.sv`` files. |
| 32 | +``paths`` defaults to ``'.'``. |
| 33 | +
|
| 34 | +```yaml |
| 35 | +- uses: chipsalliance/verible-format-action@main |
| 36 | + with: |
| 37 | + paths: | |
| 38 | + ./rtl |
| 39 | + ./shared |
| 40 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 41 | +``` |
| 42 | +
|
| 43 | +Automatic review on PRs from external repositories |
| 44 | +-------------------------------------------------- |
| 45 | +
|
| 46 | +In GitHub Actions, workflows triggered by external repositories may only have |
| 47 | +[read access to the main repository](https://docs.github.com/en/actions/reference/authentication-in-a-workflow#permissions-for-the-github_token). |
| 48 | +In order to have automatic reviews on external PRs, you need to create two workflows. |
| 49 | +One will be triggered on ``pull_request`` and upload the data needed by reviewdog as an artifact. |
| 50 | +The artifact shall store the file pointed by ``$GITHUB_EVENT_PATH`` as ``event.json``. |
| 51 | +The other workflow will download the artifact and use the Verible action. |
| 52 | +
|
| 53 | +For example: |
| 54 | +```yaml |
| 55 | +name: upload-event-file |
| 56 | +on: |
| 57 | + pull_request: |
| 58 | + |
| 59 | +... |
| 60 | + - run: cp "$GITHUB_EVENT_PATH" ./event.json |
| 61 | + - name: Upload event file as artifact |
| 62 | + uses: actions/upload-artifact@v2 |
| 63 | + with: |
| 64 | + name: event.json |
| 65 | + path: event.json |
| 66 | +``` |
| 67 | +
|
| 68 | +```yaml |
| 69 | +name: review-triggered |
| 70 | +on: |
| 71 | + workflow_run: |
| 72 | + workflows: ["upload-event-file"] |
| 73 | + types: |
| 74 | + - completed |
| 75 | + |
| 76 | +jobs: |
| 77 | + review_triggered: |
| 78 | + runs-on: ubuntu-latest |
| 79 | + steps: |
| 80 | + - uses: actions/checkout@v2 |
| 81 | + - name: 'Download artifact' |
| 82 | + id: get-artifacts |
| 83 | + |
| 84 | + with: |
| 85 | + script: | |
| 86 | + var artifacts = await github.actions.listWorkflowRunArtifacts({ |
| 87 | + owner: context.repo.owner, |
| 88 | + repo: context.repo.repo, |
| 89 | + run_id: ${{github.event.workflow_run.id }}, |
| 90 | + }); |
| 91 | + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { |
| 92 | + return artifact.name == "event.json" |
| 93 | + })[0]; |
| 94 | + var download = await github.actions.downloadArtifact({ |
| 95 | + owner: context.repo.owner, |
| 96 | + repo: context.repo.repo, |
| 97 | + artifact_id: matchArtifact.id, |
| 98 | + archive_format: 'zip', |
| 99 | + }); |
| 100 | + var fs = require('fs'); |
| 101 | + fs.writeFileSync('${{github.workspace}}/event.json.zip', Buffer.from(download.data)); |
| 102 | + - run: | |
| 103 | + unzip event.json.zip |
| 104 | + - name: Run Verible formatter action |
| 105 | + uses: chipsalliance/verible-formatter-action@main |
| 106 | + with: |
| 107 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 108 | +``` |
0 commit comments