-
Notifications
You must be signed in to change notification settings - Fork 5
165 lines (138 loc) · 5.56 KB
/
build.yml
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
# Build current branch (or provided ref) with specific version tag and create build-frontend artifact
name: Build and test frontend
on:
workflow_call:
inputs:
ref:
required: false
type: string
description: commit sha or tag that will be checked out (use it if an existing tag needs to be checked-out)
e2e:
required: true
type: boolean
addSha:
required: true
type: boolean
description: whether to append commit sha to plugin version
jobs:
frontend:
name: Frontend build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'yarn'
- name: Install dependencies
run: yarn install --immutable
# lint
- name: Check TS types
run: yarn typecheck
- name: Lint
run: yarn lint
- name: Validate Pyroscope API client is commited
run: yarn run generate:pyroscope-api && git diff --quiet src/shared/pyroscope-api
- name: Unit tests
run: yarn test:ci
- name: Report test coverage
if: ${{ github.event_name == 'pull_request' }}
uses: MishaKav/jest-coverage-comment@v1.0.27
with:
title: Unit test coverage
- name: Get current commit SHA
id: get_sha
run: echo "commit_sha=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: Get current commit short SHA
run: echo "commit_short_sha=$(echo ${{ github.event.pull_request.head.sha || env.commit_sha }} | cut -c1-7)" >> $GITHUB_ENV
# Before building make sure we update the version so it's easy to identify it
# This needs to be done after unit tests because unit tests rely on 'dev' sha in some steps
# We need to get correct sha in the stop above in cases when we are building a tag as github.ref
# would point to a commit of main when the "Cut new release" workflow was called (i.e. before tagging)
# For PR however we need to use github.event.pull_request.head.sha because env.commit_sha would point
# to a commit for merge with main commit (branch is synced with main to check for conflicts)
# see also https://github.com/orgs/community/discussions/25318
- name: Update version.ts
run: echo "export const GIT_COMMIT = '${{ github.event.pull_request.head.sha || env.commit_sha }}';" > src/version.ts
- name: Append sha to plugin version
if: inputs.addSha == true
run: npm version --no-git-tag-version `jq -r '.version' package.json`-${{ env.commit_short_sha }}
- name: Build frontend
run: yarn build
- name: Check bundlesize
run: yarn run bundlewatch
- name: Compatibility check
run: npx @grafana/levitate@latest is-compatible --path src/module.ts --target @grafana/data,@grafana/ui,@grafana/runtime
# The plugin is signed here so it's possible to use the artifact produced by the job directly
# Forks are not allowed to get is signed so we skip this step (and job to upload the artifact)
# See also https://github.com/grafana/explore-profiles/issues/366)
- name: Setup plugin signing
if: ${{ !github.event.pull_request.head.repo.fork }}
uses: grafana/shared-workflows/actions/get-vault-secrets@main
with:
vault_instance: ops
common_secrets: |
SIGN_PLUGIN_ACCESS_POLICY_TOKEN=plugins/sign-plugin-access-policy-token:token
# create MANIFEST in dist
- name: Sign plugin
if: ${{ !github.event.pull_request.head.repo.fork }}
run: yarn sign
env:
GRAFANA_ACCESS_POLICY_TOKEN: ${{ env.SIGN_PLUGIN_ACCESS_POLICY_TOKEN }}
- uses: actions/upload-artifact@v4
if: always()
with:
name: build-frontend
path: dist
retention-days: 1
end-to-end:
name: E2E tests
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [frontend]
if: inputs.e2e == true
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'yarn'
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
pattern: build-*
merge-multiple: true
path: dist
# E2E tests
# switch to "npm run" in order to prevent "Usage Error: Couldn't find the node_modules state file - running an install might help (findPackageLocation)" when using yarn
- name: Start Grafana server
run: npm run e2e:ci:server:up
- name: Prepare e2e tests
run: npm run e2e:ci:prepare
# commented to save time during the build (building this action takes ~30s)
# the next step "Prepare e2e test" takes ~20s, which gives us the time needed
# uncomment it if you experience flakiness
# - uses: cygnetdigital/wait_for_response@v2.0.0
# with:
# url: 'http://localhost:3000/a/grafana-pyroscope-app/single'
# responseCode: '200'
# timeout: 20000
# interval: 500
- name: Launch e2e tests
run: npm run e2e:ci
- name: Stop Grafana server
run: npm run e2e:ci:server:down
- uses: actions/upload-artifact@v4
if: always()
with:
name: e2e-test-reports-and-results
path: |
e2e/test-reports
e2e/test-results
retention-days: 15