Add test seed upload workflow. #11
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PR Seed Upload | |
on: | |
pull_request: | |
paths: | |
- 'studies/**' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 | |
- name: Comment PR with upload in progress status | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const uniqueCommentId = '${{github.workflow_ref}}'; | |
const commentBody = | |
`## 🔄 Seed Upload In Progress | |
A new seed file is currently being uploaded for this pull request. | |
### What's Next? | |
- The upload process typically takes a few minutes. | |
- Once the upload is complete, a follow-up comment will provide the seed details and testing instructions. | |
Stay tuned for updates! | |
<!-- ${uniqueCommentId} --> | |
` | |
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(uniqueCommentId)); | |
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, | |
}); | |
} | |
- name: Install dependencies and run tests | |
run: | | |
npm install | |
npm run typecheck:scripts | |
npm run build:proto | |
npm run typechecka | |
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 status | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const fs = require('fs'); | |
const variationsServerURL = `https://griffin.brave.com/pull/${{github.event.pull_request.number}}/seed`; | |
const serialNumberContent = fs.readFileSync('serialnumber', 'utf8'); | |
const uniqueCommentId = '${{github.workflow_ref}}'; | |
const commentBody = | |
`## 🚀 Seed Upload Successful | |
The latest seed file has been successfully uploaded and is ready for testing. | |
### Seed Details | |
- **Serial Number:** \`${serialNumberContent}\` | |
- **Upload Timestamp:** \`${new Date().toISOString()}\` | |
### Testing Instructions | |
To test the new seed, launch the Brave browser with the following command line: | |
\`\`\`bash | |
brave --accept-empty-variations-seed-signature --variations-server-url=${variationsServerURL} | |
\`\`\` | |
This will configure the browser to use the uploaded seed for variations. | |
### Use the following service pages for more information: | |
- \`brave://version\` | |
--- | |
Please report any issues or feedback to the development team. Happy testing! | |
<!-- ${uniqueCommentId} --> | |
` | |
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(uniqueCommentId)); | |
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, | |
}); | |
} | |
- name: Comment PR with failure status | |
if: failure() | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const uniqueCommentId = '${{github.workflow_ref}}'; | |
const failureCommentBody = | |
`## ❌ Seed Upload Failed | |
Unfortunately, the seed file upload process failed. | |
### What's Next? | |
- Please check the pull request **Checks list** for more details on the failure. | |
- Review the error logs to identify what went wrong. | |
- Once the issue is resolved, please re-trigger the workflow. | |
<!-- ${uniqueCommentId} --> | |
` | |
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(uniqueCommentId)); | |
if (existingComment) { | |
await github.rest.issues.updateComment({ | |
comment_id: existingComment.id, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: failureCommentBody, | |
}); | |
} else { | |
await github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: failureCommentBody, | |
}); | |
} |