[Automated] Update develop snapshot #690
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: Pull Request Flow | |
on: | |
pull_request_target: | |
types: [assigned, opened, synchronize, reopened] | |
# tags-ignore and/or paths does not work with pull_request_target | |
# tags-ignore: | |
# - "automated pr" | |
# paths: | |
# - "packages/**" | |
jobs: | |
notify: | |
name: Notify snapshot update | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 10 | |
submodules: true | |
- name: List up snapshots | |
id: snapshots | |
run: | | |
echo "::set-output name=snapshots::$(ls -1 snapshot-*.opam | sed -e 's/\.opam$//' | sort -n | tr '\n' ' ')" | |
- name: Update the PR body | |
uses: actions/github-script@v2 | |
env: | |
SNAPSHOTS: ${{ steps.snapshots.outputs.snapshots }} | |
with: | |
github-token: ${{ github.token }} | |
script: | | |
const pullRequestId = { | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.issue.number | |
}; | |
const pull_request = await github.pulls.get(pullRequestId); | |
const actionHeader = '\n# Automatic follow-ups\n'; | |
const body = (pull_request.data.body || '').replace(/\r?\n/g, '\n'); | |
console.log('body', body); | |
const splitted = body.split(actionHeader); | |
const actionSectionMessage = 'Choose follow-up actions. Do not write anything after this section.'; | |
const actions = | |
process.env.SNAPSHOTS | |
.split(' ') | |
.filter((snapshot) => snapshot) | |
.map((snapshot) => `- Add to snapshot \`${snapshot}\``); | |
const replacedBody = `${splitted[0]}${actionHeader}${actionSectionMessage}\n${actions.join('\n')}`; | |
console.log('replacedBody', replacedBody); | |
await github.pulls.update({ | |
...pullRequestId, | |
body: replacedBody | |
}); |