summaryrefslogtreecommitdiff
path: root/.github/workflows/ci.yml
blob: c180d6743c892dd2d3d24909c60eabf00d7f5f3d (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
name: Continuous Integration

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

permissions:
    contents: write
    pull-requests: write

jobs:
  linux:
    if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork
    name: "Build (Linux)"
    runs-on: ubuntu-latest
    container:
      image: archlinux
    steps:
      - name: Checkout repository actions
        uses: actions/checkout@v4
        with:
          sparse-checkout: .github/actions

      - name: Setup base
        uses: ./.github/actions/setup_base

      - 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 all

      - name: Upload Artifact
        if: success()
        uses: actions/upload-artifact@v4
        with:
          name: chat-server-linux
          path: build/chat-server

  # macos:
  #   if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork
  #   name: "Build (macOS)"
  #   runs-on: macos-latest
  #   steps:
  #     - name: Install dependencies
  #       run: |
  #         brew update
  #         brew install llvm@14 gcc@14 make ninja
  #     - name: Install compiler
  #       id: install_cc
  #       uses: rlalik/setup-cpp-compiler@master
  #       with:
  #         compiler: gcc-14
  #     - name: Checkout repository
  #       uses: actions/checkout@v4
  #       with:
  #         ref: ${{ github.head_ref }}
  #         fetch-depth: 0
  #     - name: Build project
  #       env:
  #         # CC: ${{ steps.install_cc.outputs.cc }}
  #         # CXX: ${{ steps.install_cc.outputs.cxx }}
  #         # above don't work cuz for some reason it's using g++ from /usr/local/bin :/
  #         CC: /opt/homebrew/bin/g++-14
  #         CXX: /opt/homebrew/bin/g++-14
  #       run: make all
  #     - name: Upload Artifact
  #       if: success()
  #       uses: actions/upload-artifact@v4
  #       with:
  #         name: chat-server-macos
  #         path: build/chat-server

  clang-linux:
    if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork
    name: "Build with Clang (Linux)"
    runs-on: ubuntu-latest
    container:
      image: archlinux
    steps:
      - name: Checkout repository actions
        uses: actions/checkout@v4
        with:
          sparse-checkout: .github/actions

      - name: Setup base
        uses: ./.github/actions/setup_base

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

      - name: Build project
        run: |
          CXX=clang++ CC=clang++ make all

  clang-format:
    if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork
    name: "Code Style (Arch)"
    runs-on: ubuntu-latest
    container:
      image: archlinux
    steps:
      - name: Install dependencies
        run: |
          pacman -Syu --noconfirm
          pacman -S --noconfirm cmake make clang git

      - 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: make clang-format

      - name: Configure Git
        run: git config --global --add safe.directory '*'

      - 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>"

  clang-tidy:
    if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork
    name: "Static Analysis (Arch)"
    runs-on: ubuntu-latest
    container:
      image: archlinux
    steps:
      - name: Install dependencies
        run: |
          pacman -Syu --noconfirm
          pacman -S --noconfirm cmake make clang git

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

      - name: Run clang-tidy
        run: make clang-tidy || true

      - name: Configure Git
        run: git config --global --add safe.directory '*'

      - name: Push changes
        uses: stefanzweifel/git-auto-commit-action@v5
        with:
          commit_message: "style: clang-tidy"
          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>"