55/* global process */
66
77// This script consumes the following env variables:
8- // - AUTHORIZATION (mandatory): Raw authorization header (e.g. `AUTHORIZATION='Bearer XXXXXXXXXXXXX'`)
9- // - SERVER (mandatory): Writer server URL (eg. https://settings-writer.stage.mozaws.net/v1)
10- // - ENVIRONMENT (optional): dev, stage, prod. When set to `dev`, the script will approve its own changes.
11- // - DRY_RUN (optional): If set to 1, no changes will be made to the collection, this will
8+ // - FX_REMOTE_SETTINGS_WRITER_USER (mandatory): User
9+ // - FX_REMOTE_SETTINGS_WRITER_PASS (mandatory): Password
10+ // - FX_REMOTE_SETTINGS_WRITER_SERVER (mandatory): Writer server URL (eg. https://settings-writer.stage.mozaws.net/v1)
11+ // - FX_REMOTE_SETTINGS_ENVIRONMENT (optional): dev, stage, prod. When set to `dev`, the script will approve its own changes.
12+ // - FX_REMOTE_SETTINGS_DRY_RUN (optional): If set to 1, no changes will be made to the collection, this will
1213// only log the actions that would be done.
13-
1414// This node script fetches `https://github.com/mdn/browser-compat-data/tree/main/browsers`
1515// and updates records from the associated collection in RemoteSettings.
1616// In the future, it will also handle https://github.com/mdn/browser-compat-data/tree/main/css.
1717
1818import fetch from "node-fetch" ;
19+ import btoa from "btoa" ;
1920
2021// Use the legacy wrapper to support all Node 12+ versions.
2122// If we only support Node 16+, can be updated to:
@@ -27,34 +28,44 @@ const SUCCESS_RET_VALUE = 0;
2728const FAILURE_RET_VALUE = 1 ;
2829const VALID_ENVIRONMENTS = [ "dev" , "stage" , "prod" ] ;
2930
30- if ( ! process . env . AUTHORIZATION ) {
31- console . error ( `AUTHORIZATION environment variable needs to be set` ) ;
31+ if (
32+ ! process . env . FX_REMOTE_SETTINGS_WRITER_USER ||
33+ ! process . env . FX_REMOTE_SETTINGS_WRITER_PASS
34+ ) {
35+ console . error (
36+ `Both FX_REMOTE_SETTINGS_WRITER_USER and FX_REMOTE_SETTINGS_WRITER_PASS environment variables need to be set`
37+ ) ;
3238 process . exit ( FAILURE_RET_VALUE ) ;
3339}
3440
35- if ( ! process . env . SERVER ) {
36- console . error ( `SERVER environment variable needs to be set` ) ;
41+ if ( ! process . env . FX_REMOTE_SETTINGS_WRITER_SERVER ) {
42+ console . error (
43+ `FX_REMOTE_SETTINGS_WRITER_SERVER environment variable needs to be set`
44+ ) ;
3745 process . exit ( FAILURE_RET_VALUE ) ;
3846}
3947
4048if (
41- process . env . ENVIRONMENT &&
49+ process . env . FX_REMOTE_SETTINGS_ENVIRONMENT &&
4250 ! VALID_ENVIRONMENTS . includes ( process . env . ENVIRONMENT )
4351) {
4452 console . error (
45- `ENVIRONMENT environment variable needs to be set to one of the following values: ${ VALID_ENVIRONMENTS . join (
53+ `FX_REMOTE_SETTINGS_ENVIRONMENT environment variable needs to be set to one of the following values: ${ VALID_ENVIRONMENTS . join (
4654 ", "
4755 ) } `
4856 ) ;
4957 process . exit ( FAILURE_RET_VALUE ) ;
5058}
5159
52- const rsBrowsersCollectionEndpoint = `${ process . env . SERVER } /buckets/main-workspace/collections/devtools-compatibility-browsers` ;
60+ const rsBrowsersCollectionEndpoint = `${ process . env . FX_REMOTE_SETTINGS_WRITER_SERVER } /buckets/main-workspace/collections/devtools-compatibility-browsers` ;
5361const rsBrowsersRecordsEndpoint = `${ rsBrowsersCollectionEndpoint } /records` ;
54- const isDryRun = process . env . DRY_RUN == "1" ;
62+ const isDryRun = process . env . FX_REMOTE_SETTINGS_DRY_RUN == "1" ;
63+
5564const headers = {
5665 "Content-Type" : "application/json" ,
57- Authorization : process . env . AUTHORIZATION ,
66+ Authorization : `Basic ${ btoa (
67+ `${ process . env . FX_REMOTE_SETTINGS_WRITER_USER } :${ process . env . FX_REMOTE_SETTINGS_WRITER_PASS } `
68+ ) } `,
5869} ;
5970
6071update ( )
@@ -147,7 +158,7 @@ async function update() {
147158 const refreshedRecords = await getRSRecords ( ) ;
148159 console . log ( "Browsers data synced ✅\nRefreshed records:" ) ;
149160 console . table ( refreshedRecords ) ;
150- if ( process . env . ENVIRONMENT === "dev" ) {
161+ if ( process . env . FX_REMOTE_SETTINGS_ENVIRONMENT === "dev" ) {
151162 await approveChanges ( ) ;
152163 } else {
153164 await requestReview ( ) ;
0 commit comments