Commit Snapshots #513
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: Commit Snapshots | |
on: | |
workflow_run: | |
workflows: ['Update Snapshots'] | |
types: | |
- completed | |
jobs: | |
commit: | |
name: Commit Snapshots | |
if: github.event.workflow_run.conclusion == 'success' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.workflow_run.head_branch }} | |
repository: ${{ github.event.workflow_run.head_repository.full_name }} | |
- name: Download Artifacts | |
uses: actions/github-script@v3.1.0 | |
with: | |
script: | | |
const fs = require('fs'); | |
const { execSync } = require('child_process'); | |
const artifacts = await github.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: context.payload.workflow_run.id | |
}); | |
await Promise.all( | |
artifacts.data.artifacts.map(async (artifact) => { | |
const download = await github.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: artifact.id, | |
archive_format: 'zip' | |
}); | |
const tmpDir = `/tmp/${artifact.name.replace(/[^a-zA-Z0-9-_]/g, '')}`; | |
execSync(`mkdir -p ${tmpDir}`); | |
fs.writeFileSync(`${tmpDir}.zip`, Buffer.from(download.data)); | |
console.log(`Checking artifact: ${artifact.name}`) | |
execSync(`unzip -o ${tmpDir}.zip -d ${tmpDir}`); | |
if (artifact.name === 'metadata') { | |
execSync(`rsync -zavpmr --no-links --include='pull_number.txt' --exclude='*' ${tmpDir}/ ${{ github.workspace }}`); | |
} else { | |
const snapshotsDir = artifact.name.includes('v2') ? 'tests/functional/v2/snapshots' : 'tests/functional/snapshots'; | |
execSync(`rsync -zavpmr --no-links --include='*.png' --include='*/' --exclude='*' ${tmpDir}/ ${{ github.workspace }}/${snapshotsDir}`); | |
} | |
}) | |
); | |
- name: List Snapshots | |
run: | | |
git status --porcelain | |
- name: Reset Label | |
if: github.event.workflow_run.event == 'pull_request' | |
uses: actions/github-script@v3.1.0 | |
with: | |
# The workflow_run that comes along with the event drops the PR number for some reason | |
# so we have to pass the PR number from the original workflow as an artifact | |
script: | | |
const fs = require('fs'); | |
const pullNumber = Number(fs.readFileSync('./pull_number.txt', 'utf8')).toString(); | |
await github.issues.removeLabel({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: pullNumber, | |
name: 'snapshots' | |
}).catch(() => { | |
console.log('snapshots label has already been removed'); | |
}); | |
- name: Commit Updated Snapshots | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
commit_message: 'chore(snapshots): ${{ github.event.workflow.name }} [skip ci]' | |
commit_options: '--no-verify --quiet' | |
file_pattern: tests/functional/snapshots tests/functional/v2/snapshots | |
push_options: '-v' |