Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 8060bea

Browse files
authored
WIP: update build process (#352)
* update build process and sanitize * add docker-compose for testing Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com> * Update .github/workflows/release.yml
1 parent ed75477 commit 8060bea

46 files changed

Lines changed: 8624 additions & 9535 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
3+
*
4+
* In order to extend the configuration follow the steps in
5+
* https://grafana.github.io/plugin-tools/docs/advanced-configuration#extending-the-eslint-config
6+
*/
7+
{
8+
"extends": ["@grafana/eslint-config"],
9+
"ignorePatterns": ["src/libs/*.js"],
10+
"root": true,
11+
"rules": {
12+
"react/prop-types": "off"
13+
}
14+
}

.github/workflows/ci.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
pull_request:
9+
branches:
10+
- master
11+
- main
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Setup Node.js environment
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: '16'
23+
cache: 'yarn'
24+
- name: Install dependencies
25+
run: yarn install --immutable --prefer-offline
26+
27+
- name: Check types
28+
run: yarn typecheck
29+
- name: Lint
30+
run: yarn lint
31+
- name: Unit tests
32+
run: yarn test:ci
33+
- name: Build frontend
34+
run: yarn build
35+
36+
- name: E2E - Check for Frontend Tests
37+
id: check-for-e2e-frontend-tests
38+
run: |
39+
if [ -d "cypress" ]
40+
then
41+
echo "has-e2e-frontend-tests=true" >> $GITHUB_OUTPUT
42+
fi
43+
44+
- name: E2E - Start grafana docker
45+
if: steps.check-for-e2e-frontend-tests.outputs.has-e2e-frontend-tests == 'true'
46+
run: yarn server -d
47+
48+
- name: E2E - Run tests
49+
if: steps.check-for-e2e-frontend-tests.outputs.has-e2e-frontend-tests == 'true'
50+
run: yarn e2e
51+
52+
- name: E2E - Stop grafana docker
53+
if: steps.check-for-e2e-frontend-tests.outputs.has-e2e-frontend-tests == 'true'
54+
run: docker-compose down
55+
56+
- name: Check for backend
57+
id: check-for-backend
58+
run: |
59+
if [ -f "Magefile.go" ]
60+
then
61+
echo "has-backend=true" >> $GITHUB_OUTPUT
62+
fi
63+
64+
- name: Setup Go environment
65+
if: steps.check-for-backend.outputs.has-backend == 'true'
66+
uses: actions/setup-go@v3
67+
with:
68+
go-version: '1.20'
69+
70+
- name: Test backend
71+
if: steps.check-for-backend.outputs.has-backend == 'true'
72+
uses: magefile/mage-action@v1
73+
with:
74+
version: latest
75+
args: coverage
76+
77+
- name: Build backend
78+
if: steps.check-for-backend.outputs.has-backend == 'true'
79+
uses: magefile/mage-action@v1
80+
with:
81+
version: latest
82+
args: buildAll
83+
84+
- name: Code Climate - Check environment
85+
id: check-for-codeclimate
86+
env:
87+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
88+
run: |
89+
if [ ! -z $CC_TEST_REPORTER_ID ]
90+
then
91+
echo "has-codeclimate=true" >> $GITHUB_OUTPUT
92+
fi
93+
94+
- name: Code Climate - Run
95+
if: steps.check-for-codeclimate.outputs.has-codeclimate == 'true'
96+
run: |
97+
mkdir -p ccbin/
98+
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./ccbin/cc-test-reporter
99+
chmod +x ./ccbin/cc-test-reporter
100+
yarn global add jest jest-junit
101+
./ccbin/cc-test-reporter format-coverage -t lcov -o out/codeclimate.frontend.json coverage/lcov.info
102+
npx jest --ci --runInBand --reporters=default --reporters=jest-junit
103+
104+
- name: Code Climate - Upload
105+
if: steps.check-for-codeclimate.outputs.has-codeclimate == 'true'
106+
env:
107+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
108+
run: |
109+
./ccbin/cc-test-reporter sum-coverage out/codeclimate.*.json -d -p 1 -o out/codeclimate.total.json
110+
./ccbin/cc-test-reporter upload-coverage -i out/codeclimate.total.json

.github/workflows/release.yml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*' # Run workflow on version tags, e.g. v1.0.0.
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
env:
12+
GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_KEY }} # Requires a Grafana API key from Grafana.com.
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Setup Node.js environment
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: '16'
20+
cache: 'yarn'
21+
22+
- name: Setup Go environment
23+
uses: actions/setup-go@v3
24+
with:
25+
go-version: '1.20'
26+
27+
- name: Install dependencies
28+
run: yarn install --immutable --prefer-offline
29+
30+
- name: Build and test frontend
31+
run: yarn build
32+
33+
- name: Check for backend
34+
id: check-for-backend
35+
run: |
36+
if [ -f "Magefile.go" ]
37+
then
38+
echo "has-backend=true" >> $GITHUB_OUTPUT
39+
fi
40+
41+
- name: Test backend
42+
if: steps.check-for-backend.outputs.has-backend == 'true'
43+
uses: magefile/mage-action@v1
44+
with:
45+
version: latest
46+
args: coverage
47+
48+
- name: Build backend
49+
if: steps.check-for-backend.outputs.has-backend == 'true'
50+
uses: magefile/mage-action@v1
51+
with:
52+
version: latest
53+
args: buildAll
54+
55+
- name: Warn missing Grafana API key
56+
run: |
57+
echo Please generate a Grafana API key: https://grafana.com/docs/grafana/latest/developers/plugins/sign-a-plugin/#generate-an-api-key
58+
echo Once done please follow the instructions found here: https://github.com/${{github.repository}}/blob/main/README.md#using-github-actions-release-workflow
59+
if: ${{ env.GRAFANA_API_KEY == '' }}
60+
61+
- name: Sign plugin
62+
run: yarn sign
63+
if: ${{ env.GRAFANA_API_KEY != '' }}
64+
65+
- name: Get plugin metadata
66+
id: metadata
67+
run: |
68+
sudo apt-get install jq
69+
70+
export GRAFANA_PLUGIN_ID=$(cat dist/plugin.json | jq -r .id)
71+
export GRAFANA_PLUGIN_VERSION=$(cat dist/plugin.json | jq -r .info.version)
72+
export GRAFANA_PLUGIN_TYPE=$(cat dist/plugin.json | jq -r .type)
73+
export GRAFANA_PLUGIN_ARTIFACT=${GRAFANA_PLUGIN_ID}-${GRAFANA_PLUGIN_VERSION}.zip
74+
export GRAFANA_PLUGIN_ARTIFACT_CHECKSUM=${GRAFANA_PLUGIN_ARTIFACT}.md5
75+
76+
echo "plugin-id=${GRAFANA_PLUGIN_ID}" >> $GITHUB_OUTPUT
77+
echo "plugin-version=${GRAFANA_PLUGIN_VERSION}" >> $GITHUB_OUTPUT
78+
echo "plugin-type=${GRAFANA_PLUGIN_TYPE}" >> $GITHUB_OUTPUT
79+
echo "archive=${GRAFANA_PLUGIN_ARTIFACT}" >> $GITHUB_OUTPUT
80+
echo "archive-checksum=${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}" >> $GITHUB_OUTPUT
81+
82+
echo "github-tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
83+
84+
- name: Read changelog
85+
id: changelog
86+
run: |
87+
awk '/^## / {s++} s == 1 {print}' CHANGELOG.md > release_notes.md
88+
echo "path=release_notes.md" >> $GITHUB_OUTPUT
89+
90+
- name: Check package version
91+
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
92+
93+
- name: Package plugin
94+
id: package-plugin
95+
run: |
96+
mv dist ${{ steps.metadata.outputs.plugin-id }}
97+
zip ${{ steps.metadata.outputs.archive }} ${{ steps.metadata.outputs.plugin-id }} -r
98+
md5sum ${{ steps.metadata.outputs.archive }} > ${{ steps.metadata.outputs.archive-checksum }}
99+
echo "checksum=$(cat ./${{ steps.metadata.outputs.archive-checksum }} | cut -d' ' -f1)" >> $GITHUB_OUTPUT
100+
101+
- name: Validate plugin
102+
run: |
103+
git clone https://github.com/grafana/plugin-validator
104+
pushd ./plugin-validator/pkg/cmd/plugincheck2
105+
go install
106+
popd
107+
plugincheck2 -config ./plugin-validator/config/default.yaml ${{ steps.metadata.outputs.archive }}
108+
109+
- name: Create Github release
110+
uses: softprops/action-gh-release@v1
111+
with:
112+
draft: true
113+
generate_release_notes: true
114+
files: |
115+
./${{ steps.metadata.outputs.archive }}
116+
./${{ steps.metadata.outputs.archive-checksum }}
117+
body: |
118+
**This Github draft release has been created for your plugin.**
119+
120+
_Note: if this is the first release for your plugin please consult the [distributing-your-plugin section](https://github.com/$\{{github.repository}}/blob/main/README.md#distributing-your-plugin) of the README_
121+
122+
If you would like to submit this release to Grafana please consider the following steps:
123+
124+
- Check the Validate plugin step in the [release workflow](https://github.com/${{github.repository}}/commit/${{github.sha}}/checks/${{github.run_id}}) for any warnings that need attention
125+
- Navigate to https://grafana.com/auth/sign-in/ to sign into your account
126+
- Once logged in click **My Plugins** in the admin navigation
127+
- Click the **Submit Plugin** button
128+
- Fill in the Plugin Submission form:
129+
- Paste this [.zip asset link](https://github.com/${{ github.repository }}/releases/download/v${{ steps.metadata.outputs.plugin-version }}/${{ steps.metadata.outputs.archive }}) in the Plugin URL field
130+
- Paste this [.zip.md5 link](https://github.com/${{ github.repository }}/releases/download/v${{ steps.metadata.outputs.plugin-version }}/${{ steps.metadata.outputs.archive-checksum }}) in the MD5 field
131+
132+
Once done please remove these instructions and publish this release.

.prettierrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
...require('@grafana/toolkit/src/config/prettier.plugin.config.json'),
3+
};

CHANGELOG.md

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

4+
## v1.0.3
5+
6+
- Release for Grafana 6+ support
7+
- Updated build environment and packages for future releases
8+
49
## v1.0.1
510

611
- Release for Grafana 7.0 with plugin signing

docker-compose.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
version: '3.7'
2+
3+
services:
4+
grafana:
5+
container_name: 'grafana-worldmap-panel'
6+
image: grafana/grafana:9.3.6
7+
#image: grafana/grafana:9.2.7
8+
#image: grafana/grafana:8.0.7
9+
#image: grafana/grafana:7.5.13
10+
#image: grafana/grafana:6.7.6
11+
#image: grafana/grafana:6.6.2
12+
#image: grafana/grafana:6.5.3
13+
#image: grafana/grafana:6.4.5
14+
#image: grafana/grafana:6.3.7
15+
# fails for earlier builds
16+
#image: grafana/grafana:6.2.5
17+
#image: grafana/grafana:6.1.6
18+
#image: grafana/grafana:6.0.2
19+
#image: grafana/grafana:5.4.5
20+
ports:
21+
- 3000:3000/tcp
22+
volumes:
23+
- ./:/var/lib/grafana/plugins/grafana-worldmap-panel
24+
- ./provisioning:/etc/grafana/provisioning
25+
environment:
26+
- TERM=linux
27+
- GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=grafana-worldmap-panel

jest.config.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
module.exports = {
22
verbose: true,
3-
"globals": {
4-
"ts-jest": {
5-
"tsConfig": "tsconfig.jest.json"
6-
},
7-
},
3+
testEnvironment: 'jsdom',
4+
coveragePathIgnorePatterns: ['<rootDir>/src/libs/'],
85
"transform": {
96
"\\.ts$": "ts-jest"
107
},
@@ -17,6 +14,6 @@ module.exports = {
1714
"json"
1815
],
1916
"setupFiles": [
20-
"<rootDir>/test/setupTests.ts"
17+
"jest-canvas-mock"
2118
]
2219
};

package.json

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
{
22
"name": "worldmap-panel",
3-
"version": "1.0.1",
3+
"version": "1.0.4",
44
"description": "Worldmap Panel Plugin for Grafana",
55
"main": "src/module.js",
66
"scripts": {
7-
"build": "node --max-old-space-size=8192 ./node_modules/.bin/webpack --config webpack.config.prod.js",
8-
"dev": "webpack --mode development",
9-
"watch": "webpack --mode development --watch",
10-
"test": "jest --config jest.config.js"
7+
"build": "grafana-toolkit plugin:build",
8+
"dev": "grafana-toolkit plugin:dev",
9+
"watch": "grafana-toolkit plugin:dev --watch",
10+
"lint": "eslint --cache --ignore-path ./.gitignore --ext .js,.jsx,.ts,.tsx .",
11+
"lint:fix": "yarn lint --fix",
12+
"test": "grafana-toolkit plugin:test",
13+
"test:ci": "jest --passWithNoTests --maxWorkers 4",
14+
"ci-build": "grafana-toolkit plugin:ci-build",
15+
"typecheck": "tsc --noEmit",
16+
"sign": "npx --yes @grafana/sign-plugin@latest"
1117
},
1218
"keywords": [
1319
"worldmap",
@@ -18,35 +24,23 @@
1824
"author": "Grafana Labs",
1925
"license": "MIT",
2026
"devDependencies": {
21-
"@babel/core": "^7.1.6",
22-
"@babel/preset-env": "^7.1.6",
23-
"@grafana/toolkit": "next",
27+
"@grafana/eslint-config": "^5.1.0",
28+
"@grafana/toolkit": "8.5.22",
29+
"@jest/core": "26.6.3",
2430
"@types/grafana": "https://git@github.com/CorpGlory/types-grafana.git",
25-
"@types/jest": "^23.3.9",
26-
"@types/lodash": "^4.14.118",
31+
"@types/jest": "27.0.2",
32+
"@types/lodash": "^4.14.194",
2733
"@types/moment": "^2.13.0",
28-
"babel": "~6.5.1",
29-
"babel-core": "^6.26.3",
30-
"babel-jest": "^23.6.0",
31-
"babel-loader": "^8.0.4",
32-
"babel-preset-env": "^1.7.0",
33-
"clean-webpack-plugin": "^1.0.0",
34-
"copy-webpack-plugin": "^4.6.0",
35-
"css-loader": "^1.0.1",
36-
"file-loader": "^3.0.1",
37-
"jest": "^23.6.0",
38-
"jquery": "^3.3.1",
39-
"ng-annotate-webpack-plugin": "^0.3.0",
40-
"style-loader": "^0.23.1",
41-
"ts-jest": "^23.10.5",
42-
"ts-loader": "^5.3.0",
43-
"typescript": "^3.1.6",
44-
"uglifyjs-webpack-plugin": "^2.1.1",
45-
"webpack": "^4.26.0",
46-
"webpack-cli": "^3.1.2"
34+
"jest": "26.6.3",
35+
"jest-canvas-mock": "2.3.0",
36+
"jest-config": "^27.5.1",
37+
"jest-environment-jsdom": "26.6.2",
38+
"jquery": "3.6.4",
39+
"ts-jest": "26.4.4",
40+
"ts-loader": "^5.3.0"
4741
},
4842
"dependencies": {
49-
"lodash": "^4.17.11",
50-
"package.json": "^2.0.1"
43+
"lodash": "4.17.21",
44+
"pkg.json": "2.0.8"
5145
}
5246
}

0 commit comments

Comments
 (0)