Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI/CD: clang-format #7

Merged
merged 12 commits into from
Apr 9, 2024
23 changes: 23 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
Standard: Cpp11
Language: Cpp

UseTab: Never
IndentWidth: 4
TabWidth: 4
IndentAccessModifiers: true

ColumnLimit: 0

BreakBeforeBraces: Custom
BraceWrapping:
BeforeElse: True

DerivePointerAlignment: false
PointerAlignment: Middle

IncludeBlocks: Preserve
SortIncludes: Never

ReflowComments: true
...
17 changes: 17 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: clang-format

on:
push:
branches:
- main
pull_request:

jobs:
clang-format:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run clang-format
run: |
clang-format --Werror --dry-run *.cpp *.h
28 changes: 28 additions & 0 deletions .github/workflows/make.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"Commented out since our Makefile is empty"
"""name: Make

on:
push:
branches:
- main
pull_request:

jobs:
Make:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Make
run: |
make
- name: Upload executable
uses: actions/upload-artifact@v4
with:
# suppose we compiled our game and named it 'stocksim'
name: stocksim
path: stocksim
compression-level: 9
retention-days: 90
if-no-files-found: error
"""
24 changes: 24 additions & 0 deletions .github/workflows/pr-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: clang-format pull request

on:
[workflow_dispatch]

jobs:
clang-format:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create pull request
run: |
rand_char=$(openssl rand -hex 3)
git checkout -b clang-format-$rand_char
clang-format -i *.cpp *.h
git add --all
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git commit -m "Format: Run clang-format on main branch"
git push -u origin clang-format-$rand_char
gh pr create -B main -H clang-format-$rand_char --title 'Format: Run clang-format on main branch' --body "This pull request fixes formatting issues in the codebase using .clang-format configuration file. Created by Github Actions"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion stock.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class Stock {
* @return Most recent price being the *last* element in the vector.
* If the number of rounds is greater than the size of the history array,
* return the entire history
*/
*/
vector<double> return_most_recent_history(int rounds);

/**
Expand Down