Update Jest Snap of #1324 #777
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: Update Jest Snaps after Renovate | |
run-name: 'Update Jest Snap of #${{ github.event.workflow_run.pull_requests[0].number }}' | |
on: | |
workflow_run: | |
workflows: ['CI'] | |
types: ['completed'] | |
branches: ['renovate/**'] | |
# If we're already doing the process, cancel the old attempt. | |
concurrency: | |
group: update-snap-${{ github.event.workflow_run.pull_requests[0].number }} | |
cancel-in-progress: true | |
env: | |
BRANCH_NAME: 'renovate-snap/${{github.event.workflow_run.pull_requests[0].number}}' | |
jobs: | |
close-snap: | |
name: 'Close Jest Snap PR' | |
runs-on: ubuntu-20.04 | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- name: Delete the branch | |
run: git push origin --delete $BRANCH_NAME | |
update-snap: | |
name: 'Update Jest Snap of #${{ github.event.workflow_run.pull_requests[0].number }}' | |
if: ${{ github.event.workflow_run.conclusion == 'failure' }} | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Setup runner | |
if: ${{matrix.os == 'ubuntu-20.04'}} | |
# Ensure we can use as many file watcher as we want. see https://github.com/facebook/create-react-app/blob/master/docusaurus/docs/troubleshooting.md#npm-start-fail-due-to-watch-error | |
run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p | |
- name: Setup runner | |
if: ${{matrix.os == 'windows-latest'}} | |
run: | | |
git config --global core.autocrlf false | |
git config --global core.eol lf | |
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3 | |
with: | |
ref: ${{ github.event.workflow_run.head_branch }} | |
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3 | |
with: | |
cache: 'npm' | |
node-version-file: '.nvmrc' | |
- name: Setup Git Config | |
run: | | |
git config user.name github-actions | |
git config user.email [email protected] | |
git config --global --add --bool push.autoSetupRemote true | |
- name: Ensure update branch does not exists | |
run: git push origin --delete $BRANCH_NAME || true | |
- name: Start update branch | |
run: git checkout -b $BRANCH_NAME | |
- name: Install dependencies | |
run: npm ci | |
- name: Build | |
run: npm run build | |
- name: Update snapshots | |
run: npm test -- -u | |
- name: Commit-Push | |
run: | | |
git commit -am 'chore:refresh jest snap j:cdx-227' | |
git push -f | |
- name: Open PR | |
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6 | |
continue-on-error: true | |
env: | |
DISPLAY_TITLE: ${{ github.event.workflow_run.display_title }} | |
PR_BODY: '#${{ github.event.workflow_run.pull_requests[0].number }}' | |
with: | |
script: | | |
const jira = 'j:cdx-227'; | |
const title = `${process.env.DISPLAY_TITLE.split(jira)[0]} and jest snaps ${jira}`; | |
github.rest.pulls.create({ | |
title: title, | |
body: process.env.PR_BODY, | |
base: 'master', | |
head: process.env.BRANCH_NAME, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
maintainer_can_modify: true, | |
}); | |
github.rest.actions.createWorkflowDispatch({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: 'build.yml', | |
ref: process.env.BRANCH_NAME, | |
}); |