Skip to content

Commit

Permalink
build: update build process and workflows
Browse files Browse the repository at this point in the history
* add zip Makefile target
* run plugincheck in CI workflow
  • Loading branch information
andreasgerstmayr committed Nov 11, 2021
1 parent d4d3918 commit 9332942
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 31 deletions.
18 changes: 11 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2

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

- name: Build plugin
run: make dist
run: make build

- name: Create a zip file
run: |
mv dist performancecopilot-pcp-app
zip -r performancecopilot-pcp-app.zip performancecopilot-pcp-app
- name: Create plugin zip file
run: make zip

- name: Run linters
run: make lint
# ignore unsigned plugin error in CI
continue-on-error: true

- name: Publish build artifact
uses: actions/upload-artifact@v2
with:
name: build
path: performancecopilot-pcp-app.zip
path: build
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
e2e:
name: End-to-End tests
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
Expand Down
14 changes: 9 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@ on:
jobs:
release:
name: Publish Release
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Installing jsonnet, jsonnet-bundler and grafana/plugin-validator
- name: Install jsonnet, jsonnet-bundler and grafana/plugin-validator
run: |
go get github.com/google/go-jsonnet/cmd/jsonnet
go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
go get github.com/grafana/plugin-validator/cmd/plugincheck
echo "$HOME/go/bin" >> $GITHUB_PATH
env:
GO111MODULE: off
- name: Install dependencies
run: make deps
Expand All @@ -28,7 +26,7 @@ jobs:
run: make test-backend

- name: Test frontend & Build plugin
run: make dist
run: make build

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

- name: Create plugin zip file
run: make zip

- name: Run linters
run: make lint

- name: Create GitHub release
run: scripts/github-release.sh
env:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ vendor/
vendor_jsonnet/

dist/
build/

coverage/
coverage.out
31 changes: 23 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
default: help
JSONNET_VENDOR_DIR := vendor_jsonnet

GRAFANA_PLUGIN_ID := $(shell jq -r '.id' src/plugin.json)
GRAFANA_PLUGIN_VERSION := $(shell jq -r '.version' package.json)
GRAFANA_PLUGIN_ARTIFACT := $(GRAFANA_PLUGIN_ID)-$(GRAFANA_PLUGIN_VERSION).zip
GRAFANA_PLUGIN_ARTIFACT_CHECKSUM := $(GRAFANA_PLUGIN_ARTIFACT).md5


##@ Dependencies

$(JSONNET_VENDOR_DIR): jsonnetfile.json
$(JSONNET_VENDOR_DIR): jsonnetfile.json jsonnetfile.lock.json
jb --jsonnetpkg-home="$(JSONNET_VENDOR_DIR)" install

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

node_modules: package.json
node_modules: package.json yarn.lock
yarn install

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

watch-frontend: deps-frontend dist-dashboards ## Auto rebuilt frontend on file changes
watch-frontend: deps-frontend build-dashboards ## Auto rebuilt frontend on file changes
yarn run watch

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

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

dist-frontend: deps-frontend ## Build frontend datasources
build-frontend: deps-frontend ## Build frontend datasources
yarn run build

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

dist: dist-dashboards dist-frontend dist-backend ## Build everything
build: build-dashboards build-frontend build-backend ## Build everything

zip:
rm -rf build && mkdir build
cp -a dist "build/$(GRAFANA_PLUGIN_ID)"
cd build && zip -r "$(GRAFANA_PLUGIN_ARTIFACT)" "$(GRAFANA_PLUGIN_ID)"
cd build && md5sum "$(GRAFANA_PLUGIN_ARTIFACT)" > "$(GRAFANA_PLUGIN_ARTIFACT_CHECKSUM)"
rm -r "build/$(GRAFANA_PLUGIN_ID)"


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

lint: ## Run Grafana plugincheck on the plugin zip file
plugincheck build/*.zip

clean: ## Clean all artifacts
rm -rf node_modules "$(JSONNET_VENDOR_DIR)" dist
rm -rf node_modules "$(JSONNET_VENDOR_DIR)" dist build

help: ## Display this help
@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)
13 changes: 3 additions & 10 deletions scripts/github-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,19 @@ GRAFANA_PLUGIN_VERSION="$(jq -r '.info.version' dist/plugin.json)"
GRAFANA_PLUGIN_SHA="$(git rev-parse HEAD)"
GRAFANA_PLUGIN_ARTIFACT="${GRAFANA_PLUGIN_ID}-${GRAFANA_PLUGIN_VERSION}.zip"
GRAFANA_PLUGIN_ARTIFACT_CHECKSUM="${GRAFANA_PLUGIN_ARTIFACT}.md5"
GRAFANA_PLUGIN_CHECKSUM=$(cut -d' ' -f1 "build/${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}")

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

mv dist "${GRAFANA_PLUGIN_ID}"
zip -r "${GRAFANA_PLUGIN_ARTIFACT}" "${GRAFANA_PLUGIN_ID}"
md5sum "${GRAFANA_PLUGIN_ARTIFACT}" > "${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}"
GRAFANA_PLUGIN_CHECKSUM=$(cut -d' ' -f1 "${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}")

# grafana/plugin-validator
plugincheck "${GRAFANA_PLUGIN_ARTIFACT}"

hub release create \
-m "grafana-pcp v${GRAFANA_PLUGIN_VERSION}" \
-m "${RELEASE_NOTES}" \
-a "${GRAFANA_PLUGIN_ARTIFACT}" \
-a "${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}" \
-a "build/${GRAFANA_PLUGIN_ARTIFACT}" \
-a "build/${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}" \
$PRERELEASE_ARG \
"v${GRAFANA_PLUGIN_VERSION}"

Expand Down

0 comments on commit 9332942

Please sign in to comment.