summaryrefslogtreecommitdiff
path: root/.github/workflows/ci.yml
blob: d911da34cf56ad393a99e39529a34e35e91ceed3 (plain)
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
name: continuous integration

on: 
  push:
    paths:
      - 'src/*.cpp'
      - '.clang-format'
      - 'Makefile'
      - '.github/**'
  workflow_dispatch:
  pull_request:
    paths:
      - 'src/*.cpp'
      - 'include/*.hpp'

permissions:
    contents: write
    pull-requests: write

jobs:
  clang-format:
    runs-on: ubuntu-latest
    steps:
    - name: Install dependencies(clang-format & clang-tidy)
      run: sudo apt update && sudo apt install -y g++ && sudo apt install -y clang-format && sudo apt install -y clang-tidy

    - name: Checkout repository
      uses: actions/checkout@v4
      with:
        ref: ${{ github.head_ref }}
        ssh-key: ${{ secrets.DEPLOY_KEY }}
        fetch-depth: 0

    - name: Run clang-format
      run: clang-format -i src/*.cpp src/*.hpp

    - name: Push changes
      uses: stefanzweifel/git-auto-commit-action@v5
      with:
        commit_message: "style: clang-format"
        commit_user_name: "github-actions[bot]"
        commit_user_email: "github-actions[bot]@users.noreply.github.com"
        commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
        # commit_branch: ${{ github.head_ref }}

  build:
    runs-on: ubuntu-latest

    steps:
    - name: Install dependencies(g++)
      run: sudo apt update && sudo apt install -y g++

    - name: Checkout repository
      uses: actions/checkout@v4
      with:
        ref: ${{ github.head_ref }}
        ssh-key: ${{ secrets.DEPLOY_KEY }}
        fetch-depth: 0

    - name: Build project
      run: |
        make

    - name: Revert bad commit
      if: ${{ failure() && format('refs/heads/{0}', github.event.repository.default_branch) == github.ref }}
      run: |
       git config --global user.email "github-actions[bot]@users.noreply.github.com"
       git config --global user.name "github-actions[bot]"
       git revert HEAD --no-edit
       git push --force

    - name: Upload Artifact
      if: success()
      uses: actions/upload-artifact@v4
      with:
          name: Artifact
          path: bin/