|
| 1 | +name: Add PR comment |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["Handle PDF pull request"] |
| 6 | + types: [completed] |
| 7 | + |
| 8 | +jobs: |
| 9 | + comment: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 12 | + env: |
| 13 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 14 | + run_id: ${{ github.event.workflow_run.id }} |
| 15 | + |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v3 |
| 18 | + |
| 19 | + - name: Download artifacts |
| 20 | + run: | |
| 21 | + gh run download --dir artifact --name pdf $run_id |
| 22 | + cat artifact/environ.txt >> $GITHUB_ENV |
| 23 | +
|
| 24 | + - name: Check out preview ref |
| 25 | + run: | |
| 26 | + git fetch --depth=1 origin refs/preview/$pr_number:pr || git fetch --depth=1 origin $base_sha:pr |
| 27 | + git switch pr |
| 28 | + rm -rf new diff |
| 29 | + mv artifact/new artifact/diff . |
| 30 | +
|
| 31 | + - name: Compose comment |
| 32 | + shell: python |
| 33 | + env: |
| 34 | + view_url: https://cdn.jsdelivr.net/gh/${{ github.repository }}@<SHA> |
| 35 | + run: | |
| 36 | + import os |
| 37 | +
|
| 38 | + head_sha = os.environ['head_sha'] |
| 39 | + view_url = os.environ['view_url'] |
| 40 | +
|
| 41 | + files = [] |
| 42 | + links = [] |
| 43 | + for pdf in sorted(os.listdir("new")): |
| 44 | + new_pdf = os.path.join("new", pdf) |
| 45 | + diff_pdf = os.path.join("diff", pdf) |
| 46 | +
|
| 47 | + text = f"[{os.path.splitext(pdf)[0]}]({view_url}/{new_pdf})" |
| 48 | + files.append(new_pdf) |
| 49 | + if os.path.exists(diff_pdf): |
| 50 | + text += f" ([diff]({view_url}/{diff_pdf}))" |
| 51 | + files.append(diff_pdf) |
| 52 | + links.append(text) |
| 53 | +
|
| 54 | + with open(os.environ['GITHUB_ENV'], 'a') as outf: |
| 55 | + files_text = " ".join(files) |
| 56 | + print(f"pdf_files={files_text}", file=outf) |
| 57 | +
|
| 58 | + links_text = ", ".join(links) |
| 59 | + print(f"comment=Changed PDFs as of {head_sha}: {links_text}.", file=outf) |
| 60 | +
|
| 61 | + - name: Update preview ref |
| 62 | + env: |
| 63 | + GIT_AUTHOR_NAME: hts-specs bot |
| 64 | + GIT_COMMITTER_NAME: hts-specs bot |
| 65 | + EMAIL: hts-specs-bot@broadinstitute.org |
| 66 | + run: | |
| 67 | + git add -f $pdf_files |
| 68 | + git commit --allow-empty -m "PDFs for PR #$pr_number as of $head_sha" |
| 69 | + git push origin pr:refs/preview/$pr_number |
| 70 | +
|
| 71 | + - name: Add PR comment |
| 72 | + shell: bash |
| 73 | + run: | |
| 74 | + gh pr comment --body "${comment//<SHA>/$(git rev-parse pr)}" $pr_number |
0 commit comments