|
12 | 12 |
|
13 | 13 | jobs: |
14 | 14 | build: |
15 | | - name: Build, lint and unit tests |
16 | 15 | runs-on: ubuntu-latest |
17 | 16 | permissions: |
18 | 17 | contents: read |
19 | 18 | outputs: |
20 | 19 | plugin-id: ${{ steps.metadata.outputs.plugin-id }} |
21 | 20 | plugin-version: ${{ steps.metadata.outputs.plugin-version }} |
22 | | - has-e2e: ${{ steps.check-for-e2e.outputs.has-e2e }} |
23 | | - has-backend: ${{ steps.check-for-backend.outputs.has-backend }} |
24 | 21 | env: |
25 | 22 | GRAFANA_ACCESS_POLICY_TOKEN: ${{ secrets.GRAFANA_ACCESS_POLICY_TOKEN }} |
26 | 23 | steps: |
27 | 24 | - uses: actions/checkout@v5 |
28 | 25 | with: |
29 | 26 | persist-credentials: false |
30 | | - - name: Setup Node.js environment |
31 | | - uses: actions/setup-node@v6 |
32 | | - with: |
33 | | - node-version: '22' |
34 | | - cache: 'npm' |
35 | | - |
36 | | - - name: Install dependencies |
37 | | - run: npm ci |
38 | | - |
39 | | - - name: Check types |
40 | | - run: npm run typecheck |
41 | | - - name: Lint |
42 | | - run: npm run lint |
43 | | - - name: Unit tests |
44 | | - run: npm run test:ci |
45 | | - - name: Build frontend |
46 | | - run: npm run build |
47 | | - |
48 | | - - name: Check for backend |
49 | | - id: check-for-backend |
50 | | - run: | |
51 | | - if [ -f "Magefile.go" ] |
52 | | - then |
53 | | - echo "has-backend=true" >> $GITHUB_OUTPUT |
54 | | - fi |
55 | | -
|
56 | | - - name: Setup Go environment |
57 | | - if: steps.check-for-backend.outputs.has-backend == 'true' |
58 | | - uses: actions/setup-go@v6 |
59 | | - with: |
60 | | - go-version: '1.22' |
61 | 27 |
|
62 | | - - name: Test backend |
63 | | - if: steps.check-for-backend.outputs.has-backend == 'true' |
64 | | - uses: magefile/mage-action@6f50bbb8ea47d56e62dee92392788acbc8192d0b # v3.1.0 |
| 28 | + - uses: actions/setup-node@v6 |
65 | 29 | with: |
66 | | - version: latest |
67 | | - args: coverage |
68 | | - |
69 | | - - name: Build backend |
70 | | - if: steps.check-for-backend.outputs.has-backend == 'true' |
71 | | - uses: magefile/mage-action@6f50bbb8ea47d56e62dee92392788acbc8192d0b # v3.1.0 |
72 | | - with: |
73 | | - version: latest |
74 | | - args: buildAll |
| 30 | + node-version: '20' |
| 31 | + cache: 'npm' |
75 | 32 |
|
76 | | - - name: Check for E2E |
77 | | - id: check-for-e2e |
78 | | - run: | |
79 | | - if [ -f "playwright.config.ts" ] |
80 | | - then |
81 | | - echo "has-e2e=true" >> $GITHUB_OUTPUT |
82 | | - fi |
| 33 | + - run: npm ci |
| 34 | + - run: npm run typecheck |
| 35 | + - run: npm run lint |
| 36 | + - run: npm run test:ci |
| 37 | + - run: npm run build |
83 | 38 |
|
84 | 39 | - name: Sign plugin |
85 | 40 | run: npm run sign |
86 | 41 | if: ${{ env.GRAFANA_ACCESS_POLICY_TOKEN != '' }} |
87 | 42 |
|
| 43 | + - name: Package plugin |
| 44 | + run: npm run package |
| 45 | + |
88 | 46 | - name: Get plugin metadata |
89 | 47 | id: metadata |
90 | 48 | run: | |
91 | | - sudo apt-get install jq |
92 | | -
|
93 | | - export GRAFANA_PLUGIN_ID=$(cat dist/plugin.json | jq -r .id) |
94 | | - export GRAFANA_PLUGIN_VERSION=$(cat dist/plugin.json | jq -r .info.version) |
95 | | - export GRAFANA_PLUGIN_ARTIFACT=${GRAFANA_PLUGIN_ID}-${GRAFANA_PLUGIN_VERSION}.zip |
96 | | -
|
97 | | - echo "plugin-id=${GRAFANA_PLUGIN_ID}" >> $GITHUB_OUTPUT |
98 | | - echo "plugin-version=${GRAFANA_PLUGIN_VERSION}" >> $GITHUB_OUTPUT |
99 | | - echo "archive=${GRAFANA_PLUGIN_ARTIFACT}" >> $GITHUB_OUTPUT |
100 | | -
|
101 | | - - name: Package plugin |
102 | | - id: package-plugin |
103 | | - run: | |
104 | | - mv dist ${PLUGIN_ID} |
105 | | - zip ${ARCHIVE} ${PLUGIN_ID} -r |
106 | | - env: |
107 | | - ARCHIVE: ${{ steps.metadata.outputs.archive }} |
108 | | - PLUGIN_ID: ${{ steps.metadata.outputs.plugin-id }} |
| 49 | + echo "plugin-id=$(node -p "require('./src/plugin.json').id")" >> $GITHUB_OUTPUT |
| 50 | + echo "plugin-version=$(node -p "require('./src/plugin.json').info.version")" >> $GITHUB_OUTPUT |
109 | 51 |
|
110 | | - - name: Check plugin.json |
| 52 | + - name: Validate plugin |
111 | 53 | run: | |
112 | 54 | docker run --pull=always \ |
113 | | - -v $PWD/${ARCHIVE}:/archive.zip \ |
| 55 | + -v $PWD/cybertec-pev-panel.zip:/archive.zip \ |
114 | 56 | grafana/plugin-validator-cli -analyzer=metadatavalid /archive.zip |
115 | | - env: |
116 | | - ARCHIVE: ${{ steps.metadata.outputs.archive }} |
117 | 57 |
|
118 | | - - name: Archive Build |
119 | | - uses: actions/upload-artifact@v5 |
| 58 | + - uses: actions/upload-artifact@v5 |
120 | 59 | with: |
121 | 60 | name: ${{ steps.metadata.outputs.plugin-id }}-${{ steps.metadata.outputs.plugin-version }} |
122 | | - path: ${{ steps.metadata.outputs.plugin-id }} |
| 61 | + path: cybertec-pev-panel.zip |
123 | 62 | retention-days: 5 |
124 | | - |
125 | | - resolve-versions: |
126 | | - name: Resolve e2e images |
127 | | - runs-on: ubuntu-latest |
128 | | - permissions: |
129 | | - contents: read |
130 | | - timeout-minutes: 3 |
131 | | - needs: build |
132 | | - if: ${{ needs.build.outputs.has-e2e == 'true' }} |
133 | | - outputs: |
134 | | - matrix: ${{ steps.resolve-versions.outputs.matrix }} |
135 | | - steps: |
136 | | - - name: Checkout |
137 | | - uses: actions/checkout@v5 |
138 | | - with: |
139 | | - persist-credentials: false |
140 | | - |
141 | | - - name: Resolve Grafana E2E versions |
142 | | - id: resolve-versions |
143 | | - uses: grafana/plugin-actions/e2e-version@e2e-version/v1.1.2 |
144 | | - |
145 | | - playwright-tests: |
146 | | - needs: [resolve-versions, build] |
147 | | - timeout-minutes: 15 |
148 | | - permissions: |
149 | | - contents: read |
150 | | - id-token: write |
151 | | - pull-requests: write |
152 | | - strategy: |
153 | | - fail-fast: false |
154 | | - matrix: |
155 | | - GRAFANA_IMAGE: ${{fromJson(needs.resolve-versions.outputs.matrix)}} |
156 | | - name: e2e test ${{ matrix.GRAFANA_IMAGE.name }}@${{ matrix.GRAFANA_IMAGE.VERSION }} |
157 | | - runs-on: ubuntu-latest |
158 | | - steps: |
159 | | - - uses: actions/checkout@v5 |
160 | | - with: |
161 | | - persist-credentials: false |
162 | | - |
163 | | - - name: Download plugin |
164 | | - uses: actions/download-artifact@v6 |
165 | | - with: |
166 | | - path: dist |
167 | | - name: ${{ needs.build.outputs.plugin-id }}-${{ needs.build.outputs.plugin-version }} |
168 | | - |
169 | | - - name: Execute permissions on binary |
170 | | - if: needs.build.outputs.has-backend == 'true' |
171 | | - run: | |
172 | | - chmod +x ./dist/gpx_* |
173 | | -
|
174 | | - - name: Setup Node.js environment |
175 | | - uses: actions/setup-node@v6 |
176 | | - with: |
177 | | - node-version: '22' |
178 | | - cache: 'npm' |
179 | | - |
180 | | - - name: Install dev dependencies |
181 | | - run: npm ci |
182 | | - |
183 | | - - name: Start Grafana |
184 | | - run: | |
185 | | - docker compose pull |
186 | | - ANONYMOUS_AUTH_ENABLED=false DEVELOPMENT=false GRAFANA_VERSION=${{ matrix.GRAFANA_IMAGE.VERSION }} GRAFANA_IMAGE=${{ matrix.GRAFANA_IMAGE.NAME }} docker compose up -d |
187 | | -
|
188 | | - - name: Wait for grafana server |
189 | | - uses: grafana/plugin-actions/wait-for-grafana@wait-for-grafana/v1.0.2 |
190 | | - with: |
191 | | - url: http://localhost:3000/login |
192 | | - |
193 | | - - name: Install Playwright Browsers |
194 | | - run: npm exec playwright install chromium --with-deps |
195 | | - |
196 | | - - name: Run Playwright tests |
197 | | - id: run-tests |
198 | | - run: npm run e2e |
199 | | - |
200 | | - - name: Upload e2e test summary |
201 | | - uses: grafana/plugin-actions/playwright-gh-pages/upload-report-artifacts@upload-report-artifacts/v1.0.1 |
202 | | - if: ${{ always() && !cancelled() }} |
203 | | - with: |
204 | | - upload-report: false |
205 | | - github-token: ${{ secrets.GITHUB_TOKEN }} |
206 | | - test-outcome: ${{ steps.run-tests.outcome }} |
207 | | - |
208 | | - - name: Docker logs |
209 | | - if: ${{ always() && steps.run-tests.outcome == 'failure' }} |
210 | | - run: | |
211 | | - docker logs cybertec-pev-panel >& grafana-server.log |
212 | | -
|
213 | | - - name: Stop grafana docker |
214 | | - run: docker compose down |
215 | | - |
216 | | - # Uncomment this step to upload the server log to Github artifacts. Remember Github artifacts are public on the Internet if the repository is public. |
217 | | - # - name: Upload server log |
218 | | - # uses: actions/upload-artifact@v4 |
219 | | - # if: ${{ always() && steps.run-tests.outcome == 'failure' }} |
220 | | - # with: |
221 | | - # name: ${{ matrix.GRAFANA_IMAGE.NAME }}-v${{ matrix.GRAFANA_IMAGE.VERSION }}-${{github.run_id}}-server-log |
222 | | - # path: grafana-server.log |
223 | | - # retention-days: 5 |
224 | | - |
225 | | - publish-report: |
226 | | - if: ${{ always() && !cancelled() }} |
227 | | - permissions: |
228 | | - contents: write |
229 | | - id-token: write |
230 | | - pull-requests: write |
231 | | - needs: [playwright-tests] |
232 | | - runs-on: ubuntu-latest |
233 | | - steps: |
234 | | - - uses: actions/checkout@v5 |
235 | | - with: |
236 | | - # required for playwright-gh-pages |
237 | | - persist-credentials: true |
238 | | - - name: Publish report |
239 | | - uses: grafana/plugin-actions/playwright-gh-pages/deploy-report-pages@deploy-report-pages/v1.0.1 |
240 | | - with: |
241 | | - github-token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments