From f08b71d48b537b6611cae7fbd0452a4eba71745c Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 14 Feb 2022 15:13:38 +0100 Subject: [PATCH] meta: consolidate ENV files and fix contributing guidelines (#3475) And use `pull_request_target` event instead of `pull_request` to use secrets from forks. Fixes: https://github.com/transloadit/uppy/issues/3473 Co-authored-by: Mikael Finstad --- .env.example | 7 +----- .github/CONTRIBUTING.md | 31 +++++++++----------------- .github/workflows/end-to-end.yml | 2 +- .gitignore | 1 - bin/companion.sh | 19 ++++++++-------- bin/run-example.js | 31 -------------------------- package.json | 3 +-- website/src/_template/contributing.md | 32 +++++++++------------------ 8 files changed, 34 insertions(+), 92 deletions(-) delete mode 100644 bin/run-example.js diff --git a/.env.example b/.env.example index b5ad063eb..e49e4bed6 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ -# Rename this file to `.env` +# Clone this file to `.env.local` and edit the clone. Don't put secrets in the `.env` files. NODE_ENV=development @@ -32,11 +32,6 @@ COMPANION_ZOOM_SECRET=*** COMPANION_UNSPLASH_KEY=*** COMPANION_UNSPLASH_SECRET=*** -# Transloadit keys can also be used in `e2e/clients` -TRANSLOADIT_KEY=*** -TRANSLOADIT_TEMPLATE=*** -TRANSLOADIT_SERVICE_URL=https://api2.transloadit.com - # Development environment # ======================= diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 82f1e167f..2587cc161 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -42,7 +42,7 @@ yarn run test:unit We use [Cypress](cypress.io/) for our e2e test suite. Be sure to checkout “[Writing your first test](https://docs.cypress.io/guides/getting-started/writing-your-first-test#Add-a-test-file)” and the “[Introduction to Cypress](https://docs.cypress.io/guides/core-concepts/introduction-to-cypress#Cypress-Can-Be-Simple-Sometimes)”. You should also be aware of the “[Best Practices](https://docs.cypress.io/guides/references/best-practices)”. -To get started make sure you have your `.env` set up. If it doesn’t exist, copy and rename the `.env.local` file and populate (some) of the values. What values need to be populated depends on what tests you want to run. +To get started make sure you have your `.env.local` set up. If it doesn’t exist, it will use the default value in the `.env` file which won’t work for most cases. Consider copy `.env` in a file named `.env.local` and the values relevant for the test(s) you are trying to run. To start the testing suite run: @@ -60,12 +60,10 @@ Even though facebook [allows using](https://developers.facebook.com/blog/post/20 Make sure that you are using a development facebook app at -Go to “Instagram Basic Display” and find `Instagram App ID` and `Instagram App Secret`. Put them in a file called `env.sh` in the repo root: +Go to “Instagram Basic Display” and find `Instagram App ID` and `Instagram App Secret`. Put them in a file called `.env.local` in the repo root: -```bash -export COMPANION_INSTAGRAM_KEY="Instagram App ID" -export COMPANION_INSTAGRAM_SECRET="Instagram App Secret" -``` + COMPANION_INSTAGRAM_KEY="Instagram App ID" + COMPANION_INSTAGRAM_SECRET="Instagram App Secret" Run @@ -80,18 +78,11 @@ append `/instagram/redirect` to it, such as: Add this full ngrok URL to `Valid OAuth Redirect URIs` under `Instagram Basic Display`. -Edit `bin/companion` and change to your ngrok URI: +Edit `.env.local` and change to your ngrok URI: -```bash -COMPANION_DOMAIN="e0c7de09808d.ngrok.io" -COMPANION_PROTOCOL="https" -``` - -Edit `examples/dev/Dashboard.js`: - -```js -const COMPANION_URL = 'https://e0c7de09808d.ngrok.io' -``` + COMPANION_DOMAIN="e0c7de09808d.ngrok.io" + COMPANION_PROTOCOL="https" + VITE_COMPANION_URL = 'https://e0c7de09808d.ngrok.io' Go to: Roles -> Roles -> Add Instagram testers -> Add your instagram account @@ -113,15 +104,13 @@ open http://localhost:4000/examples/dashboard Also check the other examples: ```bash -cd examples/EXAMPLENAME -yarn install -yarn start +yarn workspace start ``` Releases are managed by GitHub Actions, here’s an overview of the process to release a new Uppy version: * Run `yarn release` on your local machine. -* Follow the instructions and select what packages to release. **Warning:** skipping packages results in those changes being "lost", meaning they won't be picked up in the changelog automatically next release. Always try to release all. +* Follow the instructions and select what packages to release. **Warning:** skipping packages results in those changes being “lost”, meaning they won’t be picked up in the changelog automatically next release. Always try to release all. * Before committing, check if the generated files look good. * When asked to edit the next CHANGELOG, only include changes related to the package(s) you selected for release. * Push to the Transloadit repository using the command given by the tool. Do not open a PR yourself, the GitHub Actions will create one and assign you to it. diff --git a/.github/workflows/end-to-end.yml b/.github/workflows/end-to-end.yml index 24d78e8df..8259e513c 100644 --- a/.github/workflows/end-to-end.yml +++ b/.github/workflows/end-to-end.yml @@ -2,7 +2,7 @@ name: End-to-end tests on: push: branches: [ main ] - pull_request: + pull_request_target: # We want all branches so we configure types to be the GH default again types: [ opened, synchronize, reopened ] diff --git a/.gitignore b/.gitignore index 980c94ea3..e0d5a6b97 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,6 @@ node_modules .yarn/install-state.gz yarn-error.log -.env *.local dist/ diff --git a/bin/companion.sh b/bin/companion.sh index 836cdbb4c..eb647ab17 100644 --- a/bin/companion.sh +++ b/bin/companion.sh @@ -1,19 +1,20 @@ #!/usr/bin/env bash # Load local env vars. In CI, these are injected. -if [ -f .env ]; then +if [ -f .env.local ]; then # https://gist.github.com/mihow/9c7f559807069a03e302605691f85572?permalink_comment_id=3625310#gistcomment-3625310 set -a - source <(sed -e '/^#/d;/^\s*$/d' -e "s/'/'\\\''/g" -e "s/=\(.*\)/='\1'/g" .env) + source <(sed -e '/^#/d;/^\s*$/d' -e "s/'/'\\\''/g" -e "s/=\(.*\)/='\1'/g" .env.local) set +a nodemon --watch packages/@uppy/companion/src --exec node ./packages/@uppy/companion/src/standalone/start-server.js else env \ - COMPANION_DATADIR="./output" \ - COMPANION_DOMAIN="localhost:3020" \ - COMPANION_PROTOCOL="http" \ - COMPANION_PORT=3020 \ - COMPANION_CLIENT_ORIGINS="" \ - COMPANION_SECRET="development" \ - nodemon --watch packages/@uppy/companion/src --exec node ./packages/@uppy/companion/src/standalone/start-server.js + COMPANION_DATADIR="./output" \ + COMPANION_DOMAIN="localhost:3020" \ + COMPANION_PROTOCOL="http" \ + COMPANION_PORT=3020 \ + COMPANION_CLIENT_ORIGINS="" \ + COMPANION_SECRET="development" \ + nodemon --watch packages/@uppy/companion/src --exec node ./packages/@uppy/companion/src/standalone/start-server.js fi + diff --git a/bin/run-example.js b/bin/run-example.js deleted file mode 100644 index 2d4357a15..000000000 --- a/bin/run-example.js +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env node - -/** - * Lerna installs all the example dependencies into the root `node_modules`. - * To run the examples they need to have access to executables from npm dependencies in their $PATH. - * If you run `npm start` in a dependency folder, the root `node_modules/.bin` is not in the $PATH. - * - * This proxy executable can be run from the repository root using `npm run example`, so the root - * `node_modules/.bin` will be in the $PATH. It then runs `npm start` in the specific example folder, - * which will inherit the $PATH, so the example has access to executables from npm dependencies in both - * its own and in the root `node_modules`. - */ - -const path = require('path') -const { execSync } = require('child_process') - -const exampleName = process.argv[2] - -if (!exampleName) { - console.error('Usage: npm run example "name-of-example"') - process.exit(1) -} - -const exampleDir = path.join(__dirname, '../examples', exampleName) -// eslint-disable-next-line import/no-dynamic-require -const pkg = require(path.join(exampleDir, 'package.json')) -if (pkg.scripts && pkg.scripts.build) { - execSync('npm run build', { cwd: exampleDir, stdio: 'inherit' }) -} - -execSync('npm start', { cwd: exampleDir, stdio: 'inherit' }) diff --git a/package.json b/package.json index 44f15df28..3902eeb4a 100644 --- a/package.json +++ b/package.json @@ -133,7 +133,6 @@ "contributors:save": "yarn node ./bin/update-contributors.mjs", "dev:with-companion": "npm-run-all --parallel start:companion dev", "dev": "yarn workspace @uppy-dev/dev dev", - "example": "yarn node bin/run-example", "lint:fix": "yarn run lint -- --fix", "lint:markdown": "remark -f -q . -i .remarkignore", "lint:staged": "lint-staged", @@ -144,7 +143,7 @@ "size": "echo 'JS Bundle mingz:' && cat ./packages/uppy/dist/uppy.min.js | gzip | wc -c && echo 'CSS Bundle mingz:' && cat ./packages/uppy/dist/uppy.min.css | gzip | wc -c", "start:companion": "bash bin/companion.sh", "start": "npm-run-all --parallel watch start:companion web:start", - "e2e": "npm-run-all --parallel watch:js:lib e2e:client start:companion e2e:cypress", + "e2e": "yarn build && npm-run-all --parallel watch:js:lib e2e:client start:companion e2e:cypress", "e2e:ci": "start-server-and-test 'npm-run-all --parallel e2e:client start:companion' '1234|3020' e2e:headless", "e2e:client": "yarn workspace e2e client:start", "e2e:cypress": "yarn workspace e2e cypress:open", diff --git a/website/src/_template/contributing.md b/website/src/_template/contributing.md index 83cb4c916..cebfab71c 100644 --- a/website/src/_template/contributing.md +++ b/website/src/_template/contributing.md @@ -44,7 +44,7 @@ yarn run test:unit We use [Cypress](cypress.io/) for our e2e test suite. Be sure to checkout “[Writing your first test](https://docs.cypress.io/guides/getting-started/writing-your-first-test#Add-a-test-file)” and the “[Introduction to Cypress](https://docs.cypress.io/guides/core-concepts/introduction-to-cypress#Cypress-Can-Be-Simple-Sometimes)”. You should also be aware of the “[Best Practices](https://docs.cypress.io/guides/references/best-practices)”. -To get started make sure you have your `.env` set up. If it doesn’t exist, copy and rename the `.env.local` file and populate (some) of the values. What values need to be populated depends on what tests you want to run. +To get started make sure you have your `.env.local` set up. If it doesn’t exist, it will use the default value in the `.env` file which won’t work for most cases. Copy `.env` to a file named `.env.local` and add the values relevant for the test(s) you are trying to run. To start the testing suite run: @@ -62,12 +62,10 @@ Even though facebook [allows using](https://developers.facebook.com/blog/post/20 Make sure that you are using a development facebook app at -Go to “Instagram Basic Display” and find `Instagram App ID` and `Instagram App Secret`. Put them in a file called `env.sh` in the repo root: +Go to “Instagram Basic Display” and find `Instagram App ID` and `Instagram App Secret`. Put them in a file called `.env.local` in the repo root: -```bash -export COMPANION_INSTAGRAM_KEY="Instagram App ID" -export COMPANION_INSTAGRAM_SECRET="Instagram App Secret" -``` + COMPANION_INSTAGRAM_KEY="Instagram App ID" + COMPANION_INSTAGRAM_SECRET="Instagram App Secret" Run @@ -82,18 +80,11 @@ append `/instagram/redirect` to it, such as: Add this full ngrok URL to `Valid OAuth Redirect URIs` under `Instagram Basic Display`. -Edit `bin/companion` and change to your ngrok URI: +Edit `.env.local` and change to your ngrok URI: -```bash -COMPANION_DOMAIN="e0c7de09808d.ngrok.io" -COMPANION_PROTOCOL="https" -``` - -Edit `examples/dev/Dashboard.js`: - -```js -const COMPANION_URL = 'https://e0c7de09808d.ngrok.io' -``` + COMPANION_DOMAIN="e0c7de09808d.ngrok.io" + COMPANION_PROTOCOL="https" + VITE_COMPANION_URL = 'https://e0c7de09808d.ngrok.io' Go to: Roles -> Roles -> Add Instagram testers -> Add your instagram account @@ -115,16 +106,15 @@ open http://localhost:4000/examples/dashboard Also check the other examples: ```bash -cd examples/EXAMPLENAME -yarn install -yarn start +yarn workspace start ``` Releases are managed by GitHub Actions, here’s an overview of the process to release a new Uppy version: * Run `yarn release` on your local machine. -* Follow the instructions and select what packages to release. +* Follow the instructions and select what packages to release. **Warning:** skipping packages results in those changes being “lost”, meaning they won’t be picked up in the changelog automatically next release. Always try to release all. * Before committing, check if the generated files look good. +* When asked to edit the next CHANGELOG, only include changes related to the package(s) you selected for release. * Push to the Transloadit repository using the command given by the tool. Do not open a PR yourself, the GitHub Actions will create one and assign you to it. * Wait for all the GitHub Actions checks to pass. If one fails, try to figure out why. Do not go ahead without consulting the rest of the team. * Review the PR thoroughly, and if everything looks good to you, approve the PR. Do not merge it manually!