diff --git a/.circleci/build-openapi.sh b/.circleci/build-openapi.sh new file mode 100755 index 00000000..583493b6 --- /dev/null +++ b/.circleci/build-openapi.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +PATH=./node_modules/.bin:$PATH + +# find all OpenAPI docs that are not fragments +FNAMES=`find . -name "openapi.yaml" -not -path "./fragments/*" -not -path "./node_modules/*"` + +# use speccy to resolve +for fin in $FNAMES; do + fout=./build/$fin + mkdir -p ${fout%/*} + speccy resolve $fin > $fout +done \ No newline at end of file diff --git a/.circleci/config.yml b/.circleci/config.yml index 35ae1344..70cf716f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,6 +1,27 @@ version: 2.1 + +references: + restore_repo: &restore_repo + restore_cache: + keys: + - v0-repo-{{ .Branch }}-{{ .Revision }} + - v0-repo-{{ .Branch }} + - v0-repo + + restore_dependencies: &restore_dependencies + restore_cache: + keys: + - v0-dependencies-{{ checksum "package.json"}} + - v0-dependencies + + restore_build: &restore_build + restore_cache: + keys: + - v0-build-{{ .Branch }}-{{ .Revision }} + + jobs: - build: + validate: working_directory: ~/stac docker: - image: circleci/node:12 @@ -9,9 +30,69 @@ jobs: - run: name: init_submodules command: git submodule update --init --recursive + - save_cache: + key: v0-repo-{{ .Branch }}-{{ .Revision }} + paths: + - ~/stac - run: name: install command: npm install + - save_cache: + key: v0-dependencies-{{ checksum "package.json"}} + paths: + - ~/stac/node_modules - run: name: validate - command: npm run check \ No newline at end of file + command: npm run check + build: + working_directory: ~/stac + docker: + - image: circleci/node:12 + steps: + - *restore_repo + - *restore_dependencies + - run: + name: build openapi + command: npm run build-openapi + - save_cache: + key: v0-build-{{ .Branch }}-{{ .Revision }} + paths: + - ~/stac/build + publish: + working_directory: ~/stac + docker: + - image: circleci/node:12 + steps: + - *restore_repo + - *restore_dependencies + - *restore_build + - add_ssh_keys + - run: + name: publish + command: | + ssh-keyscan github.com >> ~/.ssh/known_hosts + npm run publish-openapi -- $CIRCLE_TAG + +workflows: + version: 2 + ci: + jobs: + - validate: + filters: + tags: + only: /^v.*/ + - build: + requires: + - validate + filters: + tags: + only: /^v.*/ + - publish: + requires: + - build + filters: + tags: + only: /^v.*/ + branches: + # Only dev branch, not PRs + only: dev \ No newline at end of file diff --git a/.circleci/publish.js b/.circleci/publish.js new file mode 100644 index 00000000..01f829e6 --- /dev/null +++ b/.circleci/publish.js @@ -0,0 +1,20 @@ +const ghpages = require('gh-pages'); + +let args = process.argv.slice(2); +let tag = 'dev'; +if (args.length && args[0].trim().length > 0) { + tag = args[0]; +} + +ghpages.publish('build/', { + src: '**', + dest: tag, + message: 'Publish JSON Schemas [ci skip]', + user: { + name: 'STAC CI', + email: 'ci@stacspec.org' + } +}, error => { + console.error(error ? error : 'Deployed to gh-pages'); + process.exit(error ? 1 : 0); +}); \ No newline at end of file diff --git a/package.json b/package.json index cddc14d6..13eba49b 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,14 @@ "check-openapi-commons": "spectral lint core/commons.yaml --ruleset .circleci/.spectral-fragments.yml", "check-openapi-ogcapi-features": "spectral lint ogcapi-features/openapi.yaml ogcapi-features/extensions/*/openapi.yaml --ruleset .circleci/.spectral.yml", "check-openapi-item-search": "spectral lint item-search/openapi.yaml --ruleset .circleci/.spectral.yml", - "check-openapi-fragments": "spectral lint fragments/*/openapi.yaml --ruleset .circleci/.spectral-fragments.yml" + "check-openapi-fragments": "spectral lint fragments/*/openapi.yaml --ruleset .circleci/.spectral-fragments.yml", + "build-openapi": ".circleci/build-openapi.sh", + "publish-openapi": "node .circleci/publish.js" }, "dependencies": { "@stoplight/spectral": "^5.7.1", + "gh-pages": "^3.1.0", + "klaw-sync": "^6.0.0", "redoc-cli": "^0.10.2", "remark-cli": "^8.0.1", "remark-lint": "^7.0.1", @@ -25,6 +29,7 @@ "remark-preset-lint-markdown-style-guide": "^3.0.1", "remark-preset-lint-recommended": "^4.0.1", "remark-validate-links": "^10.0.2", + "speccy": "^0.11.0", "yaml-files": "^1.1.0" } }