-
Notifications
You must be signed in to change notification settings - Fork 424
195 lines (157 loc) · 6.43 KB
/
Copy pathautofix.yml
File metadata and controls
195 lines (157 loc) · 6.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
name: autofix.ci # needed to securely identify the workflow
on:
pull_request:
paths:
[
"**.json",
"**.cpp",
"**.hpp",
"**.h",
"**.c",
"**.md",
"**.ts",
"**.lua",
]
pull_request_target:
types: [opened, edited, reopened, synchronize]
permissions:
contents: read
env:
DENO_DIR: /home/runner/.cache/deno
LLVM_VERSION: "22"
jobs:
autofix:
if: github.event_name == 'pull_request'
runs-on: ubuntu-slim
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- env: { DEBIAN_FRONTEND: noninteractive }
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends astyle gettext
- name: Setup C++ format tools
uses: aminya/setup-cpp@v1
with:
compiler: llvm-${{ env.LLVM_VERSION }}
clang-format: ${{ env.LLVM_VERSION }}
cmake: true
ninja: true
ccache: true
setup-cpp: false
- name: Show clang-format version
run: clang-format --version
- uses: denoland/setup-deno@v2
with: { cache: true }
- name: cache deno dependencies
uses: actions/cache@v4
with:
path: ${{ env.DENO_DIR }}
key: deno-${{ hashFiles('deno.lock') }}
- name: format C++ files
run: build-scripts/format-cpp.sh
- name: format Markdown and TypeScript files
run: deno fmt
- name: format Lua files
run: deno task dprint fmt
- name: format JSON
run: build-scripts/format-json.sh
# autofix.ci cannot edit .github directory due to security reasons
- name: unstage .github
if: ${{ always() }}
run: git restore .github
- uses: autofix-ci/action@v1.3
if: ${{ always() }}
with:
commit-message: "style(autofix.ci): automated formatting"
comment: |
Autofix has formatted [code style violation][code-style] in this PR.
<details><summary>I edit commits locally (e.g: git, github desktop) and want to keep autofix</summary>
1. Run `git pull`. this will merge the automated commit into your local copy of the PR branch.
2. Continue working.
</details>
<details><summary>I do not want the automated commit</summary>
1. [Format your code locally](https://docs.cataclysmbn.org/contribute/contributing/#code-style), then commit it.
2. Run `git push --force` to force push your branch. This will overwrite the automated commit on remote with your local one.
3. Continue working.
</details>
If you don't do this, your following commits will be based on the old commit, and cause **MERGE CONFLICT**.
[code-style]: https://docs.cataclysmbn.org/contribute/contributing/#code-style
- name: lint and test typescript files
run: |
# deno lint
deno test --allow-read --allow-env=npm_package_config_libvips,TILESET_PYTHON --allow-ffi
- name: check generated semantic PR config
run: |
deno run --allow-read --allow-write scripts/semantic.ts
git diff --exit-code -- .github/semantic.yml
lint:
if: github.event_name == 'pull_request_target'
runs-on: ubuntu-slim
permissions:
contents: read
pull-requests: write
steps:
- if: >-
github.event.action == 'opened' ||
github.event.action == 'edited' ||
github.event.action == 'reopened'
uses: scarf005/conventional-prs@v0.5.1
- name: Checkout base docs warning script
if: always() && github.event.pull_request.head.ref != github.event.repository.default_branch
uses: actions/checkout@v4
with:
fetch-depth: 1
sparse-checkout: |
docs
scripts/docs_translation_warning.ts
scripts/git_changed_files.ts
deno.jsonc
deno.lock
- name: Setup Deno for docs warning
if: always() && github.event.pull_request.head.ref != github.event.repository.default_branch
continue-on-error: true
uses: denoland/setup-deno@v2
with: { cache: true }
- name: Update docs translation PR body
if: always() && github.event.pull_request.head.ref != github.event.repository.default_branch
env:
GH_TOKEN: ${{ github.token }}
run: |
ref=refs/remotes/pull/${{ github.event.pull_request.number }}/merge
git fetch --no-tags --filter=blob:none --depth=2 origin "+refs/pull/${{ github.event.pull_request.number }}/merge:$ref" || exit 0
deno task docs:translation-warning ${{ github.event.pull_request.number }} --base "$ref^1" --head "$ref" || true
- name: Comment and close pull request
if: >-
always() &&
( github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize' ) &&
github.event.pull_request.head.ref == github.event.repository.default_branch
env: { GH_TOKEN: "${{ github.token }}" }
run: |
body="$(cat <<\BODY
<!-- reject-main-branch-pr -->
This pull request was opened from `main`, which can cause conflicts when updating your fork's `main` branch later. Please open a new pull request from a [feature branch](https://docs.cataclysmbn.org/contribute/contributing/#make-your-changes) instead.
<details>
<summary>How to open a new PR from a branch</summary>
If your changes are already committed on `main`, create a branch at the same commit and push it:
```sh
git switch main
git switch -c your-branch-name
git push -u origin your-branch-name
```
Then open a new pull request from `your-branch-name` and close this one.
If `main` should go back to the upstream branch after that, update it separately after confirming your work is safely on the new branch.
</details>
BODY
)"
gh pr close "${{ github.event.pull_request.number }}" \
--repo "$GITHUB_REPOSITORY" \
--comment "$body"
exit 1
- uses: actions/labeler@v6
if: >-
always() &&
( github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize' )
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}