Skip to content

Commit 86bfb73

Browse files
committed
fix(build): update out-of-date dependencies and documentation and also improve makefile
fix(build): improve makefile to run different kind of commands necessary to build the plugin locally fix(build): added typescript explicit dependency fix(build): upgraded grafana-plugin-sdk-go module fix(docs): add link to Grafana's how to publish plugin fix(docs): add summary to the readme fix(build): rename ci.yaml github action to validate-build.yaml to have a more precise meaning fix(build): switch from master branch to main branch in the worflow_dispatch
1 parent e7d9a6b commit 86bfb73

File tree

8 files changed

+3243
-2530
lines changed

8 files changed

+3243
-2530
lines changed

.github/workflows/release.yml

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ jobs:
1717
with:
1818
node-version: '14.x'
1919

20-
- name: Setup Go environment
21-
uses: actions/setup-go@v2
22-
with:
23-
go-version: '1.17'
24-
2520
- name: Get yarn cache directory path
2621
id: yarn-cache-dir-path
2722
run: echo "::set-output name=dir::$(yarn cache dir)"
@@ -34,6 +29,7 @@ jobs:
3429
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
3530
restore-keys: |
3631
${{ runner.os }}-yarn-
32+
3733
- name: Cache node_modules
3834
id: cache-node-modules
3935
uses: actions/cache@v2
@@ -42,11 +38,13 @@ jobs:
4238
key: ${{ runner.os }}-${{ matrix.node-version }}-nodemodules-${{ hashFiles('**/yarn.lock') }}
4339
restore-keys: |
4440
${{ runner.os }}-${{ matrix.node-version }}-nodemodules-
41+
4542
- name: Install dependencies
4643
run: yarn install --frozen-lockfile;
4744
if: |
4845
steps.cache-yarn-cache.outputs.cache-hit != 'true' ||
4946
steps.cache-node-modules.outputs.cache-hit != 'true'
47+
5048
- name: Build and test frontend
5149
run: yarn build
5250

@@ -57,18 +55,25 @@ jobs:
5755
then
5856
echo "::set-output name=has-backend::true"
5957
fi
58+
59+
- name: Setup Go environment
60+
if: steps.check-for-backend.outputs.has-backend == 'true'
61+
uses: actions/setup-go@v2
62+
with:
63+
go-version: '1.19'
64+
6065
- name: Test backend
6166
if: steps.check-for-backend.outputs.has-backend == 'true'
62-
uses: magefile/mage-action@v1
67+
uses: magefile/mage-action@v2
6368
with:
64-
version: latest
69+
version: v1.14.0
6570
args: coverage
6671

6772
- name: Build backend
6873
if: steps.check-for-backend.outputs.has-backend == 'true'
69-
uses: magefile/mage-action@v1
74+
uses: magefile/mage-action@v2
7075
with:
71-
version: latest
76+
version: v1.14.0
7277
args: buildAll
7378

7479
- name: Sign plugin
@@ -91,11 +96,13 @@ jobs:
9196
echo "::set-output name=archive::${GRAFANA_PLUGIN_ARTIFACT}"
9297
echo "::set-output name=archive-checksum::${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}"
9398
echo ::set-output name=github-tag::${GITHUB_REF#refs/*/}
99+
94100
- name: Read changelog
95101
id: changelog
96102
run: |
97103
awk '/^## / {s++} s == 1 {print}' CHANGELOG.md > release_notes.md
98104
echo "::set-output name=path::release_notes.md"
105+
99106
- name: Check package version
100107
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
101108

@@ -106,13 +113,15 @@ jobs:
106113
zip ${{ steps.metadata.outputs.archive }} ${{ steps.metadata.outputs.plugin-id }} -r
107114
md5sum ${{ steps.metadata.outputs.archive }} > ${{ steps.metadata.outputs.archive-checksum }}
108115
echo "::set-output name=checksum::$(cat ./${{ steps.metadata.outputs.archive-checksum }} | cut -d' ' -f1)"
116+
109117
- name: Lint plugin
110118
run: |
111119
git clone https://github.com/grafana/plugin-validator
112-
pushd ./plugin-validator/pkg/cmd/plugincheck
120+
pushd ./plugin-validator/pkg/cmd/plugincheck2
113121
go install
114122
popd
115-
plugincheck ${{ steps.metadata.outputs.archive }}
123+
plugincheck2 ${{ steps.metadata.outputs.archive }}
124+
116125
- name: Create release
117126
id: create_release
118127
uses: actions/create-release@v1
Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI
1+
name: validate-build
22

33
on:
44
workflow_dispatch:
@@ -7,7 +7,7 @@ on:
77
- develop
88
pull_request:
99
branches:
10-
- master
10+
- main
1111

1212
jobs:
1313
build:
@@ -57,19 +57,30 @@ jobs:
5757
if: steps.check-for-backend.outputs.has-backend == 'true'
5858
uses: actions/setup-go@v2
5959
with:
60-
go-version: '1.17'
60+
go-version: '1.19'
6161

6262
- name: Test backend
6363
if: steps.check-for-backend.outputs.has-backend == 'true'
64-
uses: magefile/mage-action@v1
64+
uses: magefile/mage-action@v2
6565
with:
66-
version: latest
66+
version: v1.14.0
6767
args: coverage
6868

6969
- name: Build backend
7070
if: steps.check-for-backend.outputs.has-backend == 'true'
71-
uses: magefile/mage-action@v1
71+
uses: magefile/mage-action@v2
7272
with:
73-
version: v1.12.1
73+
version: v1.14.0
7474
args: buildAll
75-
75+
76+
- name: Sign plugin
77+
run: yarn sign
78+
env:
79+
GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_KEY }} # Requires a Grafana API key from Grafana.com.
80+
81+
- name: Upload plugin artifacts
82+
uses: actions/upload-artifact@v3
83+
with:
84+
name: golioth-websocket-datasource
85+
path: ./dist
86+
retention-days: 1

CONTRIBUTING.md

Lines changed: 63 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
# <a name="commit"></a> Commit Message Format
1+
# What is Grafana Data Source Backend Plugin?
2+
3+
Grafana supports a wide range of data sources, including Prometheus, MySQL, and even Datadog. There’s a good chance you can already visualize metrics from the systems you have set up. In some cases, though, you already have an in-house metrics solution that you’d like to add to your Grafana dashboards. Grafana Data Source Plugins enables integrating such solutions with Grafana.
4+
5+
For more information about backend plugins, refer to the documentation on [Backend plugins](https://grafana.com/docs/grafana/latest/developers/plugins/backend/).
6+
7+
A backend data source plugin consists of both frontend and backend components.
8+
9+
In this case, the frontend is written in javascript and the backend is written in golang.
10+
11+
# Summary
12+
13+
- [Commits format](#commit)
14+
- [Building and running locally](#run-locally)
15+
- [Learn More related contents](#learn-more)
16+
17+
# <a name="commit" id="commit"></a> Commit Message Format
218

319
We have very precise rules over how our Git commit messages must be formatted.
420
This format leads to **easier to read commit history**.
@@ -89,7 +105,7 @@ Breaking Change section should start with the phrase "BREAKING CHANGE: " followe
89105

90106
Similarly, a Deprecation section should start with "DEPRECATED: " followed by a short description of what is deprecated, a blank line, and a detailed description of the deprecation that also mentions the recommended update path.
91107

92-
### Revert commits
108+
### <a name="revert-commit"></a>Revert commits
93109

94110
If the commit reverts a previous commit, it should begin with `revert: `, followed by the header of the reverted commit.
95111

@@ -98,19 +114,11 @@ The content of the commit message body should contain:
98114
- information about the SHA of the commit being reverted in the following format: `This reverts commit <SHA>`,
99115
- a clear description of the reason for reverting the commit message.
100116

101-
# Instructions for Building and Running Locally
102-
103-
This is a starting point for building Grafana Data Source Backend Plugins
104-
105-
## What is Grafana Data Source Backend Plugin?
106-
107-
Grafana supports a wide range of data sources, including Prometheus, MySQL, and even Datadog. There’s a good chance you can already visualize metrics from the systems you have set up. In some cases, though, you already have an in-house metrics solution that you’d like to add to your Grafana dashboards. Grafana Data Source Plugins enables integrating such solutions with Grafana.
108-
109-
For more information about backend plugins, refer to the documentation on [Backend plugins](https://grafana.com/docs/grafana/latest/developers/plugins/backend/).
117+
---
110118

111-
## Getting started
119+
# Instructions for Building and Running it Locally <a name="run-locally" id="run-locally"></a>
112120

113-
A data source backend plugin consists of both frontend and backend components.
121+
This is a starting point for building Grafana Data Source Backend Plugins
114122

115123
### Install Toolchain
116124

@@ -241,19 +249,43 @@ A data source backend plugin consists of both frontend and backend components.
241249
mage -l
242250
```
243251

244-
### Run the Grafana
252+
### Sign the Grafana plugin (Golioth Maintainers)
253+
254+
In case you have a Grafana API KEY, you can sign the plugin locally.
245255

246-
1. Start the docker container
256+
Set the GRAFANA_API_KEY:
257+
```
258+
$ export GRAFANA_API_KEY=<api-key-here>
259+
```
247260

261+
Sign the plugin:
262+
```
263+
$ npm run sign
264+
```
265+
266+
### Run the Grafana with Docker
267+
268+
1. Start the docker container:
269+
270+
- Run Grafana able to execute **unsigned** plugins
248271
```bash
249-
docker run \
272+
$ docker run \
250273
--network="host" -e "GF_LOG_MODE=console file" \
251274
-e "GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=golioth-websocket-datasource" \
252275
-p 3000:3000 \
253276
-v path/to/your/clone:/var/lib/grafana/plugins \
254277
--name=grafana grafana/grafana
255278
```
256279

280+
- Run Grafana only **for signed** plugins
281+
```bash
282+
$ docker run \
283+
--network="host" -e "GF_LOG_MODE=console file" \
284+
-p 3000:3000 \
285+
-v path/to/your/clone:/var/lib/grafana/plugins \
286+
--name=grafana grafana/grafana
287+
```
288+
257289
- Notes regarding Docker:
258290
- Restart container after first run: `docker start grafana`
259291
- Restart container after first run as daemon: `docker start grafana`
@@ -309,44 +341,36 @@ Every time you modify locally the plugin and desire send this change to be publi
309341
310342
For example, if you put some relative link in the README or some broken link, the validation will claim to you about them. And you'll need fix all of the claims before the submission.
311343

312-
To perform the local validation you must have the `Make` tool installed so that you can run the Makefile's commands and the Grafana's plugin validator `plugincheck` in order to your validate it.
313-
314-
In the root directory you can find a `Makefile` and it contains two commands:
344+
To perform the local validation you must have the `Make` tool installed so that you can run the Makefile's commands and the Grafana's [plugin validator](https://github.com/grafana/plugin-validator) `plugincheck` in order to your validate it.
315345

316-
- **setup**
346+
Or, you can skip installing the `plugincheck` locally and just run it through its binary using the `Node Package eXecute - npx command`. This tutorial will run the plugin validation using the `npx` command.
317347

318-
Run this command if you don't have installed yet the `plugincheck` tool in order to install it.
348+
In the root directory you can find a `Makefile` with the following commands:
319349

320350
- **validate-plugin**
321351

322-
Run this command after have installed the plugincheck. It will prepare and perform the plugin validation.
352+
Run this command in order to validate the plugin.
323353

324-
To run the commands go to the terminal and goes to the plugin's root directory:
354+
To run the command open the terminal and goes to the plugin's root directory:
325355
326356
```
327-
cd path/to/your/clone/grafana-websocket-plugin
357+
$ cd path/to/your/clone/grafana-websocket-plugin
328358
```
329359
330-
Next, install the plugin validator
360+
Run the validator:
331361
332362
```
333-
make setup
363+
$ make validate-plugin
334364
```
335365
336-
Finally, run the validator:
337-
338-
```
339-
make validate-plugin
340-
```
341-
342-
Case the validator realizes some error or warning in your plugin, it will generate in your terminal some kind of output like the following:
366+
Case the validator realizes any error or warning in your plugin, it will generate in your terminal some kind of output like the following:
343367
344368
```
345369
.
346370
.
347371
.
348372
349-
plugincheck ./golioth-websocket-datasource.zip || true
373+
$ plugincheck ./golioth-websocket-datasource.zip || true
350374
{
351375
"level": "error",
352376
"message": "Unsigned plugin",
@@ -359,10 +383,14 @@ plugincheck ./golioth-websocket-datasource.zip || true
359383
360384
You'll need verify each error or warning and solve them before pushing the plugin.
361385

362-
## Learn more
386+
387+
388+
# Learn more <a name="learn-more" id="learn-more"></a>
363389

364390
- [Build a data source backend plugin tutorial](https://grafana.com/tutorials/build-a-data-source-backend-plugin)
365391
- [Grafana documentation](https://grafana.com/docs/)
366392
- [Grafana Tutorials](https://grafana.com/tutorials/) - Grafana Tutorials are step-by-step guides that help you make the most of Grafana
367393
- [Grafana UI Library](https://developers.grafana.com/ui) - UI components to help you build interfaces using Grafana Design System
368394
- [Grafana plugin SDK for Go](https://grafana.com/docs/grafana/latest/developers/plugins/backend/grafana-plugin-sdk-for-go/)
395+
- [Grafana plugin-validator tool](https://github.com/grafana/plugin-validator)
396+
- [Grafana Publish Plugin](https://grafana.com/docs/grafana/latest/developers/plugins/publish-a-plugin/#submit-a-plugin-update)

Makefile

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
1-
setup:
2-
go get -u github.com/grafana/plugin-validator/cmd/plugincheck
1+
make clean-build:
2+
rm dist
3+
rm coverage
4+
rm node_modules
5+
6+
setup-frontend:
7+
yarn install
8+
9+
build-frontend:
10+
yarn build
11+
12+
install-mage:
13+
go install github.com/magefile/mage
14+
15+
setup-backend:
16+
go get -u github.com/grafana/grafana-plugin-sdk-go
17+
go mod tidy
18+
19+
build-backend:
20+
# build plugin's backend
21+
mage -v
22+
23+
# required by plugincheck
24+
chmod 0775 dist/gpx_websocket_*
25+
26+
sign-plugin:
27+
npm run sign
328

429
validate-plugin:
530
cp -r dist golioth-websocket-datasource
631
zip golioth-websocket-datasource golioth-websocket-datasource -r
7-
plugincheck ./golioth-websocket-datasource.zip || true
32+
npx -y @grafana/plugin-validator@latest ./golioth-websocket-datasource.zip || true
833
rm -r golioth-websocket-datasource
9-
rm golioth-websocket-datasource.zip
34+
rm golioth-websocket-datasource.zip

go.mod

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ module github.com/grafana/grafana-starter-datasource-backend
33
go 1.16
44

55
require (
6+
github.com/fatih/color v1.15.0 // indirect
7+
github.com/gopherjs/gopherjs v1.17.2 // indirect
68
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c
7-
github.com/grafana/grafana-plugin-sdk-go v0.142.0
8-
github.com/magefile/mage v1.14.0 // indirect
9+
github.com/grafana/grafana-plugin-sdk-go v0.159.0
10+
github.com/mattn/go-runewidth v0.0.14 // indirect
11+
github.com/rivo/uniseg v0.4.4 // indirect
12+
github.com/smartystreets/assertions v1.13.0 // indirect
13+
github.com/smartystreets/goconvey v1.7.2 // indirect
14+
golang.org/x/exp v0.0.0-20230310171629-522b1b587ee0 // indirect
15+
gonum.org/v1/gonum v0.12.0 // indirect
916
)

0 commit comments

Comments
 (0)