mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 11:59:00 +00:00
88 lines
2.7 KiB
YAML
88 lines
2.7 KiB
YAML
name: zig-fmt
|
|
|
|
env:
|
|
ZIG_VERSION: 0.12.0-dev.163+6780a6bbf
|
|
|
|
on:
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
- jarred/test-actions
|
|
paths:
|
|
- "src/**/*.zig"
|
|
- "src/*.zig"
|
|
# Allows you to run this workflow manually from the Actions tab
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
zig-fmt:
|
|
name: zig fmt
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
zig_fmt_errs: ${{ steps.fmt.outputs.zig_fmt_errs }}
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
with:
|
|
submodules: recursive
|
|
- name: Install zig
|
|
run: |
|
|
curl https://ziglang.org/builds/zig-linux-x86_64-${{env.ZIG_VERSION}}.tar.xz -L -o zig.tar.xz
|
|
tar -xf zig.tar.xz
|
|
echo "$(pwd)/zig-linux-x86_64-${{env.ZIG_VERSION}}" >> $GITHUB_PATH
|
|
- name: Run zig fmt
|
|
id: fmt
|
|
run: |
|
|
zig fmt --check src/*.zig src/**/*.zig 2> zig-fmt.err > zig-fmt.err2 || echo "Failed"
|
|
delimiter="$(openssl rand -hex 8)"
|
|
echo "zig_fmt_errs<<${delimiter}" >> "${GITHUB_OUTPUT}"
|
|
|
|
if [ -s zig-fmt.err ]; then
|
|
echo "// The following errors occurred:" >> "${GITHUB_OUTPUT}"
|
|
cat zig-fmt.err >> "${GITHUB_OUTPUT}"
|
|
fi
|
|
|
|
if [ -s zig-fmt.err2 ]; then
|
|
echo "// The following files were not formatted:" >> "${GITHUB_OUTPUT}"
|
|
cat zig-fmt.err2 >> "${GITHUB_OUTPUT}"
|
|
fi
|
|
|
|
echo "${delimiter}" >> "${GITHUB_OUTPUT}"
|
|
- name: Comment on PR
|
|
if: steps.fmt.outputs.zig_fmt_errs != ''
|
|
uses: thollander/actions-comment-pull-request@v2
|
|
with:
|
|
comment_tag: zig-fmt
|
|
message: |
|
|
❌ @${{ github.actor }} `zig fmt` reported errors. Consider configuring your text editor to [auto-format on save](https://github.com/ziglang/vscode-zig)
|
|
|
|
```zig
|
|
// # zig fmt --check src/*.zig src/**/*.zig
|
|
${{ steps.fmt.outputs.zig_fmt_errs }}
|
|
```
|
|
|
|
To one-off fix this manually, run:
|
|
|
|
```sh
|
|
zig fmt src/*.zig src/**/*.zig
|
|
```
|
|
|
|
<sup>[#${{github.sha}}](https://github.com/oven-sh/bun/commits/${{github.sha}})</sup>
|
|
<sup>zig v${{env.ZIG_VERSION}}</sup>
|
|
|
|
- name: Uncomment on PR
|
|
if: steps.fmt.outputs.zig_fmt_errs == ''
|
|
uses: thollander/actions-comment-pull-request@v2
|
|
with:
|
|
comment_tag: zig-fmt
|
|
mode: upsert
|
|
create_if_not_exists: false
|
|
message: |
|
|
✅ `zig fmt` errors have been resolved. Thank you.
|
|
|
|
<sup>[#${{github.sha}}](https://github.com/oven-sh/bun/commits/${{github.sha}})</sup>
|
|
<sup>zig v${{env.ZIG_VERSION}}</sup>
|
|
|
|
- name: Fail the job
|
|
if: steps.fmt.outputs.zig_fmt_errs != ''
|
|
run: exit 1
|