Commit 4e521a84 by Stephanie Closson Committed by GitHub

Tweaks and comments for ci-improvements, stability, and readibility (#23658)

* Tweaks and comments for ci-improvements, stability, and readibility
- Made naming more obvious and intuitive
- CI supports grafana e2e plus more granular design
  (side effect that it takes slightly longer, but negligable)
- disable strict e2e errors through environment variable
- Added tools for linting and for building plugin-ci

* feedback from stevev - remove version. Causes problems
parent 336ab899
version: 2.1 version: 2.1
parameters:
ssh-fingerprint:
type: string
default: "dc:60:ab:c7:2d:8c:82:50:2a:2a:97:1a:c0:66:83:14"
aliases: aliases:
# Workflow filters # Workflow filters
- &filter-only-master - &filter-only-master
...@@ -10,23 +15,40 @@ aliases: ...@@ -10,23 +15,40 @@ aliases:
only: /^v[1-9]*[0-9]+\.[1-9]*[0-9]+\.x$/ only: /^v[1-9]*[0-9]+\.[1-9]*[0-9]+\.x$/
workflows: workflows:
version: 2
plugin_workflow: plugin_workflow:
jobs: jobs:
- compile_dependencies - yarn_install
- build_plugin: - build_docs:
requires: requires:
- compile_dependencies - yarn_install
- package_and_report: - build_frontend:
requires:
- yarn_install
- build_backend:
requires:
- yarn_install
- package:
requires:
- build_frontend
- build_backend
- build_docs
- provisioning:
requires: requires:
- build_plugin - build_frontend
- test_integration: - build_backend
- build_docs
- e2e_canary:
requires: requires:
- package_and_report - provisioning
- package
- report:
requires:
- package
- e2e_canary
- approve_release: - approve_release:
type: approval type: approval
requires: requires:
- test_integration - report
filters: *filter-only-release filters: *filter-only-release
- publish_github_release: - publish_github_release:
requires: requires:
...@@ -37,71 +59,111 @@ executors: ...@@ -37,71 +59,111 @@ executors:
default_exec: # declares a reusable executor default_exec: # declares a reusable executor
docker: docker:
- image: srclosson/grafana-plugin-ci-alpine:latest - image: srclosson/grafana-plugin-ci-alpine:latest
e2e_exec:
docker:
- image: srclosson/grafana-plugin-ci-e2e:latest
jobs: jobs:
compile_dependencies: yarn_install:
executor: default_exec executor: default_exec
steps: steps:
- checkout - checkout
- restore_cache: - restore_cache:
name: restore node_modules
keys: keys:
- build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }} - build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }}
- run: - run:
name: Install dependencies name: Install dependencies
command: | command: |
mkdir ci mkdir ci
[ -L ~/project/node_modules/.bin/grafana-toolkit ] || yarn install --frozen-lockfile [ -f ~/project/node_modules/.bin/grafana-toolkit ] || yarn install --frozen-lockfile
- save_cache: - save_cache:
name: save node_modules
paths: paths:
- ~/project/node_modules - ~/project/node_modules
key: build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }} key: build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }}
- save_cache:
build_plugin: name: save cypress cache
paths:
- ~/.cache/Cypress
key: cypress-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }}
build_docs:
executor: default_exec
steps:
- checkout
- restore_cache:
name: restore node_modules
keys:
- build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }}
- run:
name: Build docs
command: |
./node_modules/.bin/grafana-toolkit plugin:ci-docs
[ -d "dist" ] || circleci-agent step halt
- persist_to_workspace:
root: .
paths:
- dist
build_frontend:
executor: default_exec executor: default_exec
steps: steps:
- checkout - checkout
- restore_cache: - restore_cache:
name: restore node_modules
keys: keys:
- build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }} - build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }}
- run: - run:
name: Build and test frontend and docs name: Build and test frontend
command: | command: ./node_modules/.bin/grafana-toolkit plugin:ci-build
npx grafana-toolkit plugin:ci-docs - persist_to_workspace:
npx grafana-toolkit plugin:ci-build root: .
paths:
- dist
build_backend:
executor: default_exec
steps:
- checkout
- restore_cache:
name: restore node_modules
keys:
- build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }}
- run: - run:
name: Build and test Backend name: Exit if no backend
command: | command: |
if [ -f "Magefile.go" ]; then [ -f "Magefile.go" ] || circleci-agent step halt
mage -v buildAll
mage -v lint
mage -v coverage
fi
- run: - run:
name: Move results to ci folder name: Build backend
command: | command: mage -v buildAll
npx grafana-toolkit plugin:ci-build --finish - run:
name: Test backend
command: |
mage -v lint
mage -v coverage
- persist_to_workspace: - persist_to_workspace:
root: . root: .
paths: paths:
- ci - dist
package_and_report: package:
executor: default_exec executor: default_exec
steps: steps:
- checkout - checkout
- restore_cache: - restore_cache:
name: restore node_modules
keys: keys:
- build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }} - build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }}
- attach_workspace: - attach_workspace:
at: . at: .
- run: - run:
name: Package distribution name: Move results to ci folder
command: | command: ./node_modules/.bin/grafana-toolkit plugin:ci-build --finish
npx grafana-toolkit plugin:ci-package
- run: - run:
name: Toolkit report name: Package distribution
command: | command: |
npx grafana-toolkit plugin:ci-report ./node_modules/.bin/grafana-toolkit plugin:ci-package
- persist_to_workspace: - persist_to_workspace:
root: . root: .
paths: paths:
...@@ -112,44 +174,100 @@ jobs: ...@@ -112,44 +174,100 @@ jobs:
- store_artifacts: - store_artifacts:
path: ci path: ci
test_integration: provisioning:
executor: default_exec executor: default_exec
steps: steps:
- checkout - checkout
- add_ssh_keys:
fingerprints:
- << pipeline.parameters.ssh-fingerprint >>
- run:
name: Checkout provisioning files
command: git clone git@github.com:grafana/plugin-provisioning.git
- run:
name: Prepare task output dir
command: |
mkdir ci # Avoid error if not exists
mkdir ci/jobs # Avoid error if not exists
mkdir ci/jobs/provisioning
mv plugin-provisioning/plugins/google-sheets/provisioning/* ci/jobs/provisioning
- persist_to_workspace:
root: .
paths:
- ci/jobs/provisioning
e2e_canary:
executor: e2e_exec
steps:
- checkout
- attach_workspace: - attach_workspace:
at: . at: .
- restore_cache: - restore_cache:
name: Restore node_modules
keys: keys:
- build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }} - build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }}
- restore_cache:
name: Restore cypress cache
keys:
- cypress-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }}
- run:
name: Exit if no e2e tests configured
command: |
[ -d cypress ] || circleci-agent step halt
- run: - run:
name: Setup Grafana (local install) name: Setup Grafana (local install)
command: | command: |
ginstall latest ginstall canary
/opt/grafana/bin/grafana-server -config ci/grafana-test-env/custom.ini -homepath /opt/grafana & /opt/grafana/bin/grafana-server -config ci/grafana-test-env/custom.ini -homepath /opt/grafana &
## To make sure grafana has started up
while ! $(netstat -tulpn | grep 3000 >/dev/null 2>&1); do sleep 1; done
/opt/grafana/bin/grafana-cli --version /opt/grafana/bin/grafana-cli --version
- run:
name: Copy provisioning files
command: cp -r ci/jobs/provisioning provisioning/
- run: - run:
name: Run e2e tests name: Run e2e tests
command: | command: |
[ -d cypress ] && npx grafana-e2e run || echo "skipping e2e" # If the tests fail, but GRAFANACI_STRICT_E2E=0, don't worry about it
./node_modules/.bin/grafana-e2e run \
|| (
[ "$GRAFANACI_STRICT_E2E" -eq 0 ] && echo "Bypassing fail. ci-nostrict enabled"
)
- run: - run:
when: always
name: Prepare task output dir name: Prepare task output dir
command: | command: |
# TODO: probably move all of this to `@grafana/toolkit plugin:ci-test` # TODO: probably move all of this to `@grafana/toolkit plugin:ci-test`
mkdir -m 0755 -p ci/jobs/test_integration mkdir ci/jobs/e2e_canary
# only copy if they exist # only copy if they exist
if [ -d cypress ]; then cp cypress/screenshots/*.* ci/jobs/e2e_canary 2>/dev/null || :
[ -d cypress/screenshots ] && cp cypress/screenshots/ ci/jobs/test_integration cp cypress/videos/*.* ci/jobs/e2e_canary 2>/dev/null || :
[ -d cypress/videos ] && cp cypress/videos/ ci/jobs/test_integration
fi
- persist_to_workspace: - persist_to_workspace:
root: . root: .
paths: paths:
- ci/jobs/test_integration - ci/jobs/e2e_canary
- store_test_results: - store_test_results:
path: ci/jobs/test_integration path: ci/jobs/e2e_canary
- store_artifacts: - store_artifacts:
path: ci/jobs/test_integration path: ci/jobs/e2e_canary
report:
executor: default_exec
steps:
- checkout
- attach_workspace:
at: .
- restore_cache:
name: restore node_modules
keys:
- build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }}
- run:
name: Toolkit report
command: |
./node_modules/.bin/grafana-toolkit plugin:ci-report
- store_artifacts:
path: ci
publish_github_release: publish_github_release:
executor: default_exec executor: default_exec
...@@ -161,10 +279,11 @@ jobs: ...@@ -161,10 +279,11 @@ jobs:
- attach_workspace: - attach_workspace:
at: . at: .
- restore_cache: - restore_cache:
name: restore node_modules
keys: keys:
- build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }} - build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }}
- run: - run:
name: "Publish Release on GitHub" name: "Publish Release on GitHub"
command: | command: |
npx grafana-toolkit plugin:github-publish ./node_modules/.bin/grafana-toolkit plugin:github-publish
...@@ -36,3 +36,17 @@ untar_file () { ...@@ -36,3 +36,17 @@ untar_file () {
tar -C "$dest" -xf "$src" && /bin/rm -rf "$src" tar -C "$dest" -xf "$src" && /bin/rm -rf "$src"
} }
##
# WIP: Just started this and not finished.
# The intent it to download a release from a git repo,
# compile, and install
get_latest_release () {
tarsrc=$(curl -sL "https://api.github.com/repos/$1/$2/releases/latest" | jq ".tarball_url" | tr -d '"')
wget -O /tmp/autoretrieved.tar.gz "$tarsrc"
origdir=$PWD
reponame=$(tar zxvf autoretrieved.tar.gz | tail -1 | awk -F / '{print $1}')
cd "/tmp/$reponame"
#perform compile
cd $origdir
}
...@@ -47,6 +47,19 @@ mkdir -pv /tmp/mage $HOME/go/bin ...@@ -47,6 +47,19 @@ mkdir -pv /tmp/mage $HOME/go/bin
git clone https://github.com/magefile/mage.git /tmp/mage git clone https://github.com/magefile/mage.git /tmp/mage
cd /tmp/mage && go run bootstrap.go cd /tmp/mage && go run bootstrap.go
mv $HOME/go/bin/mage /usr/local/bin mv $HOME/go/bin/mage /usr/local/bin
wget -O - -q https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b /usr/local/bin v2.2.0
source "/etc/profile"
sh -l -c "go get -u github.com/mgechev/revive"
for file in $(ls $HOME/go/bin); do
mv -v $HOME/go/bin/$file /usr/local/bin/$file
done
ls -l /usr/local/bin
revive --help
file /usr/local/bin/revive
# Cleanup after yourself # Cleanup after yourself
/bin/rm -rf /tmp/mage /bin/rm -rf /tmp/mage
/bin/rm -rf $HOME/go /bin/rm -rf $HOME/go
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment