build(ci): add ocpp-server code linter check
[e-mobility-charging-stations-simulator.git] / .github / workflows / ci.yml
1 name: CI
2 on:
3 push:
4 branches: [main]
5 pull_request:
6 types: [opened, synchronize, reopened]
7 merge_group:
8 branches: [main]
9 jobs:
10 check-secrets:
11 runs-on: ubuntu-latest
12 outputs:
13 sonar-token-exists: ${{ steps.sonar-token.outputs.defined }}
14 steps:
15 - name: Check for SonarCloud Token Availability
16 id: sonar-token
17 shell: bash
18 run: |
19 if [ "${{ secrets.SONAR_TOKEN }}" != '' ]; then
20 echo "defined=true" >> $GITHUB_OUTPUT;
21 else
22 echo "defined=false" >> $GITHUB_OUTPUT;
23 fi
24 build-ocpp-server:
25 strategy:
26 matrix:
27 python:
28 - 3.12
29 runs-on: ubuntu-latest
30 defaults:
31 run:
32 working-directory: tests/ocpp-server
33 steps:
34 - uses: actions/checkout@v4
35 - name: Setup Python ${{ matrix.python }}
36 uses: actions/setup-python@v4
37 with:
38 python-version: ${{ matrix.python }}
39 - name: Install Poetry
40 run: |
41 python -m pip install --upgrade pip
42 pip install poetry
43 - name: Install Dependencies
44 run: poetry install
45 - name: Lint
46 run: poetry run task lint
47 build-simulator:
48 needs: [check-secrets]
49 strategy:
50 matrix:
51 os: [windows-latest, macos-latest, ubuntu-latest]
52 node: ['20.x', 'latest']
53 name: Build simulator with Node ${{ matrix.node }} on ${{ matrix.os }}
54 runs-on: ${{ matrix.os }}
55 steps:
56 - uses: actions/checkout@v4
57 with:
58 fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
59 - name: Dependency Review
60 if: ${{ github.event_name == 'push' && matrix.os == 'ubuntu-latest' && matrix.node == '20.x' }}
61 uses: actions/dependency-review-action@v4
62 with:
63 base-ref: ${{ github.ref_name }}
64 head-ref: ${{ github.sha }}
65 - name: Pull Request Dependency Review
66 if: ${{ github.event_name == 'pull_request' && matrix.os == 'ubuntu-latest' && matrix.node == '20.x' }}
67 uses: actions/dependency-review-action@v4
68 - uses: pnpm/action-setup@v4
69 - name: Setup node ${{ matrix.node }}
70 uses: actions/setup-node@v4
71 with:
72 node-version: ${{ matrix.node }}
73 cache: 'pnpm'
74 - name: pnpm install
75 run: pnpm install --ignore-scripts --frozen-lockfile
76 - name: pnpm audit
77 if: ${{ matrix.os == 'ubuntu-latest' && matrix.node == '20.x' }}
78 run: pnpm audit --prod
79 - name: pnpm lint
80 if: ${{ matrix.os == 'ubuntu-latest' && matrix.node == '20.x' }}
81 run: pnpm lint
82 - name: pnpm build
83 run: pnpm build
84 - name: pnpm test
85 run: pnpm test
86 - name: pnpm coverage
87 if: ${{ github.repository == 'sap/e-mobility-charging-stations-simulator' && matrix.os == 'ubuntu-latest' && matrix.node == '20.x' }}
88 run: pnpm coverage
89 - name: SonarCloud Scan
90 if: ${{ needs.check-secrets.outputs.sonar-token-exists == 'true' && github.repository == 'sap/e-mobility-charging-stations-simulator' && matrix.os == 'ubuntu-latest' && matrix.node == '20.x' }}
91 uses: sonarsource/sonarcloud-github-action@v2.2.0
92 env:
93 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94 SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
95 build-dashboard:
96 needs: [check-secrets]
97 strategy:
98 matrix:
99 os: [windows-latest, macos-latest, ubuntu-latest]
100 node: ['18.x', '20.x', 'latest']
101 name: Build dashboard with Node ${{ matrix.node }} on ${{ matrix.os }}
102 runs-on: ${{ matrix.os }}
103 defaults:
104 run:
105 working-directory: ui/web
106 steps:
107 - uses: actions/checkout@v4
108 with:
109 fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
110 - name: Dependency Review
111 if: ${{ github.event_name == 'push' && matrix.os == 'ubuntu-latest' && matrix.node == '20.x' }}
112 uses: actions/dependency-review-action@v4
113 with:
114 base-ref: ${{ github.ref_name }}
115 head-ref: ${{ github.sha }}
116 - name: Pull Request Dependency Review
117 if: ${{ github.event_name == 'pull_request' && matrix.os == 'ubuntu-latest' && matrix.node == '20.x' }}
118 uses: actions/dependency-review-action@v4
119 - uses: pnpm/action-setup@v4
120 - name: Setup node ${{ matrix.node }}
121 uses: actions/setup-node@v4
122 with:
123 node-version: ${{ matrix.node }}
124 cache: 'pnpm'
125 - name: pnpm install
126 run: pnpm install --ignore-scripts --frozen-lockfile
127 - name: pnpm audit
128 if: ${{ matrix.os == 'ubuntu-latest' && matrix.node == '20.x' }}
129 run: pnpm audit --prod
130 - name: pnpm lint
131 if: ${{ matrix.os == 'ubuntu-latest' && matrix.node == '20.x' }}
132 run: pnpm lint
133 - name: pnpm build
134 run: pnpm build
135 - name: pnpm test
136 run: pnpm test
137 - name: pnpm coverage
138 if: ${{ github.repository == 'sap/e-mobility-charging-stations-simulator' && matrix.os == 'ubuntu-latest' && matrix.node == '20.x' }}
139 run: pnpm coverage
140 - name: SonarCloud Scan
141 if: ${{ needs.check-secrets.outputs.sonar-token-exists == 'true' && github.repository == 'sap/e-mobility-charging-stations-simulator' && matrix.os == 'ubuntu-latest' && matrix.node == '20.x' }}
142 uses: sonarsource/sonarcloud-github-action@v2.2.0
143 with:
144 projectBaseDir: ui/web
145 env:
146 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
147 SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
148 build-docker-image:
149 runs-on: ubuntu-latest
150 name: Build docker image
151 steps:
152 - uses: actions/checkout@v4
153 - name: Setup Docker Buildx
154 id: buildx
155 uses: docker/setup-buildx-action@v3
156 - name: Build docker image
157 run: |
158 cd docker
159 make SUBMODULES_INIT=false