Skip to content

Commit

Permalink
CI/CD: Script that creates a pull request to run clang-format on our …
Browse files Browse the repository at this point in the history
…codebase
  • Loading branch information
eric15342335 committed Apr 9, 2024
1 parent 7088bf7 commit e62968a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
name: clang-format

on: [pull_request]
on:
push:
branches:
- main
pull_request:

jobs:
cpp-formatting-check:
clang-format:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Run clang-format
run: |
clang-format --Werror --dry-run $(find . -name '*.cpp' -or -name '*.h')
clang-format --Werror --dry-run *.cpp *.h
10 changes: 7 additions & 3 deletions .github/workflows/make.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
"Commented out since our Makefile is empty"
"""name: Make
on: [pull_request]
on:
push:
branches:
- main
pull_request:
jobs:
Make:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Make
run: |
make clean
make
- name: Upload executable
uses: actions/upload-artifact@v4
Expand Down
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

0 comments on commit e62968a

Please sign in to comment.