Skip to content
This repository was archived by the owner on Apr 27, 2023. It is now read-only.

Commit bfc22de

Browse files
authored
pull code from main repo (#3)
* pull code from main repo
1 parent 26b1b30 commit bfc22de

28 files changed

+204
-15407
lines changed

.github/workflows/ci.yml

Lines changed: 76 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
name: CI
22

33
on:
4-
push:
5-
branches:
6-
- main
74
pull_request:
85
branches:
96
- main
@@ -14,14 +11,14 @@ jobs:
1411
- uses: actions/checkout@v2
1512

1613
- name: Setup Node.js environment
17-
uses: actions/setup-node@v2.1.2
14+
uses: actions/setup-node@v2
1815
with:
19-
node-version: "14.x"
16+
node-version: "14.17"
2017

2118
- name: Get yarn cache directory path
2219
id: yarn-cache-dir-path
2320
run: echo "::set-output name=dir::$(yarn cache dir)"
24-
21+
2522
- name: Cache yarn cache
2623
uses: actions/cache@v2
2724
id: cache-yarn-cache
@@ -30,7 +27,7 @@ jobs:
3027
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
3128
restore-keys: |
3229
${{ runner.os }}-yarn-
33-
30+
3431
- name: Cache node_modules
3532
id: cache-node-modules
3633
uses: actions/cache@v2
@@ -40,36 +37,85 @@ jobs:
4037
restore-keys: |
4138
${{ runner.os }}-${{ matrix.node-version }}-nodemodules-
4239
43-
- name: Install dependencies
44-
run: yarn install --frozen-lockfile
45-
46-
- name: Build and test frontend
40+
- name: Build plugin
4741
run: yarn build
4842

49-
- name: Check for backend
50-
id: check-for-backend
43+
- name: Sign plugin
5144
run: |
52-
if [ -f "Magefile.go" ]
53-
then
54-
echo "::set-output name=has-backend::true"
55-
fi
45+
# We only have a single dependency, grafana-toolkit
46+
# So we install next to where it's needed
47+
yarn
48+
yarn sign
49+
env:
50+
GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_KEY }} # Requires a Grafana API key from Grafana.com.
5651

52+
# We reuse the same tests from the other repo, after all, why not?
53+
# TODO: run other tests that are valid here
54+
# eg: checking README etc
55+
- name: Run grafana server
56+
run: docker-compose -f pyroscope/grafana-plugin/datasource/docker-compose.yml up -d
57+
- name: Run tests
58+
run: yarn --cwd pyroscope cy:datasource:ci
59+
env:
60+
CYPRESS_VIDEO: true
61+
CYPRESS_COMPARE_SNAPSHOTS: true
62+
- uses: actions/upload-artifact@v2
63+
if: always()
64+
with:
65+
name: cypress-screenshots
66+
path: pyroscope/cypress/screenshots
67+
- uses: actions/upload-artifact@v2
68+
if: always()
69+
with:
70+
name: cypress-videos
71+
path: pyroscope/cypress/videos
72+
- uses: actions/upload-artifact@v2
73+
if: always()
74+
with:
75+
name: cypress-snapshots
76+
# TODO: scope to only store screenshots that refer to grafana
77+
path: pyroscope/cypress/snapshots
78+
79+
# Setup the go environment, since the grafana plugin linter isn't distributed as a binary
5780
- name: Setup Go environment
5881
if: steps.check-for-backend.outputs.has-backend == 'true'
5982
uses: actions/setup-go@v2
6083
with:
61-
go-version: "1.15"
84+
go-version: "1.16"
6285

63-
- name: Test backend
64-
if: steps.check-for-backend.outputs.has-backend == 'true'
65-
uses: magefile/mage-action@v1
66-
with:
67-
version: latest
68-
args: coverage
86+
- name: Get plugin metadata
87+
id: metadata
88+
run: |
89+
sudo apt-get install jq
6990
70-
- name: Build backend
71-
if: steps.check-for-backend.outputs.has-backend == 'true'
72-
uses: magefile/mage-action@v1
73-
with:
74-
version: latest
75-
args: buildAll
91+
export GRAFANA_PLUGIN_ID=$(cat dist/plugin.json | jq -r .id)
92+
export GRAFANA_PLUGIN_VERSION=$(cat dist/plugin.json | jq -r .info.version)
93+
export GRAFANA_PLUGIN_TYPE=$(cat dist/plugin.json | jq -r .type)
94+
export GRAFANA_PLUGIN_ARTIFACT=${GRAFANA_PLUGIN_ID}-${GRAFANA_PLUGIN_VERSION}.zip
95+
export GRAFANA_PLUGIN_ARTIFACT_CHECKSUM=${GRAFANA_PLUGIN_ARTIFACT}.md5
96+
97+
echo "::set-output name=plugin-id::${GRAFANA_PLUGIN_ID}"
98+
echo "::set-output name=plugin-version::${GRAFANA_PLUGIN_VERSION}"
99+
echo "::set-output name=plugin-type::${GRAFANA_PLUGIN_TYPE}"
100+
echo "::set-output name=archive::${GRAFANA_PLUGIN_ARTIFACT}"
101+
echo "::set-output name=archive-checksum::${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}"
102+
103+
echo ::set-output name=github-tag::${GITHUB_REF#refs/*/}
104+
105+
- name: Package plugin
106+
id: package-plugin
107+
run: |
108+
mv dist ${{ steps.metadata.outputs.plugin-id }}
109+
zip ${{ steps.metadata.outputs.archive }} ${{ steps.metadata.outputs.plugin-id }} -r
110+
md5sum ${{ steps.metadata.outputs.archive }} > ${{ steps.metadata.outputs.archive-checksum }}
111+
echo "::set-output name=checksum::$(cat ./${{ steps.metadata.outputs.archive-checksum }} | cut -d' ' -f1)"
112+
113+
- name: Lint plugin
114+
run: |
115+
export PATH="$(go env GOPATH)/bin/:$PATH"
116+
117+
git clone https://github.com/grafana/plugin-validator
118+
pushd ./plugin-validator/pkg/cmd/plugincheck2
119+
go install
120+
popd
121+
plugincheck2 -config lint.config.yaml ${{ steps.metadata.outputs.archive }}

.github/workflows/release.yml

Lines changed: 69 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: Release
22

33
on:
44
push:
5-
tags:
6-
- "v*.*.*" # Run workflow on version tags, e.g. v1.0.0.
5+
branches:
6+
- main
77

88
jobs:
99
release:
@@ -13,19 +13,14 @@ jobs:
1313
- uses: actions/checkout@v2
1414

1515
- name: Setup Node.js environment
16-
uses: actions/setup-node@v2.1.2
16+
uses: actions/setup-node@v2
1717
with:
18-
node-version: "14.x"
19-
20-
- name: Setup Go environment
21-
uses: actions/setup-go@v2
22-
with:
23-
go-version: "1.15"
18+
node-version: "14.17"
2419

2520
- name: Get yarn cache directory path
2621
id: yarn-cache-dir-path
2722
run: echo "::set-output name=dir::$(yarn cache dir)"
28-
23+
2924
- name: Cache yarn cache
3025
uses: actions/cache@v2
3126
id: cache-yarn-cache
@@ -34,7 +29,7 @@ jobs:
3429
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
3530
restore-keys: |
3631
${{ runner.os }}-yarn-
37-
32+
3833
- name: Cache node_modules
3934
id: cache-node-modules
4035
uses: actions/cache@v2
@@ -44,41 +39,51 @@ jobs:
4439
restore-keys: |
4540
${{ runner.os }}-${{ matrix.node-version }}-nodemodules-
4641
47-
- name: Install dependencies
48-
run: yarn install --frozen-lockfile;
49-
if: |
50-
steps.cache-yarn-cache.outputs.cache-hit != 'true' ||
51-
steps.cache-node-modules.outputs.cache-hit != 'true'
52-
53-
- name: Build and test frontend
42+
- name: Build plugin
5443
run: yarn build
5544

56-
- name: Check for backend
57-
id: check-for-backend
45+
- name: Sign plugin
5846
run: |
59-
if [ -f "Magefile.go" ]
60-
then
61-
echo "::set-output name=has-backend::true"
62-
fi
47+
# We only have a single dependency, grafana-toolkit
48+
# So we install next to where it's needed
49+
yarn
50+
yarn sign
51+
env:
52+
GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_KEY }} # Requires a Grafana API key from Grafana.com.
6353

64-
- name: Test backend
65-
if: steps.check-for-backend.outputs.has-backend == 'true'
66-
uses: magefile/mage-action@v1
54+
# We reuse the same tests from the other repo, after all, why not?
55+
# TODO: run other tests that are valid here
56+
# eg: checking README etc
57+
- name: Run grafana server
58+
run: docker-compose -f pyroscope/grafana-plugin/datasource/docker-compose.yml up -d
59+
- name: Run tests
60+
run: yarn --cwd pyroscope cy:datasource:ci
61+
env:
62+
CYPRESS_VIDEO: true
63+
CYPRESS_COMPARE_SNAPSHOTS: true
64+
- uses: actions/upload-artifact@v2
65+
if: always()
66+
with:
67+
name: cypress-screenshots
68+
path: pyroscope/cypress/screenshots
69+
- uses: actions/upload-artifact@v2
70+
if: always()
6771
with:
68-
version: latest
69-
args: coverage
72+
name: cypress-videos
73+
path: pyroscope/cypress/videos
74+
- uses: actions/upload-artifact@v2
75+
if: always()
76+
with:
77+
name: cypress-snapshots
78+
# TODO: scope to only store screenshots that refer to grafana
79+
path: pyroscope/cypress/snapshots
7080

71-
- name: Build backend
81+
# Setup the go environment, since the grafana plugin linter isn't distributed as a binary
82+
- name: Setup Go environment
7283
if: steps.check-for-backend.outputs.has-backend == 'true'
73-
uses: magefile/mage-action@v1
84+
uses: actions/setup-go@v2
7485
with:
75-
version: latest
76-
args: buildAll
77-
78-
- name: Sign plugin
79-
run: yarn sign
80-
env:
81-
GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_KEY }} # Requires a Grafana API key from Grafana.com.
86+
go-version: "1.16"
8287

8388
- name: Get plugin metadata
8489
id: metadata
@@ -99,15 +104,6 @@ jobs:
99104
100105
echo ::set-output name=github-tag::${GITHUB_REF#refs/*/}
101106
102-
- name: Read changelog
103-
id: changelog
104-
run: |
105-
awk '/^## / {s++} s == 1 {print}' CHANGELOG.md > release_notes.md
106-
echo "::set-output name=path::release_notes.md"
107-
108-
- name: Check package version
109-
run: if [ "v${{ steps.metadata.outputs.plugin-version }}" != "${{ steps.metadata.outputs.github-tag }}" ]; then printf "\033[0;31mPlugin version doesn't match tag name\033[0m\n"; exit 1; fi
110-
111107
- name: Package plugin
112108
id: package-plugin
113109
run: |
@@ -125,15 +121,37 @@ jobs:
125121
go install
126122
popd
127123
plugincheck2 -config lint.config.yaml ${{ steps.metadata.outputs.archive }}
124+
# until here it's pretty much the same as ci.yml
125+
# TODO: share the code somehow
126+
127+
##########################
128+
# Release Specific Stuff #
129+
##########################
130+
- name: Read changelog
131+
id: changelog
132+
run: |
133+
awk '/^## / {s++} s == 1 {print}' CHANGELOG.md > release_notes.md
134+
echo "::set-output name=path::release_notes.md"
128135
136+
- name: Create tag
137+
uses: actions/github-script@v5
138+
with:
139+
script: |
140+
github.rest.git.createRef({
141+
owner: context.repo.owner,
142+
repo: context.repo.repo,
143+
ref: 'refs/tags/v${{ steps.metadata.outputs.plugin-version }}',
144+
sha: context.sha
145+
})
146+
129147
- name: Create release
130148
id: create_release
131149
uses: actions/create-release@v1
132150
env:
133151
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
134152
with:
135-
tag_name: ${{ github.ref }}
136-
release_name: Release ${{ github.ref }}
153+
tag_name: 'v${{ steps.metadata.outputs.plugin-version }}'
154+
release_name: Release ${{ steps.metadata.outputs.plugin-version }}
137155
body_path: ${{ steps.changelog.outputs.path }}
138156
draft: true
139157

@@ -161,6 +179,5 @@ jobs:
161179

162180
- name: Publish to Grafana.com
163181
run: |
164-
echo A draft release has been created for your plugin. Please review and publish it. Then submit your plugin to grafana.com/plugins by opening a PR to https://github.com/grafana/grafana-plugin-repository with the following entry:
165-
echo
166-
echo '{ "id": "${{ steps.metadata.outputs.plugin-id }}", "type": "${{ steps.metadata.outputs.plugin-type }}", "url": "https://github.com/${{ github.repository }}", "versions": [ { "version": "${{ steps.metadata.outputs.plugin-version }}", "commit": "${{ github.sha }}", "url": "https://github.com/${{ github.repository }}", "download": { "any": { "url": "https://github.com/${{ github.repository }}/releases/download/v${{ steps.metadata.outputs.plugin-version }}/${{ steps.metadata.outputs.archive }}", "md5": "${{ steps.package-plugin.outputs.checksum }}" } } } ] }' | jq .
182+
echo "A draft release has been created for your plugin. Please review and publish it."
183+
echo "To publish a new version, follow https://github.com/grafana/grafana-plugin-repository#maintain-your-plugin"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ e2e-results/
3131
# Editor
3232
.idea
3333

34+
pyroscope

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 1.1.1
4+
* Bug fixes and improvements
5+
36
## 1.1.0
47
* Support template variables
58

0 commit comments

Comments
 (0)