Skip to content

Commit 9332942

Browse files
build: update build process and workflows
* add zip Makefile target * run plugincheck in CI workflow
1 parent d4d3918 commit 9332942

File tree

6 files changed

+48
-31
lines changed

6 files changed

+48
-31
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ jobs:
1515
- name: Checkout sources
1616
uses: actions/checkout@v2
1717

18-
- name: Installing jsonnet and jsonnet-bundler
18+
- name: Install jsonnet, jsonnet-bundler and grafana/plugin-validator
1919
run: |
2020
go get github.com/google/go-jsonnet/cmd/jsonnet
2121
go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
22+
go get github.com/grafana/plugin-validator/cmd/plugincheck
2223
echo "$HOME/go/bin" >> $GITHUB_PATH
2324
2425
- name: Install dependencies
@@ -28,15 +29,18 @@ jobs:
2829
run: make test-frontend-coverage test-backend-coverage
2930

3031
- name: Build plugin
31-
run: make dist
32+
run: make build
3233

33-
- name: Create a zip file
34-
run: |
35-
mv dist performancecopilot-pcp-app
36-
zip -r performancecopilot-pcp-app.zip performancecopilot-pcp-app
34+
- name: Create plugin zip file
35+
run: make zip
36+
37+
- name: Run linters
38+
run: make lint
39+
# ignore unsigned plugin error in CI
40+
continue-on-error: true
3741

3842
- name: Publish build artifact
3943
uses: actions/upload-artifact@v2
4044
with:
4145
name: build
42-
path: performancecopilot-pcp-app.zip
46+
path: build

.github/workflows/e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
jobs:
1111
e2e:
1212
name: End-to-End tests
13-
runs-on: ubuntu-20.04
13+
runs-on: ubuntu-latest
1414
steps:
1515
- name: Checkout sources
1616
uses: actions/checkout@v2

.github/workflows/release.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ on:
77
jobs:
88
release:
99
name: Publish Release
10-
runs-on: ubuntu-20.04
10+
runs-on: ubuntu-latest
1111
steps:
1212
- name: Checkout sources
1313
uses: actions/checkout@v2
1414

15-
- name: Installing jsonnet, jsonnet-bundler and grafana/plugin-validator
15+
- name: Install jsonnet, jsonnet-bundler and grafana/plugin-validator
1616
run: |
1717
go get github.com/google/go-jsonnet/cmd/jsonnet
1818
go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
1919
go get github.com/grafana/plugin-validator/cmd/plugincheck
2020
echo "$HOME/go/bin" >> $GITHUB_PATH
21-
env:
22-
GO111MODULE: off
2321
2422
- name: Install dependencies
2523
run: make deps
@@ -28,7 +26,7 @@ jobs:
2826
run: make test-backend
2927

3028
- name: Test frontend & Build plugin
31-
run: make dist
29+
run: make build
3230

3331
- name: Check if package version and git tag matches
3432
run: |
@@ -42,6 +40,12 @@ jobs:
4240
env:
4341
GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_KEY }}
4442

43+
- name: Create plugin zip file
44+
run: make zip
45+
46+
- name: Run linters
47+
run: make lint
48+
4549
- name: Create GitHub release
4650
run: scripts/github-release.sh
4751
env:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ vendor/
44
vendor_jsonnet/
55

66
dist/
7+
build/
78

89
coverage/
910
coverage.out

Makefile

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22
default: help
33
JSONNET_VENDOR_DIR := vendor_jsonnet
44

5+
GRAFANA_PLUGIN_ID := $(shell jq -r '.id' src/plugin.json)
6+
GRAFANA_PLUGIN_VERSION := $(shell jq -r '.version' package.json)
7+
GRAFANA_PLUGIN_ARTIFACT := $(GRAFANA_PLUGIN_ID)-$(GRAFANA_PLUGIN_VERSION).zip
8+
GRAFANA_PLUGIN_ARTIFACT_CHECKSUM := $(GRAFANA_PLUGIN_ARTIFACT).md5
9+
510

611
##@ Dependencies
712

8-
$(JSONNET_VENDOR_DIR): jsonnetfile.json
13+
$(JSONNET_VENDOR_DIR): jsonnetfile.json jsonnetfile.lock.json
914
jb --jsonnetpkg-home="$(JSONNET_VENDOR_DIR)" install
1015

1116
deps-dashboards: $(JSONNET_VENDOR_DIR) ## Install jsonnet dependencies
1217

13-
node_modules: package.json
18+
node_modules: package.json yarn.lock
1419
yarn install
1520

1621
deps-frontend: node_modules ## Install Node.js dependencies
@@ -26,7 +31,7 @@ deps: deps-dashboards deps-frontend deps-backend ## Install all dependencies
2631
dev-frontend: deps-frontend ## Build frontend datasources (development)
2732
yarn run dev
2833

29-
watch-frontend: deps-frontend dist-dashboards ## Auto rebuilt frontend on file changes
34+
watch-frontend: deps-frontend build-dashboards ## Auto rebuilt frontend on file changes
3035
yarn run watch
3136

3237
dev-backend: deps-backend
@@ -43,21 +48,28 @@ dist/%.json: src/%.jsonnet $(JSONNET_VENDOR_DIR)
4348
mkdir -p $(dir $@)
4449
jsonnet -J "$(JSONNET_VENDOR_DIR)" -o $@ $<
4550

46-
dist-dashboards: $(shell find src -name '*.jsonnet' | sed -E 's@src/(.*)\.jsonnet@dist/\1.json@g') ## Build Grafana dashboards from jsonnet
51+
build-dashboards: $(shell find src -name '*.jsonnet' | sed -E 's@src/(.+)\.jsonnet@dist/\1.json@g') ## Build Grafana dashboards from jsonnet
4752

48-
dist-frontend: deps-frontend ## Build frontend datasources
53+
build-frontend: deps-frontend ## Build frontend datasources
4954
yarn run build
5055

5156
GO_LD_FLAGS := -w -s -extldflags "-static"
52-
dist-backend: deps-backend ## Build backend datasource
57+
build-backend: deps-backend ## Build backend datasource
5358
#mage buildAll
5459
for arch in amd64 arm arm64 s390x ppc64le 386; do \
5560
CGO_ENABLED=0 GOOS=linux GOARCH=$${arch} go build -o dist/datasources/redis/pcp_redis_datasource_linux_$${arch} -ldflags '$(GO_LD_FLAGS)' ./pkg; \
5661
done
5762
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o dist/datasources/redis/pcp_redis_datasource_darwin_amd64 -ldflags '$(GO_LD_FLAGS)' ./pkg
5863
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o dist/datasources/redis/pcp_redis_datasource_windows_amd64.exe -ldflags '$(GO_LD_FLAGS)' ./pkg
5964

60-
dist: dist-dashboards dist-frontend dist-backend ## Build everything
65+
build: build-dashboards build-frontend build-backend ## Build everything
66+
67+
zip:
68+
rm -rf build && mkdir build
69+
cp -a dist "build/$(GRAFANA_PLUGIN_ID)"
70+
cd build && zip -r "$(GRAFANA_PLUGIN_ARTIFACT)" "$(GRAFANA_PLUGIN_ID)"
71+
cd build && md5sum "$(GRAFANA_PLUGIN_ARTIFACT)" > "$(GRAFANA_PLUGIN_ARTIFACT_CHECKSUM)"
72+
rm -r "build/$(GRAFANA_PLUGIN_ID)"
6173

6274

6375
##@ Test
@@ -105,8 +117,11 @@ sign: ## Sign the plugin
105117
jsonnetfmt: ## Run jsonnetfmt on all jsonnet files
106118
jsonnetfmt -i $$(find . -name '*.jsonnet')
107119

120+
lint: ## Run Grafana plugincheck on the plugin zip file
121+
plugincheck build/*.zip
122+
108123
clean: ## Clean all artifacts
109-
rm -rf node_modules "$(JSONNET_VENDOR_DIR)" dist
124+
rm -rf node_modules "$(JSONNET_VENDOR_DIR)" dist build
110125

111126
help: ## Display this help
112127
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-16s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

scripts/github-release.sh

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,19 @@ GRAFANA_PLUGIN_VERSION="$(jq -r '.info.version' dist/plugin.json)"
1111
GRAFANA_PLUGIN_SHA="$(git rev-parse HEAD)"
1212
GRAFANA_PLUGIN_ARTIFACT="${GRAFANA_PLUGIN_ID}-${GRAFANA_PLUGIN_VERSION}.zip"
1313
GRAFANA_PLUGIN_ARTIFACT_CHECKSUM="${GRAFANA_PLUGIN_ARTIFACT}.md5"
14+
GRAFANA_PLUGIN_CHECKSUM=$(cut -d' ' -f1 "build/${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}")
1415

1516
RELEASE_NOTES=$(awk '/^## / {s++} s == 1 {print}' CHANGELOG.md)
1617
PRERELEASE_ARG=""
1718
if [[ "${GRAFANA_PLUGIN_VERSION}" == *beta* ]]; then
1819
PRERELEASE_ARG="-p"
1920
fi
2021

21-
mv dist "${GRAFANA_PLUGIN_ID}"
22-
zip -r "${GRAFANA_PLUGIN_ARTIFACT}" "${GRAFANA_PLUGIN_ID}"
23-
md5sum "${GRAFANA_PLUGIN_ARTIFACT}" > "${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}"
24-
GRAFANA_PLUGIN_CHECKSUM=$(cut -d' ' -f1 "${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}")
25-
26-
# grafana/plugin-validator
27-
plugincheck "${GRAFANA_PLUGIN_ARTIFACT}"
28-
2922
hub release create \
3023
-m "grafana-pcp v${GRAFANA_PLUGIN_VERSION}" \
3124
-m "${RELEASE_NOTES}" \
32-
-a "${GRAFANA_PLUGIN_ARTIFACT}" \
33-
-a "${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}" \
25+
-a "build/${GRAFANA_PLUGIN_ARTIFACT}" \
26+
-a "build/${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}" \
3427
$PRERELEASE_ARG \
3528
"v${GRAFANA_PLUGIN_VERSION}"
3629

0 commit comments

Comments
 (0)