Skip to content

Commit 76abe94

Browse files
authored
Improve user experience for setting up environment variables (#21)
Setup dotenv to load environment variables from a `.env` file instead of assuming the user knows how to set environment variables in their shell on their own. Updated the README instructions to make it much more clear and explicit for how users should set their environment variables. Test Plan: Without any environment variables set: 1. Enable the "sourcecred/github" plugin 2. Add your github token to the `.env` file 3. Run `yarn load` and ensure that it successfully reads the token and loads github data into the cache.
1 parent 332ce0d commit 76abe94

File tree

5 files changed

+90
-23
lines changed

5 files changed

+90
-23
lines changed

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SOURCECRED_DISCORD_TOKEN=TjkyOTk1OFg1NTA2MTQ4NgVw.TqpnSA.fWIrGvOaQuT8Z-5-8dN-hdChkub
2+
SOURCECRED_GITHUB_TOKEN=913043df20670ec28e4428eacc80218a1bcce0dd

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ site/
33
output/
44
cache/
55

6-
7-
6+
.env

README.md

+24-17
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,30 @@ the plugins you want, pointing at the data you care about. We recommend setting
4444
your instance locally first and make sure its working before pushing your changes
4545
to master and using the Github Action.
4646

47-
Get [Yarn] and then run `yarn` to install SourceCred and dependencies.
47+
1. Get [Yarn] and then run `yarn` to install SourceCred and dependencies.
4848

49-
Enable the plugins you want to use by updating the `sourcecred.json` file. e.g.
49+
2. Enable the plugins you want to use by updating the `sourcecred.json` file. e.g.
5050
to enable all the plugins:
5151
```json
5252
{
5353
"bundledPlugins": ["sourcecred/discourse", "sourcecred/discord", "sourcecred/github"]
5454
}
5555
```
5656

57-
Update the configuration files according to the plugin guides below.
57+
3. If you are using the GitHub or Discord plugin, copy the `.env.example` file to a `.env` file:
58+
```shell script
59+
cp .env.example .env
60+
```
61+
62+
4. Follow the steps in the [plugin guides below](#supported-plugins) to setup the config files and generate access tokens
63+
for each plugin and then paste them into the `.env` file after the `=` sign.
64+
5865

59-
Then, run the following commands to update the instance:
66+
5. Run the following commands to update the instance:
6067

61-
- `yarn load [...plugins]` loads the cache. By default, it loads all
62-
plugins, or it can load only specific plugins if requested.
63-
- `yarn graph` regenerates plugin graphs from the cache;
64-
these graphs get saved in `output/`.
65-
- `yarn score` computes Cred scores, combining data from all the chosen
66-
plugins
68+
- `yarn load` loads the data from each plugin into the cache
69+
- `yarn graph` regenerates plugin graphs from the cache; these graphs get saved in `output/`.
70+
- `yarn score` computes Cred scores, combining data from all the chosen plugins
6771
- `yarn grain` distributes Grain according to the current Cred scores, and the config in `config/grain.json`
6872

6973
**Generate the frontend:**
@@ -95,8 +99,6 @@ commit and push your changes to master (or make a pull request). The Github Acti
9599
and deploy it to GitHub Pages. To enable GitHub Pages for your instance, check out [this guide](https://docs.github.com/en/github/working-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site).
96100
Make sure you select `gh-pages` as the branch to publish from.
97101

98-
99-
100102
# Supported Plugins
101103

102104
## GitHub
@@ -107,9 +109,9 @@ You can specify the repositories to load in
107109
`config/plugins/sourcecred/github/config.json`.
108110

109111
The Github Action automatically has its own GITHUB_TOKEN, but if you need to load data from the
110-
GitHub plugin locally, you must have a GitHub API key in your environment as
111-
`$SOURCECRED_GITHUB_TOKEN`. The key should be read-only without any special
112-
permissions (unless you are loading a private GitHub repository, in which case
112+
GitHub plugin locally, you must have a GitHub API key in your `.env` file as
113+
`SOURCECRED_GITHUB_TOKEN=<token>` (copy the `.env.example` file for reference). The key should be read-only without any special
114+
scopes or permissions (unless you are loading a private GitHub repository, in which case
113115
the key needs access to your private repositories).
114116

115117
You can generate a GitHub API key [here](https://github.com/settings/tokens).
@@ -121,8 +123,13 @@ keys or permissions. You just need to set the server url in `config/plugins/sour
121123

122124
## Discord
123125

124-
The Discord plugin loads Discord servers, and mints Cred on Discord reactions.
125-
For instructions on configuring the Discord plugin, see the [Discord plugin page](https://sourcecred.io/docs/beta/plugins/discord/#configuration) in the SourceCred documentation.
126+
The Discord plugin loads Discord servers, and mints Cred on Discord reactions. In order for SourceCred to
127+
access your Discord server, you need to generate a "bot token" and paste it in the `.env` file as
128+
`SOURCECRED_DISCORD_TOKEN=<token>` (copy the `.env.example` file for reference). You will also need to add it
129+
to your GitHub Action secrets.
130+
131+
The full instructions for setting up the Discord plugin can be found in the [Discord plugin page](https://sourcecred.io/docs/beta/plugins/discord/#configuration)
132+
in the SourceCred documentation.
126133

127134
# Removing plugins
128135

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
"scripts": {
1313
"clean": "rimraf cache site",
1414
"clean-all": "yarn clean && rimraf output",
15-
"load": "sourcecred load",
16-
"graph": "sourcecred graph",
15+
"load": "dotenv sourcecred load",
16+
"graph": "dotenv sourcecred graph",
1717
"score": "sourcecred score",
1818
"site": "sourcecred site",
1919
"serve": "sourcecred serve",
2020
"grain": "sourcecred grain"
2121
},
2222
"devDependencies": {
23-
"rimraf": "^3.0.2"
23+
"rimraf": "^3.0.2",
24+
"dotenv-cli": "^4.0.0"
2425
}
2526
}

yarn.lock

+59-1
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,15 @@ core-util-is@~1.0.0:
646646
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
647647
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=
648648

649+
cross-spawn@^7.0.1:
650+
version "7.0.3"
651+
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
652+
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==
653+
dependencies:
654+
path-key "^3.1.0"
655+
shebang-command "^2.0.0"
656+
which "^2.0.1"
657+
649658
css-in-js-utils@^2.0.0:
650659
version "2.0.1"
651660
resolved "https://registry.yarnpkg.com/css-in-js-utils/-/css-in-js-utils-2.0.1.tgz#3b472b398787291b47cfe3e44fecfdd9e914ba99"
@@ -942,6 +951,26 @@ domutils@^2.0.0:
942951
domelementtype "^2.0.1"
943952
domhandler "^3.0.0"
944953

954+
dotenv-cli@^4.0.0:
955+
version "4.0.0"
956+
resolved "https://registry.yarnpkg.com/dotenv-cli/-/dotenv-cli-4.0.0.tgz#3cdd68b87ccd63c78dbfa72aab2f639bbeba5f4b"
957+
integrity sha512-ByKEec+ashePEXthZaA1fif9XDtcaRnkN7eGdBDx3HHRjwZ/rA1go83Cbs4yRrx3JshsCf96FjAyIA2M672+CQ==
958+
dependencies:
959+
cross-spawn "^7.0.1"
960+
dotenv "^8.1.0"
961+
dotenv-expand "^5.1.0"
962+
minimist "^1.1.3"
963+
964+
dotenv-expand@^5.1.0:
965+
version "5.1.0"
966+
resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-5.1.0.tgz#3fbaf020bfd794884072ea26b1e9791d45a629f0"
967+
integrity sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA==
968+
969+
dotenv@^8.1.0:
970+
version "8.2.0"
971+
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"
972+
integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==
973+
945974
946975
version "3.2.7"
947976
resolved "https://registry.yarnpkg.com/downshift/-/downshift-3.2.7.tgz#0c40d78d1cbc24753c7a622cfc664df1c9480b4a"
@@ -1560,6 +1589,11 @@ isarray@~1.0.0:
15601589
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
15611590
integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=
15621591

1592+
isexe@^2.0.0:
1593+
version "2.0.0"
1594+
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
1595+
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=
1596+
15631597
isobject@^3.0.1:
15641598
version "3.0.1"
15651599
resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
@@ -1837,7 +1871,7 @@ minimatch@^3.0.4:
18371871
dependencies:
18381872
brace-expansion "^1.1.7"
18391873

1840-
minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5, minimist@~1.2.0:
1874+
minimist@^1.1.3, minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5, minimist@~1.2.0:
18411875
version "1.2.5"
18421876
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
18431877
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
@@ -2005,6 +2039,11 @@ path-is-absolute@^1.0.0:
20052039
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
20062040
integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18=
20072041

2042+
path-key@^3.1.0:
2043+
version "3.1.1"
2044+
resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375"
2045+
integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==
2046+
20082047
20092048
version "0.1.7"
20102049
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c"
@@ -2658,6 +2697,18 @@ [email protected]:
26582697
resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.1.1.tgz#7e95acb24aa92f5885e0abef5ba131330d4ae683"
26592698
integrity sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==
26602699

2700+
shebang-command@^2.0.0:
2701+
version "2.0.0"
2702+
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea"
2703+
integrity sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==
2704+
dependencies:
2705+
shebang-regex "^3.0.0"
2706+
2707+
shebang-regex@^3.0.0:
2708+
version "3.0.0"
2709+
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
2710+
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
2711+
26612712
signal-exit@^3.0.0:
26622713
version "3.0.3"
26632714
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c"
@@ -3145,6 +3196,13 @@ which-pm-runs@^1.0.0:
31453196
resolved "https://registry.yarnpkg.com/which-pm-runs/-/which-pm-runs-1.0.0.tgz#670b3afbc552e0b55df6b7780ca74615f23ad1cb"
31463197
integrity sha1-Zws6+8VS4LVd9rd4DKdGFfI60cs=
31473198

3199+
which@^2.0.1:
3200+
version "2.0.2"
3201+
resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1"
3202+
integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==
3203+
dependencies:
3204+
isexe "^2.0.0"
3205+
31483206
wide-align@^1.1.0:
31493207
version "1.1.3"
31503208
resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.3.tgz#ae074e6bdc0c14a431e804e624549c633b000457"

0 commit comments

Comments
 (0)