用 GitHub Actions 格式化 C/C++ 程式碼

我的 ProblemSet 專案,每次都 Format 太麻煩了,需要一個自動化 Format 的功能。利用 GitHub Actions,即可實現。

GitHub Actions

GitHub Actions 是 GitHub 推出的持續整合服務,最近不要錢了,用(白嫖)的人就多起來了。

程式碼

直接上程式碼:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

name: "Check Clang Format"

on: [push, pull_request]

jobs:
format:
name: "Run Clang Format"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: "Install clang-format"
run: |
sudo apt-get update
sudo apt-get install clang-format-10
- name: "Format Codes"
run: clang-format-10 -style=file -i */*/*.cpp
- name: Push changes
uses: actions-go/push@v1
with:
author-name: Clang Format Bot
commit-message: Run clang-format

後記

如果大家有什麼改進的好方法,可以在下方評論!