Skip to content

Commit

Permalink
Update ts configs, add diff-based linter. (#995)
Browse files Browse the repository at this point in the history
* Update ts configs, add diff-based linter.

* Add typecheck:scripts step to check scripts before running via tsx.

* Prettier format everything.
  • Loading branch information
goodov authored Apr 24, 2024
1 parent 9a32ee6 commit 1415b9d
Show file tree
Hide file tree
Showing 36 changed files with 1,967 additions and 856 deletions.
4 changes: 1 addition & 3 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"local>brave/renovate-config"
]
"extends": ["local>brave/renovate-config"]
}
4 changes: 2 additions & 2 deletions .github/workflows/deploy-to-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Deploy to Production

on:
push:
branches: [ main ]
branches: [main]
paths:
- 'src/**'
- 'src/**'
workflow_dispatch:

jobs:
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/test-src.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
with:
fetch-depth: 0

- name: npm install
run: npm install

- name: typecheck:scripts
run: npm run typecheck:scripts

- name: build
run: npm run build

- name: run tests
run: npm run test

- name: lint
run: npm run lint
run: npm run lint -- --base origin/${{ github.event.pull_request.base.ref }}
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
with:
fetch-depth: "0"
fetch-depth: '0'

- name: Setup Python
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4
with:
python-version: "3.11"
python-version: '3.11'

- name: Install requirements
run: pip install -r seed/requirements.txt
Expand Down
22 changes: 11 additions & 11 deletions .github/workflows/upsert-study.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ on:
workflow_dispatch:
inputs:
name:
description: "Study name"
description: 'Study name'
required: true
type: string
enable_feature:
description: "Feature name to enable"
description: 'Feature name to enable'
required: true
type: string
probability_enabled:
description: "Percentage number to enable (ex: 25)"
description: 'Percentage number to enable (ex: 25)'
required: true
default: "25"
default: '25'
type: string
channel:
description: "Channels to enable on (in comma separated value format)"
description: 'Channels to enable on (in comma separated value format)'
required: true
default: "RELEASE,BETA,NIGHTLY"
default: 'RELEASE,BETA,NIGHTLY'
type: string
platform:
description: "Platforms to enable on (in comma separated value format)"
description: 'Platforms to enable on (in comma separated value format)'
required: true
default: "WINDOWS,MAC,LINUX,ANDROID"
default: 'WINDOWS,MAC,LINUX,ANDROID'
type: string
min_version:
description: "Minimum version to enable on (optional)"
description: 'Minimum version to enable on (optional)'
required: false
type: string

Expand All @@ -44,11 +44,11 @@ jobs:
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
with:
fetch-depth: "0"
fetch-depth: '0'

- uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4
with:
python-version: "3.11"
python-version: '3.11'

- name: upsert-study
id: upsert
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/.venv/
/.vscode
/node_modules/
**/build/

seed.bin
serialnumber
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
seed/seed.json
src/web/css/bootstrap.min.css
14 changes: 14 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) 2024 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

// This file is located at the root level, rather than within the src/
// directory, to enable formatting for all files across the project, not just
// those within src/.

/** @type {import("prettier").Config} */
module.exports = {
plugins: ['prettier-plugin-organize-imports'],
singleQuote: true,
};
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
# Brave Variations (Griffin)
Griffin is Brave's version of Google's Finch - A backend for Chromium's variation service. This repository contains resources to compile, publish and inspect the so called *seed* file, which contains definitions for all variations.

See the [Wiki](https://github.com/brave/brave-browser/wiki/Brave-Variations-(Griffin)) to learn more about what variations are and how to use them for (1) staged rollouts, (2) parameter updates and (3) experiments.
Griffin is Brave's version of Google's Finch - A backend for Chromium's variation service. This repository contains resources to compile, publish and inspect the so called _seed_ file, which contains definitions for all variations.

See the [Wiki](<https://github.com/brave/brave-browser/wiki/Brave-Variations-(Griffin)>) to learn more about what variations are and how to use them for (1) staged rollouts, (2) parameter updates and (3) experiments.

## Overview

A continuous integration server (CI) serializes and signs the updated seed file before publishing it to a CDN endpoint at https://variations.brave.com/seed. To browse the contents of the seed file a dashboard is hosted at https://griffin.brave.com. The repo is organized as follows:

- `/crypto` contains a util to create key pairs and sign the seed file.
- `/seed` contains the JSON seed definition and serialisation code.
- `/src` contains the web dashboard to browse the seed contents and tracker code the track changes. See https://github.com/brave/brave-variations/blob/main/src/README.md for details.

## Git flow

1. Work in feature branch and when done create a PR to `main` branch (which will be picked up by CI for staging).
2. Verify that everything works as intended via the staging endpoint `--variations-server-url=https://variations.bravesoftware.com/seed`.
3. Cherry-pick the commit to production by creating another PR to `production` branch (which will be picked up by CI again).

## Key Generation and Exchange

On initial deployment and subsequent key rotations a new key pair has to be generated. The public key is exchanged by patching the hard-coded public key bytes in [variations_seed_store.cc#L37](https://source.chromium.org/chromium/chromium/src/+/master:components/variations/variations_seed_store.cc;l=37):

1. Generate a key pair with `$ go run ./crypto/crypto_util.go keygen`.
2. Update the [patched public key](https://github.com/brave/brave-core/blob/master/chromium_src/components/variations/variations_seed_store.cc#L6) in brave-core.
3. Store the private key in a secure vault and ensure it is accessible by CI.

## Seed Serialization, Signing and Serving

The following steps are performed by CI to publish the updated seed file:

1. Run `$ python seed/serialize.py seed/seed.json` to compile the protobuf.
Expand All @@ -36,6 +42,7 @@ Constraints:
- Brave Ads studies must contain the stubstring "BraveAds" in their study name. Only one ads study with page visible side effects is allowed to run. Multiple studies without visible side effects can run simultanesouly.

## Some Notes on using variations in the Browser

- Studies only take effect after restarting the browser.
- Pull from staging endpoint with `--variations-server-url=https://variations.bravesoftware.com/seed`.
- Precedence rules for feature overrides (starting with highest precedence):
Expand All @@ -50,6 +57,8 @@ Constraints:
- for logging add `--vmodule="*/variations/*"=1` or higher

## Dashboard

To build the dashboard:

1. Install dependencies `$ npm install`
2. Bundle resources `$ npm run build`
Loading

0 comments on commit 1415b9d

Please sign in to comment.