Skip to content

Commit 1831ff4

Browse files
committed
Implement diff and ci command
1 parent 4ea35e5 commit 1831ff4

File tree

13 files changed

+2070
-206
lines changed

13 files changed

+2070
-206
lines changed

.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[target.aarch64-unknown-linux-gnu]
22
linker = "aarch64-linux-gnu-gcc"
3+
4+
[alias]
5+
regress = "run -p svd2rust-regress --"

.github/workflows/ci.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ jobs:
2121
runs-on: ubuntu-latest
2222
strategy:
2323
matrix:
24-
TARGET: [x86_64-unknown-linux-gnu, x86_64-apple-darwin, x86_64-pc-windows-msvc]
24+
TARGET:
25+
[
26+
x86_64-unknown-linux-gnu,
27+
x86_64-apple-darwin,
28+
x86_64-pc-windows-msvc,
29+
]
2530

2631
steps:
2732
- uses: actions/checkout@v4
@@ -176,24 +181,35 @@ jobs:
176181
name: Build svd2rust artifact
177182
if: github.event_name == 'pull_request'
178183
needs: [check]
179-
runs-on: ubuntu-latest
184+
runs-on: ${{ matrix.runs-on }}
185+
strategy:
186+
matrix:
187+
include:
188+
- target: x86_64-unknown-linux-gnu
189+
runs-on: ubuntu-latest
190+
- target: aarch64-apple-darwin
191+
runs-on: macos-latest
192+
- target: x86_64-pc-windows-msvc
193+
runs-on: windows-latest
194+
suffix: .exe
180195
steps:
181196
- uses: actions/checkout@v3
182197

183198
- uses: dtolnay/rust-toolchain@master
184199
with:
185200
toolchain: stable
201+
targets: ${{ matrix.target }}
186202

187203
- name: Cache Dependencies
188204
uses: Swatinem/rust-cache@v2
189205

190206
- name: Build svd2rust artifact
191-
run: cargo build --release
207+
run: cargo build --release --target ${{ matrix.target }}
192208

193-
- run: mv target/release/svd2rust svd2rust-x86_64-unknown-linux-gnu-$(git rev-parse --short HEAD)
209+
- run: mv target/${{ matrix.target }}/release/svd2rust${{ matrix.suffix || '' }} svd2rust-${{ matrix.target }}-$(git rev-parse --short HEAD)${{ matrix.suffix || '' }}
194210

195211
- name: Upload artifact
196212
uses: actions/upload-artifact@v3
197213
with:
198-
name: artifact-svd2rust-x86_64-unknown-linux-gnu
199-
path: svd2rust-x86_64-unknown-linux-gnu*
214+
name: artifact-svd2rust-${{ matrix.target }}
215+
path: svd2rust-${{ matrix.target }}*

.github/workflows/diff.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Diff
2+
on:
3+
issue_comment:
4+
types: [created]
5+
6+
jobs:
7+
generate:
8+
runs-on: ubuntu-latest
9+
outputs:
10+
diffs: ${{ steps.regress-ci.outputs.diffs }}
11+
if: ${{ github.event.issue.pull_request }}
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- uses: dtolnay/rust-toolchain@master
16+
with:
17+
toolchain: stable
18+
19+
- name: Cache
20+
uses: Swatinem/rust-cache@v2
21+
22+
- run: cargo regress ci
23+
id: regress-ci
24+
env:
25+
GITHUB_COMMENT: ${{ github.event.comment.body }}
26+
GITHUB_COMMENT_PR: ${{ github.event.comment.issue_url }}
27+
diff:
28+
runs-on: ubuntu-latest
29+
needs: [generate]
30+
if: needs.generate.outputs.diffs != '{}' && needs.generate.outputs.diffs != '[]' && needs.generate.outputs.diffs != ''
31+
strategy:
32+
matrix:
33+
include: ${{ fromJson(needs.generate.outputs.diffs) }}
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- uses: dtolnay/rust-toolchain@master
38+
with:
39+
toolchain: stable
40+
41+
- name: Cache
42+
uses: Swatinem/rust-cache@v2
43+
with:
44+
cache-on-failure: true
45+
46+
- uses: taiki-e/install-action@v2
47+
if: matrix.needs_semver_checks
48+
with:
49+
tool: cargo-semver-checks
50+
51+
- uses: taiki-e/install-action@v2
52+
with:
53+
tool: git-delta
54+
55+
- run: cargo regress diff ${{ matrix.command }} --use-pager-directly
56+
env:
57+
GH_TOKEN: ${{ github.token }}
58+
GITHUB_PR: ${{ matrix.pr }}
59+
GIT_PAGER: delta --hunk-header-style omit
60+
summary:
61+
runs-on: ubuntu-latest
62+
needs: [diff]
63+
if: always()
64+
steps:
65+
- uses: actions/checkout@v4
66+
67+
- run: |
68+
PR_ID=$(echo "${{ github.event.comment.issue_url }}" | grep -o '[0-9]\+$')
69+
gh run view ${{ github.run_id }} --json jobs | \
70+
jq -r '"Diff for [comment]("+$comment+")\n\n" + ([.jobs[] | select(.name | startswith("diff")) | "- [" + (.name | capture("\\((?<name>[^,]+),.*") | .name) + "](" + .url + "?pr=" + $pr_id + "#step:7:45)"] | join("\n"))' --arg pr_id "$PR_ID" --arg comment "${{ github.event.comment.url }}"| \
71+
gh pr comment "$PR_ID" --body "$(< /dev/stdin)"
72+
env:
73+
GH_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)