Skip to content

Commit 7e31d11

Browse files
Fix nasa#386, Reuse CodeQL, Static Analysis, Format Check
Co-authored-by: Ariel Adams <ArielSAdamsNASA@users.noreply.github.com>
1 parent d2ecab8 commit 7e31d11

7 files changed

+161
-76
lines changed

.github/workflows/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Our Workflows
22

3+
## Reusable Workflows
4+
5+
To reduce duplication, the workflows CodeQL Analysis, Static Analysis, and Format Checker are placed in cFS to be reused in the subrepositories.
6+
7+
CodeQL Analysis and Static Analysis require inputs, therefore, they are called in an additional workflow in cFS to be utilized. Format checker does not need to be reused in cFS because it does not require inputs.
8+
9+
Provided is a diagram of the architecture of the reusable workflows.
10+
11+
![Reusable Workflows Architecture](Reusable-Workflows-Architecture.PNG)
12+
313
## Deprecated Build, Test, and Run
414
[![Deprecated Build, Test, and Run](https://github.com/nasa/cfs/actions/workflows/build-cfs-deprecated.yml/badge.svg)](https://github.com/nasa/cfs/actions/workflows/build-cfs-deprecated.yml)
515

Loading
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Reuse CodeQl Analysis
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
codeql:
9+
name: CodeQL Analysis
10+
uses: nasa/cFS/.github/workflows/codeql-build.yml@main

.github/workflows/codeql-build.yml

+49-51
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,46 @@
11
name: "CodeQL Analysis"
22

3-
# Only trigger, when the build workflow succeeded
43
on:
5-
workflow_run:
6-
workflows: ["Build, Test, and Run \\[OMIT_DEPRECATED = true\\]"]
7-
types:
8-
- completed
9-
branches:
10-
- '**'
4+
workflow_call:
5+
inputs:
6+
setup:
7+
description: 'Build Prep'
8+
type: string
9+
default: 'cp ./cfe/cmake/Makefile.sample Makefile && cp -r ./cfe/cmake/sample_defs sample_defs'
10+
make-prep:
11+
description: 'Make Prep'
12+
type: string
13+
default: ''
14+
make:
15+
description: 'Make Copy'
16+
type: string
17+
default: 'make'
18+
tests:
19+
description: 'Tests'
20+
type: string
21+
default: ''
22+
1123
env:
1224
SIMULATION: native
1325
ENABLE_UNIT_TESTS: true
1426
OMIT_DEPRECATED: true
1527
BUILDTYPE: release
1628

17-
1829
jobs:
1930
#Checks for duplicate actions. Skips push actions if there is a matching or duplicate pull-request action.
2031
check-for-duplicates:
2132
runs-on: ubuntu-latest
2233
# Map a step output to a job output
2334
outputs:
2435
should_skip: ${{ steps.skip_check.outputs.should_skip }}
25-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
2636
steps:
2737
- id: skip_check
2838
uses: fkirc/skip-duplicate-actions@master
2939
with:
3040
concurrent_skipping: 'same_content'
3141
skip_after_successful_duplicate: 'true'
3242
do_not_skip: '["pull_request", "workflow_dispatch", "schedule"]'
33-
34-
43+
3544
CodeQL-Security-Build:
3645
#Continue if check-for-duplicates found no duplicates. Always runs for pull-requests.
3746
needs: check-for-duplicates
@@ -42,42 +51,37 @@ jobs:
4251
steps:
4352
# Checks out a copy of your repository
4453
- name: Checkout code
45-
if: ${{ !steps.skip-workflow.outputs.skip }}
4654
uses: actions/checkout@v2
4755
with:
4856
repository: nasa/cFS
4957
submodules: true
5058

5159
- name: Check versions
52-
if: ${{ !steps.skip-workflow.outputs.skip }}
5360
run: |
5461
git log -1 --pretty=oneline
5562
git submodule
56-
63+
5764
- name: Initialize CodeQL
58-
if: ${{ !steps.skip-workflow.outputs.skip }}
5965
uses: github/codeql-action/init@v1
6066
with:
6167
languages: c
62-
config-file: ./.github/codeql/codeql-security.yml
63-
64-
# Setup the build system
68+
config-file: nasa/cFS/.github/codeql/codeql-security.yml@main
69+
6570
- name: Copy sample_defs
66-
if: ${{ !steps.skip-workflow.outputs.skip }}
67-
run: |
68-
cp ./cfe/cmake/Makefile.sample Makefile
69-
cp -r ./cfe/cmake/sample_defs sample_defs
71+
run: ${{ inputs.setup }}
7072

71-
# Setup the build system
73+
- name: Make prep
74+
run: ${{ inputs.make-prep }}
75+
7276
- name: Make Install
73-
if: ${{ !steps.skip-workflow.outputs.skip }}
74-
run: make
77+
run: ${{ inputs.make }}
78+
79+
- name: Run tests
80+
run: ${{ inputs.tests }}
7581

76-
# Run CodeQL
7782
- name: Perform CodeQL Analysis
78-
if: ${{ !steps.skip-workflow.outputs.skip }}
7983
uses: github/codeql-action/analyze@v1
80-
84+
8185
CodeQL-Coding-Standard-Build:
8286
#Continue if check-for-duplicates found no duplicates. Always runs for pull-requests.
8387
needs: check-for-duplicates
@@ -88,45 +92,39 @@ jobs:
8892
steps:
8993
# Checks out a copy of your repository
9094
- name: Checkout code
91-
if: ${{ !steps.skip-workflow.outputs.skip }}
9295
uses: actions/checkout@v2
9396
with:
9497
repository: nasa/cFS
9598
submodules: true
9699

97100
- name: Check versions
98-
if: ${{ !steps.skip-workflow.outputs.skip }}
99101
run: |
100102
git log -1 --pretty=oneline
101103
git submodule
104+
- name: Checkout codeql code
105+
uses: actions/checkout@v2
106+
with:
107+
repository: github/codeql
108+
submodules: true
109+
path: codeql
102110

103111
- name: Initialize CodeQL
104-
if: ${{ !steps.skip-workflow.outputs.skip }}
105112
uses: github/codeql-action/init@v1
106113
with:
107114
languages: c
108-
config-file: ./.github/codeql/codeql-coding-standard.yml
115+
config-file: nasa/cFS/.github/codeql/codeql-coding-standard.yml@main
109116

110-
# Setup the build system
111117
- name: Copy sample_defs
112-
if: ${{ !steps.skip-workflow.outputs.skip }}
113-
run: |
114-
cp ./cfe/cmake/Makefile.sample Makefile
115-
cp -r ./cfe/cmake/sample_defs sample_defs
116-
117-
# Setup the build system
118+
run: ${{ inputs.setup }}
119+
120+
- name: Make prep
121+
run: ${{ inputs.make-prep }}
122+
118123
- name: Make Install
119-
if: ${{ !steps.skip-workflow.outputs.skip }}
120-
run: make
124+
run: ${{ inputs.make }}
125+
126+
- name: Run tests
127+
run: ${{ inputs.tests }}
121128

122-
# Run CodeQL
123129
- name: Perform CodeQL Analysis
124-
if: ${{ !steps.skip-workflow.outputs.skip }}
125-
uses: github/codeql-action/analyze@v1
126-
127-
on-failure:
128-
runs-on: ubuntu-latest
129-
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
130-
steps:
131-
- name: Fail workflow
132-
run: exit 1
130+
uses: github/codeql-action/analyze@v1

.github/workflows/format-check.yml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Format Check
2+
3+
# Run on all push and pull requests
4+
on:
5+
push:
6+
pull_request:
7+
workflow_call:
8+
9+
jobs:
10+
#Checks for duplicate actions. Skips push actions if there is a matching or duplicate pull-request action.
11+
check-for-duplicates:
12+
runs-on: ubuntu-latest
13+
# Map a step output to a job output
14+
outputs:
15+
should_skip: ${{ steps.skip_check.outputs.should_skip }}
16+
steps:
17+
- id: skip_check
18+
uses: fkirc/skip-duplicate-actions@master
19+
with:
20+
concurrent_skipping: 'same_content'
21+
skip_after_successful_duplicate: 'true'
22+
do_not_skip: '["pull_request", "workflow_dispatch", "schedule"]'
23+
24+
format-checker:
25+
name: Run format check
26+
#Continue if check-for-duplicates found no duplicates. Always runs for pull-requests.
27+
needs: check-for-duplicates
28+
if: ${{ needs.check-for-duplicates.outputs.should_skip != 'true' }}
29+
runs-on: ubuntu-18.04
30+
timeout-minutes: 15
31+
32+
steps:
33+
- name: Install format checker
34+
run: |
35+
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
36+
sudo add-apt-repository 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main'
37+
sudo apt-get update && sudo apt-get install clang-format-10
38+
39+
- name: Checkout bundle
40+
uses: actions/checkout@v2
41+
with:
42+
repository: nasa/cFS
43+
44+
- name: Checkout
45+
uses: actions/checkout@v2
46+
with:
47+
path: repo
48+
49+
- name: Generate format differences
50+
run: |
51+
cd repo
52+
find . -name "*.[ch]" -exec clang-format-10 -i -style=file {} +
53+
git diff > $GITHUB_WORKSPACE/style_differences.txt
54+
55+
- name: Archive Static Analysis Artifacts
56+
uses: actions/upload-artifact@v2
57+
with:
58+
name: style_differences
59+
path: style_differences.txt
60+
61+
- name: Error on differences
62+
run: |
63+
if [[ -s style_differences.txt ]];
64+
then
65+
cat style_differences.txt
66+
exit -1
67+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Reuse Static Analysis
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
static-analysis:
9+
name: Static Analysis
10+
uses: nasa/cFS/.github/workflows/static-analysis.yml@main

.github/workflows/static-analysis.yml

+15-25
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
name: Static Analysis
22

3-
# Run this workflow every time a new commit pushed to your repository and for pull requests
43
on:
5-
push:
6-
pull_request:
4+
workflow_call:
5+
inputs:
6+
strict-dir-list:
7+
description: 'Directory List'
8+
type: string
9+
default: ''
710

811
jobs:
912
#Checks for duplicate actions. Skips push actions if there is a matching or duplicate pull-request action.
@@ -30,7 +33,7 @@ jobs:
3033
strategy:
3134
fail-fast: false
3235
matrix:
33-
cppcheck: [bundle, cfe, osal, psp]
36+
cppcheck: [non-strict, strict]
3437

3538
steps:
3639
- name: Install cppcheck
@@ -43,38 +46,25 @@ jobs:
4346
submodules: true
4447

4548
- name: Run bundle cppcheck
46-
if: ${{matrix.cppcheck =='bundle'}}
47-
run: cppcheck --force --inline-suppr --quiet . 2> ${{matrix.cppcheck}}_cppcheck_err.txt
48-
49+
run: cppcheck --force --inline-suppr . 2> ${{matrix.cppcheck}}_cppcheck_err.txt
50+
4951
# Run strict static analysis for embedded portions of cfe, osal, and psp
50-
- name: cfe strict cppcheck
51-
if: ${{matrix.cppcheck =='cfe'}}
52-
run: |
53-
cd ${{matrix.cppcheck}}
54-
cppcheck --force --inline-suppr --std=c99 --language=c --enable=warning,performance,portability,style --suppress=variableScope --inconclusive ./modules/core_api/fsw ./modules/core_private/fsw ./modules/es/fsw ./modules/evs/fsw ./modules/fs/fsw ./modules/msg/fsw ./modules/resourceid/fsw ./modules/sb/fsw ./modules/sbr/fsw ./modules/tbl/fsw ./modules/time/fsw -UCFE_PLATFORM_TIME_CFG_CLIENT -DCFE_PLATFORM_TIME_CFG_SERVER 2> ../${{matrix.cppcheck}}_cppcheck_err.txt
55-
56-
- name: osal strict cppcheck
57-
if: ${{matrix.cppcheck =='osal'}}
58-
run: |
59-
cd ${{matrix.cppcheck}}
60-
cppcheck --force --inline-suppr --std=c99 --language=c --enable=warning,performance,portability,style --suppress=variableScope --inconclusive ./src/bsp ./src/os 2> ../${{matrix.cppcheck}}_cppcheck_err.txt
61-
62-
- name: psp strict cppcheck
63-
if: ${{matrix.cppcheck =='psp'}}
64-
run: |
65-
cd ${{matrix.cppcheck}}
66-
cppcheck --force --inline-suppr --std=c99 --language=c --enable=warning,performance,portability,style --suppress=variableScope --inconclusive ./fsw 2> ../${{matrix.cppcheck}}_cppcheck_err.txt
52+
- name: Strict cppcheck
53+
if: ${{ inputs.strict-dir-list !='' }}
54+
run: cppcheck --force --inline-suppr --std=c99 --language=c --enable=warning,performance,portability,style --suppress=variableScope --inconclusive .${{ inputs.strict-dir-list }} 2> ../${{matrix.cppcheck}}_cppcheck_err.txt
6755

6856
- name: Archive Static Analysis Artifacts
57+
if: ${{ inputs.strict-dir-list !='' || matrix.cppcheck == 'non-strict' }}
6958
uses: actions/upload-artifact@v2
7059
with:
7160
name: ${{matrix.cppcheck}}-cppcheck-err
7261
path: ./*cppcheck_err.txt
7362

7463
- name: Check for errors
64+
if: ${{ inputs.strict-dir-list !='' || matrix.cppcheck == 'non-strict' }}
7565
run: |
7666
if [[ -s ${{matrix.cppcheck}}_cppcheck_err.txt ]];
7767
then
7868
cat ${{matrix.cppcheck}}_cppcheck_err.txt
7969
exit -1
80-
fi
70+
fi

0 commit comments

Comments
 (0)