diff --git a/.circleci/config.yml b/.circleci/config.yml index 9e0f0f807d5..bc4f2e17b15 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,14 +1,5 @@ version: 2 -unit_tests: &unit_tests - steps: - - checkout - - restore_cache: - key: dependency-cache-{{ checksum "package-lock.json" }} - - run: - name: Run unit tests. - command: npm run ci:test - jobs: analysis: docker: @@ -18,13 +9,13 @@ jobs: - restore_cache: key: dependency-cache-{{ checksum "package-lock.json" }} - run: - name: Install Dependencies + name: Installing Dependencies command: npm ci --ignore-scripts - run: - name: Run linting. + name: Running linting command: npm run ci:lint - run: - name: Run NPM Security Audit + name: Running NPM Security Audit command: npm run security - save_cache: key: dependency-cache-{{ checksum "package-lock.json" }} @@ -33,7 +24,20 @@ jobs: node-v10-latest: docker: - image: rollupcabal/circleci-node-v10:latest - <<: *unit_tests + steps: + - checkout + - restore_cache: + key: dependency-cache-{{ checksum "package-lock.json" }} + - run: + name: Running tests + command: npm run ci:test + - store_artifacts: + name: Storing browser build for REPL + path: /home/circleci/project/dist/rollup.browser.js + destination: rollup.browser.js + - run: + name: Post REPL comment + command: ./scripts/post-comment.js node-v12-latest: docker: - image: rollupcabal/circleci-node-v12:latest @@ -42,9 +46,10 @@ jobs: - restore_cache: key: dependency-cache-{{ checksum "package-lock.json" }} - run: - name: Run tests with coverage. + name: Running tests with coverage command: npm run ci:coverage + workflows: version: 2 validate-test: diff --git a/.eslintrc.json b/.eslintrc.json index e35395ba7e3..5925f36e338 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -32,7 +32,7 @@ "plugin:import/warnings" ], "parserOptions": { - "ecmaVersion": 6, + "ecmaVersion": 2018, "sourceType": "module" }, "settings": { diff --git a/package.json b/package.json index 1c2105a002c..09b8917dc3e 100644 --- a/package.json +++ b/package.json @@ -97,6 +97,7 @@ "micromatch": "^4.0.2", "minimist": "^1.2.0", "mocha": "^6.2.2", + "node-fetch": "^2.6.0", "nyc": "^15.0.0", "prettier": "^1.19.1", "pretty-bytes": "^5.3.0", diff --git a/scripts/post-comment.js b/scripts/post-comment.js new file mode 100755 index 00000000000..1532fa65085 --- /dev/null +++ b/scripts/post-comment.js @@ -0,0 +1,60 @@ +#!/usr/bin/env node + +const path = require('path'); +const fetch = require('node-fetch'); + +const authToken = process.env.GH_AUTH_TOKEN; +if (!authToken) { + throw new Error('Could not find auth token.'); +} + +const prNumber = path.basename( + process.env.CIRCLE_PULL_REQUEST || process.env.CI_PULL_REQUEST || '' +); +if (!prNumber) { + console.log('No pull request number found'); + process.exit(0); +} + +const headline = '### Thank you for your contribution! ❤️'; + +postComment(); + +async function postComment() { + const existingId = await findExistingComment(); + console.log(existingId ? `Update comment ${existingId}` : 'Create new comment.'); + const installPath = await getInstallPath(); + const path = existingId ? `issues/comments/${existingId}` : `issues/${prNumber}/comments`; + const method = existingId ? 'PATCH' : 'POST'; + await fetch(getApiUrl(path), { + method, + body: JSON.stringify({ + body: `${headline} + +You can try out this pull request locally via + +\`\`\` +npm install ${installPath} +\`\`\` + +or load it into the REPL: +https://rollupjs.org/repl/?circleci=${process.env.CIRCLE_BUILD_NUM} +` + }) + }); +} + +async function findExistingComment() { + const comments = await (await fetch(getApiUrl(`issues/${prNumber}/comments`), {})).json(); + const existingComment = comments.find(comment => comment.body.startsWith(headline)); + return existingComment && existingComment.id; +} + +async function getInstallPath() { + const prInfo = await (await fetch(getApiUrl(`pulls/${prNumber}`), {})).json(); + return `${prInfo.head.repo.full_name}#${prInfo.head.ref}`; +} + +function getApiUrl(path) { + return `https://${authToken}:x-oauth-basic@api.github.com/repos/rollup/rollup/${path}`; +}