Make Card DB PR #280
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: Make Card DB PR | |
on: | |
workflow_run: | |
workflows: | |
- Compile Card DB | |
types: | |
- completed | |
jobs: | |
make_pr: | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/github-script@v6 | |
id: get-artifact | |
with: | |
result-encoding: string | |
script: | | |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: ${{github.event.workflow_run.id }}, | |
}); | |
var matchArtifacts = artifacts.data.artifacts.filter((artifact) => { | |
return artifact.name == "card_db" | |
}); | |
if (matchArtifacts.length > 0) { | |
var matchArtifact = matchArtifacts[0]; | |
var download = await github.rest.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: matchArtifact.id, | |
archive_format: 'zip', | |
}); | |
var fs = require('fs'); | |
fs.writeFileSync('${{github.workspace}}/card_db.zip', Buffer.from(download.data)); | |
return 'found_artifact'; | |
} else { | |
return 'no_artifact' | |
} | |
- run: unzip -o -d src/domdiv/card_db card_db.zip | |
if: steps.get-artifact.outputs.result == 'found_artifact' | |
- run: rm -f card_db.zip | |
if: steps.get-artifact.outputs.result == 'found_artifact' | |
- name: 'Download PR number artifact' | |
if: steps.get-artifact.outputs.result == 'found_artifact' | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: ${{github.event.workflow_run.id }}, | |
}); | |
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { | |
return artifact.name == "pr_number" | |
})[0]; | |
let download = await github.rest.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: matchArtifact.id, | |
archive_format: 'zip', | |
}); | |
let fs = require('fs'); | |
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_number.zip`, Buffer.from(download.data)); | |
- name: 'Unzip PR Number artifact' | |
if: steps.get-artifact.outputs.result == 'found_artifact' | |
run: unzip pr_number.zip | |
- name: 'Read PR number' | |
id: read-pr-number | |
if: steps.get-artifact.outputs.result == 'found_artifact' | |
uses: actions/github-script@v6 | |
with: | |
result-encoding: string | |
script: | | |
let fs = require('fs'); | |
let pr_number = Number(fs.readFileSync('./pr_number')); | |
console.log(`original pr number: ${pr_number}`) | |
return pr_number | |
- name: Make PR | |
id: make-pr | |
if: steps.get-artifact.outputs.result == 'found_artifact' | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
title: 'Auto Card DB compile for #${{ steps.read-pr-number.outputs.result }}' | |
body: | | |
Auto-generate package card DB to from source card DB for PR #${{ steps.read-pr-number.outputs.result }} | |
delete-branch: true | |
reviewers: sumpfork | |
assignees: sumpfork | |
add-paths: | | |
src/domdiv/card_db/ | |
- name: 'Comment on PR' | |
if: steps.get-artifact.outputs.result == 'found_artifact' | |
uses: actions/github-script@v6 | |
env: | |
THIS_PR_NUMBER: ${{ steps.make-pr.outputs.pull-request-number }} | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
console.log(`new PR number: ${{ steps.make-pr.outputs.pull-request-number }}`) | |
console.log(process.env) | |
const { THIS_PR_NUMBER } = process.env | |
console.log(`new PR number: ${THIS_PR_NUMBER}`) | |
let fs = require('fs'); | |
let issue_number = Number(fs.readFileSync('./pr_number')); | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number, | |
body: `It seems compiling the card DB on this PR produced changes.\n` + | |
`Ideally, please run "doit update-language" yourself on this PR and check in the results.\n` + | |
`Otherwise, PR #${THIS_PR_NUMBER} has the necessary (but unreviewed) changes.\n` | |
}); |