From a06d532fb0e20ee6454d03ec5e969229259918b0 Mon Sep 17 00:00:00 2001 From: Aleksey Khoroshilov Date: Thu, 11 Jul 2024 17:35:58 +0700 Subject: [PATCH] Add version set support. --- .github/workflows/generate-test-seed.yml | 8 ++-- seed/serialize.py | 3 ++ src/seed_tools/commands/create_seed.test.ts | 34 ++++++++++++++ src/seed_tools/commands/create_seed.ts | 4 +- .../data/set_seed_version/expected_seed.bin | Bin 0 -> 138 bytes .../set_seed_version/studies/TestStudy.json | 43 ++++++++++++++++++ 6 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 src/test/data/set_seed_version/expected_seed.bin create mode 100644 src/test/data/set_seed_version/studies/TestStudy.json diff --git a/.github/workflows/generate-test-seed.yml b/.github/workflows/generate-test-seed.yml index 2c431457..d3f41e01 100644 --- a/.github/workflows/generate-test-seed.yml +++ b/.github/workflows/generate-test-seed.yml @@ -12,6 +12,7 @@ jobs: env: ACTION_RUN_URL: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}' REMOTE_SEED_PATH: 'pull/${{ github.event.pull_request.number }}/seed' + SEED_VERSION: 'pull/${{ github.event.pull_request.number }}@${{ github.event.pull_request.head.sha }}' steps: - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 @@ -63,9 +64,9 @@ jobs: - name: Generate seed run: | # Use only python implementation for now. - python seed/serialize.py seed/seed.json + python seed/serialize.py seed/seed.json --version "$SEED_VERSION" # TODO: enable this when per-file studies will be synced with seed.json. - # npm run seed_tools -- create_seed studies seed.bin + # npm run seed_tools -- create_seed studies seed.bin --version "$SEED_VERSION" - name: Upload seed env: @@ -97,8 +98,9 @@ jobs: \`\`\` #### Seed Details - - Serial Number: \`${serialNumberContent}\` + - Version: \`${process.env.SEED_VERSION}\` - Uploaded: \`${new Date().toISOString()}\` + - Serial Number: \`${serialNumberContent}\` ` const comment = require('.github/workflows/scripts/comment.js') await comment(github, context, commentBody) diff --git a/seed/serialize.py b/seed/serialize.py index 48ef0daa..e251864f 100644 --- a/seed/serialize.py +++ b/seed/serialize.py @@ -329,6 +329,7 @@ def main(): 'seed_path', type=argparse.FileType('r'), nargs='?', help='json seed file to process') parser.add_argument('--mock_serial_number', help='mock serial number') + parser.add_argument('--version', help='version') args = parser.parse_args() print("Load", args.seed_path.name) @@ -343,6 +344,8 @@ def main(): if args.mock_serial_number is not None: seed_message.serial_number = args.mock_serial_number update_serial_number(seed_message.serial_number) + if args.version is not None: + seed_message.version = args.version # Serialize and save as seed file with open(SEED_BIN_PATH, "wb") as seed_file: diff --git a/src/seed_tools/commands/create_seed.test.ts b/src/seed_tools/commands/create_seed.test.ts index de61cc4a..170e8bb7 100644 --- a/src/seed_tools/commands/create_seed.test.ts +++ b/src/seed_tools/commands/create_seed.test.ts @@ -7,6 +7,7 @@ import * as fs_sync from 'fs'; import { promises as fs } from 'fs'; import * as os from 'os'; import * as path from 'path'; +import { VariationsSeed } from 'src/proto/generated/variations_seed'; import { wsPath } from '../../base/path_utils'; import create_seed from './create_seed'; @@ -52,10 +53,43 @@ describe('create_seed command', () => { const outputSerialNumber = await fs.readFile(serialNumberPath, 'utf-8'); expect(outputSerialNumber).toEqual('1'); + expect(VariationsSeed.fromBinary(output).version).toEqual('1'); }, ); }); + test('set seed version', async () => { + const testCaseDir = path.join(testDataDir, 'set_seed_version'); + const studiesDir = path.join(testCaseDir, 'studies'); + const outputFile = path.join(tempDir, 'output.bin'); + const serialNumberPath = path.join(tempDir, 'serial_number.txt'); + + await create_seed.parseAsync([ + 'node', + 'create_seed', + studiesDir, + outputFile, + '--version', + 'test version value', + '--mock_serial_number', + '1', + '--serial_number_path', + serialNumberPath, + ]); + + const output = await fs.readFile(outputFile); + const expectedOutput = await fs.readFile( + path.join(testCaseDir, 'expected_seed.bin'), + ); + expect(output).toEqual(expectedOutput); + + const outputSerialNumber = await fs.readFile(serialNumberPath, 'utf-8'); + expect(outputSerialNumber).toEqual('1'); + expect(VariationsSeed.fromBinary(output).version).toEqual( + 'test version value', + ); + }); + describe('invalid studies', () => { const invalidStudiesDir = path.join(testDataDir, 'invalid_studies'); it.each(fs_sync.readdirSync(invalidStudiesDir))( diff --git a/src/seed_tools/commands/create_seed.ts b/src/seed_tools/commands/create_seed.ts index 0b6c5bfa..66a3d1f8 100644 --- a/src/seed_tools/commands/create_seed.ts +++ b/src/seed_tools/commands/create_seed.ts @@ -21,6 +21,7 @@ export default new Command('create_seed') .description('Create seed.bin from study files') .argument('', 'path to a directory containing study files') .argument('', 'output seed file') + .option('--version ', 'version to set into the seed') .option( '--serial_number_path ', 'file path to write the serial number to', @@ -32,6 +33,7 @@ export default new Command('create_seed') interface Options { mock_serial_number?: string; serial_number_path?: string; + version?: string; } async function main(studiesDir: string, outputFile: string, options: Options) { @@ -47,7 +49,7 @@ async function main(studiesDir: string, outputFile: string, options: Options) { const variationsSeed: VariationsSeed = { study: [], layers: [], - version: '1', + version: options.version ?? '1', }; for (const file of files) { diff --git a/src/test/data/set_seed_version/expected_seed.bin b/src/test/data/set_seed_version/expected_seed.bin new file mode 100644 index 0000000000000000000000000000000000000000..1ebf1d4b1d7feb78a57a35090e0567d96e1beb21 GIT binary patch literal 138 zcmd;LG!!c2;tWYGE(tCvO{uhC^pfIYcg;&o%1KQTNJ--5;s(jNr6!h?7NvSgb8)z2 z7DFT%l6ZwsB)PfRT~gB$OLIyD7=omPxGatI4E2l+^i0ha7!;Tkm^BzQ7&VwQSP~eO Xgi3&hDwL%b6=&w>DU>DVl%@gz|Gp$# literal 0 HcmV?d00001 diff --git a/src/test/data/set_seed_version/studies/TestStudy.json b/src/test/data/set_seed_version/studies/TestStudy.json new file mode 100644 index 00000000..ad5694dc --- /dev/null +++ b/src/test/data/set_seed_version/studies/TestStudy.json @@ -0,0 +1,43 @@ +[ + { + "name": "TestStudy", + "experiment": [ + { + "name": "Enabled", + "probability_weight": 100, + "feature_association": { + "enable_feature": [ + "TestFeature" + ] + } + }, + { + "name": "Disabled", + "probability_weight": 0, + "feature_association": { + "disable_feature": [ + "TestFeature" + ] + } + }, + { + "name": "Default", + "probability_weight": 0 + } + ], + "filter": { + "min_version": "92.1.30.57", + "channel": [ + "NIGHTLY", + "BETA", + "RELEASE" + ], + "platform": [ + "PLATFORM_WINDOWS", + "PLATFORM_MAC", + "PLATFORM_LINUX", + "PLATFORM_ANDROID" + ] + } + } +]