nsarrazin HF staff commited on
Commit
fac3250
1 Parent(s): e69cb4a

Update CI scripts for dotenv management (#508)

Browse files

* Replace DOTENV python script by TS script

* Add script to update .env.local locally

* add back secrets in actions flow

.github/workflows/deploy-release.yml CHANGED
@@ -8,26 +8,21 @@ on:
8
 
9
  jobs:
10
  update-env:
11
- name: "Update production environment config"
12
  runs-on: ubuntu-latest
 
13
 
14
  steps:
15
- - name: checkout repo content
16
- uses: actions/checkout@v3 # checkout the repository content to github runner.
17
- - name: setup python
18
- uses: actions/setup-python@v4
19
  with:
20
- python-version: 3.11 #install the python needed
21
- - name: "Install dependencies"
22
- run: |
23
- python -m pip install --upgrade pip
24
- pip install huggingface_hub
25
- - name: Update .env.local # run file
26
  env:
27
  HF_TOKEN: ${{ secrets.HF_TOKEN }}
28
  SECRET_CONFIG: ${{ secrets.SECRET_CONFIG }}
29
- run: |
30
- python update_env.py
31
  sync-to-hub:
32
  runs-on: ubuntu-latest
33
  steps:
 
8
 
9
  jobs:
10
  update-env:
 
11
  runs-on: ubuntu-latest
12
+ timeout-minutes: 10
13
 
14
  steps:
15
+ - uses: actions/checkout@v3
16
+ - uses: actions/setup-node@v3
 
 
17
  with:
18
+ node-version: "18"
19
+ cache: "npm"
20
+ - run: npm install ci
21
+ - name: "Update DOTENV_LOCAL in prod"
 
 
22
  env:
23
  HF_TOKEN: ${{ secrets.HF_TOKEN }}
24
  SECRET_CONFIG: ${{ secrets.SECRET_CONFIG }}
25
+ run: npm run updateProdEnv
 
26
  sync-to-hub:
27
  runs-on: ubuntu-latest
28
  steps:
.gitignore CHANGED
@@ -9,3 +9,4 @@ node_modules
9
  !.env.template
10
  vite.config.js.timestamp-*
11
  vite.config.ts.timestamp-*
 
 
9
  !.env.template
10
  vite.config.js.timestamp-*
11
  vite.config.ts.timestamp-*
12
+ SECRET_CONFIG
package-lock.json CHANGED
@@ -49,6 +49,7 @@
49
  "prettier-plugin-tailwindcss": "^0.2.7",
50
  "svelte": "^4.0.0",
51
  "svelte-check": "^3.4.3",
 
52
  "tslib": "^2.4.1",
53
  "typescript": "^5.0.0",
54
  "unplugin-icons": "^0.16.1",
@@ -91,6 +92,28 @@
91
  "url": "https://github.com/sponsors/antfu"
92
  }
93
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  "node_modules/@esbuild/android-arm": {
95
  "version": "0.17.16",
96
  "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.17.16.tgz",
@@ -1007,6 +1030,30 @@
1007
  "node": ">= 10"
1008
  }
1009
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1010
  "node_modules/@types/chai": {
1011
  "version": "4.3.5",
1012
  "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.5.tgz",
@@ -1435,7 +1482,7 @@
1435
  "version": "8.10.0",
1436
  "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.10.0.tgz",
1437
  "integrity": "sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==",
1438
- "dev": true,
1439
  "bin": {
1440
  "acorn": "bin/acorn"
1441
  },
@@ -1456,7 +1503,7 @@
1456
  "version": "8.2.0",
1457
  "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz",
1458
  "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==",
1459
- "dev": true,
1460
  "engines": {
1461
  "node": ">=0.4.0"
1462
  }
@@ -2045,6 +2092,12 @@
2045
  "node": ">= 0.6"
2046
  }
2047
  },
 
 
 
 
 
 
2048
  "node_modules/cross-spawn": {
2049
  "version": "7.0.3",
2050
  "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
@@ -2269,6 +2322,15 @@
2269
  "resolved": "https://registry.npmjs.org/didyoumean/-/didyoumean-1.2.2.tgz",
2270
  "integrity": "sha512-gxtyfqMg7GKyhQmb056K7M3xszy/myH8w+B4RT+QXBQsvAOdc3XymqDDPHx1BgPgsdAA5SIifona89YtRATDzw=="
2271
  },
 
 
 
 
 
 
 
 
 
2272
  "node_modules/dir-glob": {
2273
  "version": "3.0.1",
2274
  "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz",
@@ -3570,6 +3632,12 @@
3570
  "node": ">=12"
3571
  }
3572
  },
 
 
 
 
 
 
3573
  "node_modules/marked": {
3574
  "version": "4.3.0",
3575
  "resolved": "https://registry.npmjs.org/marked/-/marked-4.3.0.tgz",
@@ -5772,6 +5840,55 @@
5772
  "resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz",
5773
  "integrity": "sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA=="
5774
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5775
  "node_modules/tslib": {
5776
  "version": "2.5.0",
5777
  "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz",
@@ -5826,7 +5943,7 @@
5826
  "version": "5.2.2",
5827
  "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz",
5828
  "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==",
5829
- "dev": true,
5830
  "bin": {
5831
  "tsc": "bin/tsc",
5832
  "tsserver": "bin/tsserver"
@@ -5970,6 +6087,12 @@
5970
  "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
5971
  "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="
5972
  },
 
 
 
 
 
 
5973
  "node_modules/varint": {
5974
  "version": "5.0.2",
5975
  "resolved": "https://registry.npmjs.org/varint/-/varint-5.0.2.tgz",
@@ -6308,6 +6431,15 @@
6308
  "node": ">= 6"
6309
  }
6310
  },
 
 
 
 
 
 
 
 
 
6311
  "node_modules/yocto-queue": {
6312
  "version": "0.1.0",
6313
  "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
 
49
  "prettier-plugin-tailwindcss": "^0.2.7",
50
  "svelte": "^4.0.0",
51
  "svelte-check": "^3.4.3",
52
+ "ts-node": "^10.9.1",
53
  "tslib": "^2.4.1",
54
  "typescript": "^5.0.0",
55
  "unplugin-icons": "^0.16.1",
 
92
  "url": "https://github.com/sponsors/antfu"
93
  }
94
  },
95
+ "node_modules/@cspotcode/source-map-support": {
96
+ "version": "0.8.1",
97
+ "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz",
98
+ "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==",
99
+ "devOptional": true,
100
+ "dependencies": {
101
+ "@jridgewell/trace-mapping": "0.3.9"
102
+ },
103
+ "engines": {
104
+ "node": ">=12"
105
+ }
106
+ },
107
+ "node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping": {
108
+ "version": "0.3.9",
109
+ "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz",
110
+ "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==",
111
+ "devOptional": true,
112
+ "dependencies": {
113
+ "@jridgewell/resolve-uri": "^3.0.3",
114
+ "@jridgewell/sourcemap-codec": "^1.4.10"
115
+ }
116
+ },
117
  "node_modules/@esbuild/android-arm": {
118
  "version": "0.17.16",
119
  "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.17.16.tgz",
 
1030
  "node": ">= 10"
1031
  }
1032
  },
1033
+ "node_modules/@tsconfig/node10": {
1034
+ "version": "1.0.9",
1035
+ "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz",
1036
+ "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==",
1037
+ "devOptional": true
1038
+ },
1039
+ "node_modules/@tsconfig/node12": {
1040
+ "version": "1.0.11",
1041
+ "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz",
1042
+ "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==",
1043
+ "devOptional": true
1044
+ },
1045
+ "node_modules/@tsconfig/node14": {
1046
+ "version": "1.0.3",
1047
+ "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz",
1048
+ "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==",
1049
+ "devOptional": true
1050
+ },
1051
+ "node_modules/@tsconfig/node16": {
1052
+ "version": "1.0.4",
1053
+ "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz",
1054
+ "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==",
1055
+ "devOptional": true
1056
+ },
1057
  "node_modules/@types/chai": {
1058
  "version": "4.3.5",
1059
  "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.5.tgz",
 
1482
  "version": "8.10.0",
1483
  "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.10.0.tgz",
1484
  "integrity": "sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==",
1485
+ "devOptional": true,
1486
  "bin": {
1487
  "acorn": "bin/acorn"
1488
  },
 
1503
  "version": "8.2.0",
1504
  "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz",
1505
  "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==",
1506
+ "devOptional": true,
1507
  "engines": {
1508
  "node": ">=0.4.0"
1509
  }
 
2092
  "node": ">= 0.6"
2093
  }
2094
  },
2095
+ "node_modules/create-require": {
2096
+ "version": "1.1.1",
2097
+ "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz",
2098
+ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==",
2099
+ "devOptional": true
2100
+ },
2101
  "node_modules/cross-spawn": {
2102
  "version": "7.0.3",
2103
  "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
 
2322
  "resolved": "https://registry.npmjs.org/didyoumean/-/didyoumean-1.2.2.tgz",
2323
  "integrity": "sha512-gxtyfqMg7GKyhQmb056K7M3xszy/myH8w+B4RT+QXBQsvAOdc3XymqDDPHx1BgPgsdAA5SIifona89YtRATDzw=="
2324
  },
2325
+ "node_modules/diff": {
2326
+ "version": "4.0.2",
2327
+ "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
2328
+ "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==",
2329
+ "devOptional": true,
2330
+ "engines": {
2331
+ "node": ">=0.3.1"
2332
+ }
2333
+ },
2334
  "node_modules/dir-glob": {
2335
  "version": "3.0.1",
2336
  "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz",
 
3632
  "node": ">=12"
3633
  }
3634
  },
3635
+ "node_modules/make-error": {
3636
+ "version": "1.3.6",
3637
+ "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",
3638
+ "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==",
3639
+ "devOptional": true
3640
+ },
3641
  "node_modules/marked": {
3642
  "version": "4.3.0",
3643
  "resolved": "https://registry.npmjs.org/marked/-/marked-4.3.0.tgz",
 
5840
  "resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz",
5841
  "integrity": "sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA=="
5842
  },
5843
+ "node_modules/ts-node": {
5844
+ "version": "10.9.1",
5845
+ "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz",
5846
+ "integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==",
5847
+ "devOptional": true,
5848
+ "dependencies": {
5849
+ "@cspotcode/source-map-support": "^0.8.0",
5850
+ "@tsconfig/node10": "^1.0.7",
5851
+ "@tsconfig/node12": "^1.0.7",
5852
+ "@tsconfig/node14": "^1.0.0",
5853
+ "@tsconfig/node16": "^1.0.2",
5854
+ "acorn": "^8.4.1",
5855
+ "acorn-walk": "^8.1.1",
5856
+ "arg": "^4.1.0",
5857
+ "create-require": "^1.1.0",
5858
+ "diff": "^4.0.1",
5859
+ "make-error": "^1.1.1",
5860
+ "v8-compile-cache-lib": "^3.0.1",
5861
+ "yn": "3.1.1"
5862
+ },
5863
+ "bin": {
5864
+ "ts-node": "dist/bin.js",
5865
+ "ts-node-cwd": "dist/bin-cwd.js",
5866
+ "ts-node-esm": "dist/bin-esm.js",
5867
+ "ts-node-script": "dist/bin-script.js",
5868
+ "ts-node-transpile-only": "dist/bin-transpile.js",
5869
+ "ts-script": "dist/bin-script-deprecated.js"
5870
+ },
5871
+ "peerDependencies": {
5872
+ "@swc/core": ">=1.2.50",
5873
+ "@swc/wasm": ">=1.2.50",
5874
+ "@types/node": "*",
5875
+ "typescript": ">=2.7"
5876
+ },
5877
+ "peerDependenciesMeta": {
5878
+ "@swc/core": {
5879
+ "optional": true
5880
+ },
5881
+ "@swc/wasm": {
5882
+ "optional": true
5883
+ }
5884
+ }
5885
+ },
5886
+ "node_modules/ts-node/node_modules/arg": {
5887
+ "version": "4.1.3",
5888
+ "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz",
5889
+ "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==",
5890
+ "devOptional": true
5891
+ },
5892
  "node_modules/tslib": {
5893
  "version": "2.5.0",
5894
  "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz",
 
5943
  "version": "5.2.2",
5944
  "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz",
5945
  "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==",
5946
+ "devOptional": true,
5947
  "bin": {
5948
  "tsc": "bin/tsc",
5949
  "tsserver": "bin/tsserver"
 
6087
  "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
6088
  "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="
6089
  },
6090
+ "node_modules/v8-compile-cache-lib": {
6091
+ "version": "3.0.1",
6092
+ "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz",
6093
+ "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==",
6094
+ "devOptional": true
6095
+ },
6096
  "node_modules/varint": {
6097
  "version": "5.0.2",
6098
  "resolved": "https://registry.npmjs.org/varint/-/varint-5.0.2.tgz",
 
6431
  "node": ">= 6"
6432
  }
6433
  },
6434
+ "node_modules/yn": {
6435
+ "version": "3.1.1",
6436
+ "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz",
6437
+ "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==",
6438
+ "devOptional": true,
6439
+ "engines": {
6440
+ "node": ">=6"
6441
+ }
6442
+ },
6443
  "node_modules/yocto-queue": {
6444
  "version": "0.1.0",
6445
  "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
package.json CHANGED
@@ -11,7 +11,9 @@
11
  "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
12
  "lint": "prettier --plugin-search-dir . --check . && eslint .",
13
  "format": "prettier --plugin-search-dir . --write .",
14
- "test": "MONGODB_URL=mongodb://127.0.0.1:27017/ vitest"
 
 
15
  },
16
  "devDependencies": {
17
  "@iconify-json/carbon": "^1.1.16",
@@ -33,6 +35,7 @@
33
  "prettier-plugin-tailwindcss": "^0.2.7",
34
  "svelte": "^4.0.0",
35
  "svelte-check": "^3.4.3",
 
36
  "tslib": "^2.4.1",
37
  "typescript": "^5.0.0",
38
  "unplugin-icons": "^0.16.1",
 
11
  "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
12
  "lint": "prettier --plugin-search-dir . --check . && eslint .",
13
  "format": "prettier --plugin-search-dir . --write .",
14
+ "test": "MONGODB_URL=mongodb://127.0.0.1:27017/ vitest",
15
+ "updateLocalEnv": "npx ts-node --esm scripts/updateLocalEnv.ts",
16
+ "updateProdEnv": "npx ts-node --esm scripts/updateProdEnv.ts"
17
  },
18
  "devDependencies": {
19
  "@iconify-json/carbon": "^1.1.16",
 
35
  "prettier-plugin-tailwindcss": "^0.2.7",
36
  "svelte": "^4.0.0",
37
  "svelte-check": "^3.4.3",
38
+ "ts-node": "^10.9.1",
39
  "tslib": "^2.4.1",
40
  "typescript": "^5.0.0",
41
  "unplugin-icons": "^0.16.1",
scripts/updateLocalEnv.ts ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import fs from "fs";
2
+
3
+ const SECRET_CONFIG = fs.existsSync(".env.SECRET_CONFIG")
4
+ ? fs.readFileSync(".env.SECRET_CONFIG", "utf8")
5
+ : process.env.SECRET_CONFIG;
6
+
7
+ if (SECRET_CONFIG === "") {
8
+ throw new Error(
9
+ "SECRET_CONFIG is not defined. Please provide it either in a file or as an environment variable."
10
+ );
11
+ }
12
+
13
+ // Read the content of the file .env.template
14
+ const PUBLIC_CONFIG = fs.readFileSync(".env.template", "utf8");
15
+
16
+ // Prepend the content of the env variable SECRET_CONFIG
17
+ const full_config = `${PUBLIC_CONFIG}\n${SECRET_CONFIG}`;
18
+
19
+ // Write full_config to .env.local
20
+ fs.writeFileSync(".env.local", full_config);
scripts/updateProdEnv.ts ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import fs from "fs";
2
+
3
+ const HF_TOKEN = process.env.HF_TOKEN;
4
+ const SECRET_CONFIG = fs.existsSync(".env.SECRET_CONFIG")
5
+ ? fs.readFileSync(".env.SECRET_CONFIG", "utf8")
6
+ : process.env.SECRET_CONFIG;
7
+
8
+ if (SECRET_CONFIG === "") {
9
+ throw new Error(
10
+ "SECRET_CONFIG is not defined. Please provide it either in a file or as an environment variable."
11
+ );
12
+ }
13
+
14
+ // Read the content of the file .env.template
15
+ const PUBLIC_CONFIG = fs.readFileSync(".env.template", "utf8");
16
+
17
+ // Prepend the content of the env variable SECRET_CONFIG
18
+ const full_config = `${PUBLIC_CONFIG}\n${SECRET_CONFIG}`;
19
+
20
+ // Make an HTTP POST request to add the space secre
21
+ fetch(`https://huggingface.co/api/spaces/huggingchat/chat-ui/secrets`, {
22
+ method: "POST",
23
+ body: JSON.stringify({
24
+ key: "DOTENV_LOCAL",
25
+ value: full_config,
26
+ description: `Env variable for HuggingChat. Last updated ${new Date().toISOString()}`,
27
+ }),
28
+ headers: {
29
+ Authorization: `Bearer ${HF_TOKEN}`,
30
+ "Content-Type": "application/json",
31
+ },
32
+ });
update_env.py DELETED
@@ -1,17 +0,0 @@
1
- import os
2
- from huggingface_hub import HfApi
3
-
4
-
5
- SECRET_CONFIG = os.environ["SECRET_CONFIG"]
6
- HF_TOKEN = os.environ["HF_TOKEN"]
7
-
8
- # Read the content of the file .env.template
9
- with open(".env.template", "r") as f:
10
- PUBLIC_CONFIG = f.read()
11
-
12
- # Prepend the content of the env variable SECRET_CONFIG
13
- full_config = f"{PUBLIC_CONFIG}\n{SECRET_CONFIG}"
14
-
15
- api = HfApi()
16
-
17
- api.add_space_secret("huggingchat/chat-ui", "DOTENV_LOCAL", full_config, token=HF_TOKEN)