summaryrefslogtreecommitdiff
path: root/.github/workflows/ci.yml
blob: 419b77b38d167a595a1b886ba1a04038e4e23b06 (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
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
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)
      run: sudo apt update && sudo apt install -y clang-format

    - 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: 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/
  doxygen:
    runs-on: ubuntu-latest
    if: ${{ github.event_name == 'push' && format('refs/heads/{0}', github.event.repository.default_branch) == github.ref }}

    steps:
    - name: Install dependencies(doxygen, graphviz)
      run: sudo apt update && sudo apt install -y doxygen graphviz

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

    - name: Generate Doxygen documentation
      run: doxygen
    
    - name: Push changes
      uses: stefanzweifel/git-auto-commit-action@v5
      with:
        commit_message: "bump: doxygen"
        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 }}

    - name: Deploy to Github Pages
      uses: peaceiris/actions-gh-pages@v4
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        publish_dir: ./docs

    - name: Upload Artifact
      uses: actions/upload-artifact@v4
      with:
          name: Doxygen
          path: docs/