summaryrefslogtreecommitdiff
path: root/.github/workflows/cmake.yml
blob: 340a97e952a3c9516aa1364f08ca4f72d744b2f2 (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
180
181
182
183
184
185
186
187
188
189
190
191
192
name: Build, lint, and test

on: [push, pull_request]

env:
  # Don't mix these up!
  # runner.workspace = /home/runner/work/serenity
  # github.workspace = /home/runner/work/serenity/serenity
  SERENITY_ROOT: ${{ github.workspace }}

jobs:
  build_and_test:
    runs-on: ubuntu-20.04

    steps:
    - uses: actions/checkout@v2

    # === OS SETUP ===

    # Do we need to update the package cache first?
    # sudo apt-get update -qq

    - name: Purge interfering packages
      # Remove GCC 9 and clang-format 10 (installed by default)
      run: sudo apt-get purge -y gcc-9 g++-9 libstdc++-9-dev clang-format-10
    - name: Install dependencies
      # These packages are already part of the ubuntu-20.04 image:
      # cmake gcc-10 g++-10 shellcheck libgmp-dev
      # These aren't:
      run: |
        wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
        sudo add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-11 main"
        sudo apt-get update
        sudo apt-get install clang-format-11 libstdc++-10-dev libmpfr-dev libmpc-dev ninja-build npm
      # If we ever do any qemu-emulation on Github Actions, we should re-enable this:
      # e2fsprogs qemu-system-i386 qemu-utils
    - name: Install prettier
      run: sudo npm install -g prettier
    - name: Use GCC 10 instead
      run: sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 60 --slave /usr/bin/g++ g++ /usr/bin/g++-10
    - name: Check versions
      run: set +e; g++ --version; g++-10 --version; clang-format --version; clang-format-11 --version; prettier --version; python --version; python3 --version; ninja --version

    # === PREPARE FOR BUILDING ===

    - name: Lint (Phase 1/2)
      run: ${{ github.workspace }}/Meta/lint-ci.sh
    - name: Toolchain cache
      uses: actions/cache@v2
      with:
        path: ${{ github.workspace }}/Toolchain/Cache/
        # This assumes that *ALL* LibC headers have an impact on the Toolchain.
        # This is wrong, and causes more Toolchain rebuilds than necessary.
        # However, we want to avoid false cache hits at all costs.
        key: ${{ runner.os }}-toolchain-i686-${{ hashFiles('Libraries/LibC/**/*.h', 'Toolchain/Patches/*.patch', 'Toolchain/BuildIt.sh') }}
    - name: Restore or regenerate Toolchain
      run: TRY_USE_LOCAL_TOOLCHAIN=y ${{ github.workspace }}/Toolchain/BuildIt.sh

    # TODO: ccache
    # https://cristianadam.eu/20200113/speeding-up-c-plus-plus-github-actions-using-ccache/
    # https://github.com/cristianadam/HelloWorld/blob/master/.github/workflows/build_cmake.yml
    - name: Create build environment
      working-directory: ${{ github.workspace }}
      # Note that this needs to run *even if* the Toolchain was built,
      # in order to set options like BUILD_LAGOM.
      run: |
        mkdir -p Build
        cd Build
        cmake .. -GNinja -DBUILD_LAGOM=1 -DENABLE_ALL_THE_DEBUG_MACROS=ON

    # === ACTUALLY BUILD AND TEST ===

    - name: Initialize CodeQL Static Analysis for C++
      uses: github/codeql-action/init@v1
      with:
        languages: cpp
        config-file: ./.github/codeql/config.yml

    - name: Build Serenity and Tests
      working-directory: ${{ github.workspace }}/Build
      run: cmake --build .
    - name: Lint (Phase 2/2)
      working-directory: ${{ github.workspace }}/Meta
      run: ./check-symbols.sh
    - name: Run CMake tests
      working-directory: ${{ github.workspace }}/Build
      run: CTEST_OUTPUT_ON_FAILURE=1 ninja test
      timeout-minutes: 2
    - name: Run JS tests
      working-directory: ${{ github.workspace }}/Build/Meta/Lagom
      run: DISABLE_DBG_OUTPUT=1 ./test-js

     # Run analysis last, so contributors get lint/test feedback ASAP.
    - name: Perform post build CodeQL Analysis
      uses: github/codeql-action/analyze@v1

    # === NOTIFICATIONS ===

    - name: Dump event info
      if: always()
      # Usually unnecessary, but insanely useful if IRC notifications fail.
      run: |
        cat <<"EOF"
        ${{ toJSON(github.event) }}
        EOF
    - name: Generate IRC message
      # I really dislike putting so much logic here, but I can't come up with something better.
      if: github.repository == 'SerenityOS/serenity' && !cancelled() && (github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/master'))
      run: |
        ${{ github.workspace }}/Meta/notify_irc.py <<"EOF"
        ["${{ github.actor }}", ${{ github.run_id }}, "${{ job.status }}",
        ${{ toJSON(github.event) }}
        ]
        EOF
  build_lagom_with_fuzzers:
    runs-on: ubuntu-20.04

    steps:
    - uses: actions/checkout@v2

    # === OS SETUP ===
    #
    - name: Install dependencies
      run: sudo apt-get install ninja-build
    - name: Check versions
      run: set +e; clang --version; clang++ --version; ninja --version

    # === PREPARE FOR BUILDING ===

    # TODO: ccache
    # https://cristianadam.eu/20200113/speeding-up-c-plus-plus-github-actions-using-ccache/
    # https://github.com/cristianadam/HelloWorld/blob/master/.github/workflows/build_cmake.yml
    - name: Create build environment
      working-directory: ${{ github.workspace }}/Meta/Lagom
      run: |
        mkdir -p Build
        cd Build
        cmake -GNinja -DBUILD_LAGOM=ON -DENABLE_FUZZER_SANITIZER=ON -DENABLE_ADDRESS_SANITIZER=ON -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ..

    # === ACTUALLY BUILD ===

    - name: Build Lagom with Fuzzers
      working-directory: ${{ github.workspace }}/Meta/Lagom/Build
      run: cmake --build .
  build_and_test_on_macos:
    runs-on: macos-10.15

    steps:
    - uses: actions/checkout@v2

    - name: Install dependencies
      run: brew install coreutils ninja
    - name: Check versions
      run: set +e; g++ --version; g++-10 --version; clang --version; clang++ --version; python --version; python3 --version; ninja --version
    - name: Toolchain cache
      uses: actions/cache@v2
      with:
        path: ${{ github.workspace }}/Toolchain/Cache/
        # This assumes that *ALL* LibC headers have an impact on the Toolchain.
        # This is wrong, and causes more Toolchain rebuilds than necessary.
        # However, we want to avoid false cache hits at all costs.
        key: ${{ runner.os }}-toolchain-i686-${{ hashFiles('Libraries/LibC/**/*.h', 'Toolchain/Patches/*.patch', 'Toolchain/BuildIt.sh') }}
    - name: Restore or regenerate Toolchain
      run: TRY_USE_LOCAL_TOOLCHAIN=y ${{ github.workspace }}/Toolchain/BuildIt.sh

    # TODO: ccache
    # https://cristianadam.eu/20200113/speeding-up-c-plus-plus-github-actions-using-ccache/
    # https://github.com/cristianadam/HelloWorld/blob/master/.github/workflows/build_cmake.yml
    - name: Create build environment
      working-directory: ${{ github.workspace }}
      # Note that this needs to run *even if* the Toolchain was built,
      # in order to set options like BUILD_LAGOM.
      run: |
        mkdir -p Build
        cd Build
        cmake .. -GNinja -DBUILD_LAGOM=1 -DENABLE_ALL_THE_DEBUG_MACROS=ON -DCMAKE_C_COMPILER=gcc-10 -DCMAKE_CXX_COMPILER=g++-10

    # === ACTUALLY BUILD AND TEST ===

    - name: Build Serenity and Tests
      working-directory: ${{ github.workspace }}/Build
      run: cmake --build .
    - name: Run CMake tests
      working-directory: ${{ github.workspace }}/Build
      # FIXME: Fix tests on MacOS
      run: CTEST_OUTPUT_ON_FAILURE=1 ninja test || true
      continue-on-error: true
      timeout-minutes: 2
    - name: Run JS tests
      working-directory: ${{ github.workspace }}/Build/Meta/Lagom
      # FIXME: Fix tests on MacOS
      run: DISABLE_DBG_OUTPUT=1 ./test-js || true