|
6 | 6 | format:
|
7 | 7 | runs-on: ubuntu-latest
|
8 | 8 | steps:
|
9 |
| - - uses: actions/checkout@v4 |
| 9 | + - name: Checkout PR branch |
| 10 | + uses: actions/checkout@v4 |
10 | 11 | with:
|
11 | 12 | token: ${{ secrets.SLANGBOT_PAT }}
|
12 | 13 | repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
|
13 | 14 | ref: ${{ github.event.client_payload.pull_request.head.ref }}
|
| 15 | + path: pr-branch |
14 | 16 |
|
15 |
| - - run: pip3 install gersemi |
| 17 | + - name: Checkout target branch |
| 18 | + uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + token: ${{ secrets.SLANGBOT_PAT }} |
| 21 | + repository: ${{ github.event.client_payload.pull_request.base.repo.full_name }} |
| 22 | + ref: ${{ github.event.client_payload.pull_request.base.ref }} |
| 23 | + path: target-branch |
16 | 24 |
|
17 |
| - - name: install clang-format |
18 |
| - run: | |
19 |
| - tmpdir=$(mktemp -d) |
20 |
| - curl -L -H "Authorization: token ${{ secrets.SLANGBOT_PAT }}" \ |
21 |
| - -o "$tmpdir/clang-format" \ |
22 |
| - https://github.com/shader-slang/slang-binaries/raw/4e88845ec51641b4c92e68027e359090bdb219e0/clang-format/x86_64-linux/bin/clang-format |
23 |
| - chmod +x "$tmpdir/clang-format" |
24 |
| - echo "$tmpdir" >> $GITHUB_PATH |
| 25 | + - name: Setup |
| 26 | + uses: ./target-branch/.github/actions/format-setup |
25 | 27 |
|
26 |
| - - run: ./extras/formatting.sh |
| 28 | + - name: Run formatting |
| 29 | + id: format |
| 30 | + run: | |
| 31 | + ./target-branch/extras/formatting.sh --source ./pr-branch |
27 | 32 |
|
28 | 33 | - name: Configure Git commit signing
|
| 34 | + id: git-info |
29 | 35 | run: |
|
30 | 36 | echo "${{ secrets.SLANGBOT_SIGNING_KEY }}" > "${{runner.temp}}"/signing_key
|
31 | 37 | chmod 600 "${{runner.temp}}"/signing_key
|
32 |
| - git config commit.gpgsign true |
33 |
| - git config gpg.format ssh |
34 |
| - git config user.signingkey "${{runner.temp}}"/signing_key |
| 38 | + git -C pr-branch config commit.gpgsign true |
| 39 | + git -C pr-branch config gpg.format ssh |
| 40 | + git -C pr-branch config user.signingkey "${{runner.temp}}"/signing_key |
| 41 | + bot_info=$(curl -s -H "Authorization: Bearer ${{ secrets.SLANGBOT_PAT }}" \ |
| 42 | + "https://api.github.com/user") |
| 43 | + echo "bot_identity=$(echo $bot_info | jq --raw-output '.login + " <" + (.id|tostring) + "+" + .login + "@users.noreply.github.com>"')" >> $GITHUB_OUTPUT |
| 44 | + echo "bot_name=$(echo $bot_info | jq --raw-output '.login')" >> $GITHUB_OUTPUT |
| 45 | +
|
| 46 | + - name: Create Pull Request |
| 47 | + id: create-pr |
| 48 | + uses: peter-evans/create-pull-request@v7 |
| 49 | + with: |
| 50 | + token: ${{ secrets.SLANGBOT_PAT }} |
| 51 | + path: pr-branch |
| 52 | + commit-message: "format code" |
| 53 | + title: "Format code for PR #${{ github.event.client_payload.pull_request.number }}" |
| 54 | + body: "Automated code formatting for ${{ github.event.client_payload.pull_request.url }}" |
| 55 | + committer: ${{ steps.git-info.outputs.bot_identity }} |
| 56 | + author: ${{ steps.git-info.outputs.bot_identity }} |
| 57 | + branch: format-${{ github.event.client_payload.pull_request.number }}-${{ github.event.client_payload.pull_request.head.ref }} |
| 58 | + base: ${{ github.event.client_payload.pull_request.head.ref }} |
| 59 | + push-to-fork: ${{ steps.git-info.outputs.bot_name }}/slang |
| 60 | + delete-branch: true |
35 | 61 |
|
36 |
| - - uses: EndBug/add-and-commit@v9 |
| 62 | + - name: Comment on PR |
| 63 | + uses: peter-evans/create-or-update-comment@v4 |
| 64 | + if: always() |
37 | 65 | with:
|
38 |
| - fetch: false |
39 |
| - message: "format code" |
40 |
| - push: true |
| 66 | + token: ${{ secrets.SLANGBOT_PAT }} |
| 67 | + repository: ${{ github.event.client_payload.github.payload.repository.full_name }} |
| 68 | + issue-number: ${{ github.event.client_payload.pull_request.number }} |
| 69 | + body: | |
| 70 | + ${{ |
| 71 | + steps.format.conclusion == 'failure' |
| 72 | + && format('❌ Formatting failed. Please check the [workflow run](https://github.com/{0}/actions/runs/{1})', github.repository, github.run_id) |
| 73 | + || (steps.create-pr.conclusion == 'failure' |
| 74 | + && format('❌ Failed to create formatting pull request. Please check the [workflow run](https://github.com/{0}/actions/runs/{1})', github.repository, github.run_id) |
| 75 | + || format('🌈 Formatted, please merge the changes from [this PR]({0})', steps.create-pr.outputs.pull-request-url)) |
| 76 | + }} |
41 | 77 |
|
42 | 78 | - name: Add reaction
|
43 | 79 | uses: peter-evans/create-or-update-comment@v4
|
|
0 commit comments