|
1 |
| -version: 2 # use CircleCI 2.0 |
| 1 | +version: 2.1 |
2 | 2 |
|
3 |
| -jobs: # a collection of steps |
4 |
| - build: # runs not using Workflows must have a `build` job as entry point |
5 |
| - working_directory: ~/worldmap-panel # directory where steps will run |
6 |
| - docker: # run the steps with Docker |
7 |
| - - image: circleci/node:latest |
8 |
| - steps: |
9 |
| - - checkout |
10 |
| - - restore_cache: |
11 |
| - name: Restore Yarn Package Cache |
12 |
| - keys: |
13 |
| - - yarn-packages-{{ checksum "yarn.lock" }} |
14 |
| - - run: |
15 |
| - name: Install Dependencies |
16 |
| - command: yarn install --frozen-lockfile |
17 |
| - - save_cache: |
18 |
| - name: Save Yarn Package Cache |
19 |
| - key: yarn-packages-{{ checksum "yarn.lock" }} |
20 |
| - paths: |
21 |
| - - ~/.cache/yarn |
22 |
| - - run: # run tests |
23 |
| - name: test |
24 |
| - command: yarn test |
| 3 | +parameters: |
| 4 | + ssh-fingerprint: |
| 5 | + type: string |
| 6 | + default: ${GITHUB_SSH_FINGERPRINT} |
| 7 | + |
| 8 | +aliases: |
| 9 | + # Workflow filters |
| 10 | + - &filter-only-master |
| 11 | + branches: |
| 12 | + only: master |
| 13 | + - &filter-only-release |
| 14 | + branches: |
| 15 | + only: /^v[1-9]*[0-9]+\.[1-9]*[0-9]+\.x$/ |
| 16 | + |
| 17 | +workflows: |
| 18 | + plugin_workflow: |
| 19 | + jobs: |
| 20 | + - build |
| 21 | + - report: |
| 22 | + requires: |
| 23 | + - build |
| 24 | + - approve_release: |
| 25 | + type: approval |
| 26 | + requires: |
| 27 | + - report |
| 28 | + filters: *filter-only-release |
| 29 | + - publish_github_release: |
| 30 | + requires: |
| 31 | + - approve_release |
| 32 | + filters: *filter-only-release |
| 33 | + |
| 34 | +executors: |
| 35 | + default_exec: # declares a reusable executor |
| 36 | + docker: |
| 37 | + - image: srclosson/grafana-plugin-ci-alpine:latest |
| 38 | + e2e_exec: |
| 39 | + docker: |
| 40 | + - image: srclosson/grafana-plugin-ci-e2e:latest |
| 41 | + |
| 42 | +jobs: |
| 43 | + build: |
| 44 | + executor: default_exec |
| 45 | + steps: |
| 46 | + - checkout |
| 47 | + - restore_cache: |
| 48 | + name: restore node_modules |
| 49 | + keys: |
| 50 | + - build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }} |
| 51 | + - run: |
| 52 | + name: Install dependencies |
| 53 | + command: | |
| 54 | + mkdir ci |
| 55 | + [ -f ~/project/node_modules/.bin/grafana-toolkit ] || yarn install --frozen-lockfile |
| 56 | + - save_cache: |
| 57 | + name: save node_modules |
| 58 | + paths: |
| 59 | + - ~/project/node_modules |
| 60 | + key: build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }} |
| 61 | + - save_cache: |
| 62 | + name: save cypress cache |
| 63 | + paths: |
| 64 | + - ~/.cache/Cypress |
| 65 | + key: cypress-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }} |
| 66 | + - run: |
| 67 | + name: Build and test panel |
| 68 | + command: | |
| 69 | + sed -e "s/%VERSION%/$(cat package.json | jq .version | tr -d '\"')/" -e "s/%TODAY%/$(date)/" ./src/plugin.json.tmpl > ./src/plugin.json |
| 70 | + yarn build |
| 71 | + - run: |
| 72 | + name: Move results to ci folder |
| 73 | + command: | |
| 74 | + # Update the plugin.json with up to date info |
| 75 | + mkdir -pv ci/job/build_plugin |
| 76 | + mkdir -pv ci/packages |
| 77 | + mkdir -pv ci/jobs/package |
| 78 | + mkdir -pv ci/grafana-test-env |
| 79 | + cp -rv dist ci/job/build_plugin |
| 80 | + - run: |
| 81 | + name: Package distribution |
| 82 | + command: | |
| 83 | + ./node_modules/.bin/grafana-toolkit plugin:ci-package |
| 84 | + - persist_to_workspace: |
| 85 | + root: . |
| 86 | + paths: |
| 87 | + - ci/jobs/package |
| 88 | + - ci/packages |
| 89 | + - ci/dist |
| 90 | + - ci/grafana-test-env |
| 91 | + - store_artifacts: |
| 92 | + path: ci |
| 93 | + |
| 94 | + report: |
| 95 | + executor: default_exec |
| 96 | + steps: |
| 97 | + - checkout |
| 98 | + - attach_workspace: |
| 99 | + at: . |
| 100 | + - restore_cache: |
| 101 | + name: restore node_modules |
| 102 | + keys: |
| 103 | + - build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }} |
| 104 | + - run: |
| 105 | + name: Toolkit report |
| 106 | + command: | |
| 107 | + ./node_modules/.bin/grafana-toolkit plugin:ci-report |
| 108 | + - store_artifacts: |
| 109 | + path: ci |
| 110 | + |
| 111 | + publish_github_release: |
| 112 | + executor: default_exec |
| 113 | + steps: |
| 114 | + - checkout |
| 115 | + - add_ssh_keys: |
| 116 | + fingerprints: |
| 117 | + - "${GITHUB_SSH_FINGERPRINT}" |
| 118 | + - attach_workspace: |
| 119 | + at: . |
| 120 | + - restore_cache: |
| 121 | + name: restore node_modules |
| 122 | + keys: |
| 123 | + - build-cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }} |
| 124 | + - run: |
| 125 | + name: "Publish Release on GitHub" |
| 126 | + command: | |
| 127 | + wget "https://github.com/tcnksm/ghr/releases/download/v0.13.0/ghr_v0.13.0_linux_amd64.tar.gz" |
| 128 | + tar zxvf "./ghr_v0.13.0_linux_amd64.tar.gz" -C /usr/local |
| 129 | + /bin/rm -rf "./ghr_v0.13.0_linux_amd64.tar.gz" |
| 130 | + mkdir -pv dist |
| 131 | + mkdir -pv artifacts |
| 132 | + cp -r ci/dist/grafana-worldmap-panel/* dist/ |
| 133 | + cp -r ci/packages/* artifacts/ |
| 134 | + DATASOURCE_NAME=grafana-worldmap-panel |
| 135 | + RELEASE_NOTES=`awk 'BEGIN {FS="##"; RS=""} FNR==4 {print; exit}' CHANGELOG.md` |
| 136 | + VERSION=`cat ci/dist/plugin.json|jq '.info.version'| sed s/\"//g` |
| 137 | + git config user.email "[email protected]" |
| 138 | + git config user.name "CircleCI Automation" |
| 139 | + git checkout -b release-${VERSION} |
| 140 | + git add --force dist/ |
| 141 | + git add --force artifacts/ |
| 142 | + git commit -m "automated release $VERSION [skip ci]" |
| 143 | + git push -f origin release-${VERSION} |
| 144 | + git tag -f v${VERSION} |
| 145 | + git push -f origin v${VERSION} |
| 146 | + /usr/local/ghr_v0.13.0_linux_amd64/ghr \ |
| 147 | + -t ${GITHUB_TOKEN} \ |
| 148 | + -u ${CIRCLE_PROJECT_USERNAME} \ |
| 149 | + -r ${CIRCLE_PROJECT_REPONAME} \ |
| 150 | + -c ${CIRCLE_SHA1} \ |
| 151 | + -n "${DATASOURCE_NAME} v${VERSION}" \ |
| 152 | + -b "${RELEASE_NOTES}" \ |
| 153 | + -delete \ |
| 154 | + v${VERSION} \ |
| 155 | + ./artifacts |
0 commit comments