Skip to content

Add test seed upload workflow. #6

Add test seed upload workflow.

Add test seed upload workflow. #6

Workflow file for this run

name: PR Seed Upload
on:
pull_request:
paths:
- 'studies/**'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- name: Install dependencies and run tests
run: |
npm install
npm run typecheck:scripts
npm run build:proto
npm run typecheck
npm run test
- name: Generate seed
run: |
npm run seed_tools -- create_seed studies seed.bin
- name: Upload seed
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_PRODUCTION_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_PRODUCTION_SECRET_ACCESS_KEY }}
AWS_REGION: us-west-2
CLOUDFRONT_DISTRIBUTION_ID: ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }}
REMOTE_SEED_PATH: 'pull/${{github.event.pull_request.number}}/seed'
run: |
gzip -c seed.bin | aws s3 cp - "s3://brave-production-griffin-origin/$REMOTE_SEED_PATH" \
--content-type application/octet-stream \
--content-encoding gzip
INVALIDATION_ID=$(aws cloudfront create-invalidation --distribution-id "$CLOUDFRONT_DISTRIBUTION_ID" --paths "/$REMOTE_SEED_PATH" --query 'Invalidation.Id' --output text)
aws cloudfront wait invalidation-completed --distribution-id "$CLOUDFRONT_DISTRIBUTION_ID" --id "$INVALIDATION_ID"
- name: Comment PR with uploaded file URL and serialfile content
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const workflowName = process.env.GITHUB_WORKFLOW;
const variationsServerURL = `https://griffin.brave.com/pull/${{github.event.pull_request.number}}`;
const serialNumberContent = fs.readFileSync('serialnumber', 'utf8');
// Use the workflow ref as the unique comment identifier.
const uniqueIdentifier = '${{github.workflow_ref}}';
const commentBody =
`### Latest seed
\`\`\`
Uploaded: ${new Date().toISOString()}
Serial number: ${serialNumberContent}
\`\`\`
### Testing
\`\`\`
brave --accept-empty-variations-seed-signature --variations-server-url=${variationsServerURL}
\`\`\`
<!-- ${uniqueIdentifier} -->
`
const comments = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const existingComment = comments.data.find(comment => comment.body.includes(uniqueIdentifier));
if (existingComment) {
await github.rest.issues.updateComment({
comment_id: existingComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody,
});
} else {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody,
});
}