|
| 1 | +name: Update External Links Gallery |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - edited |
| 8 | +jobs: |
| 9 | + validate-user-submission: |
| 10 | + if: | |
| 11 | + github.repository == 'ProjectPythia/projectpythia.github.io' |
| 12 | + && contains(github.event.issue.labels.*.name, 'external-links-gallery-submission') |
| 13 | + runs-on: ubuntu-latest |
| 14 | + defaults: |
| 15 | + run: |
| 16 | + shell: bash -l {0} |
| 17 | + steps: |
| 18 | + - name: Find Comment |
| 19 | + uses: peter-evans/find-comment@v1 |
| 20 | + id: fc |
| 21 | + with: |
| 22 | + issue-number: ${{ github.event.issue.number }} |
| 23 | + comment-author: 'github-actions[bot]' |
| 24 | + body-includes: Thank you for your contribution |
| 25 | + - name: Create comment |
| 26 | + if: steps.fc.outputs.comment-id == '' |
| 27 | + uses: peter-evans/create-or-update-comment@v1 |
| 28 | + with: |
| 29 | + issue-number: ${{ github.event.issue.number }} |
| 30 | + body: | |
| 31 | + Thank you for your contribution 🎉, @${{ github.actor }}! |
| 32 | +
|
| 33 | + We're currently running [validation checks](https://github.com${{ github.repository }}/actions/runs/${{ github.run_id }}) to make sure the contents of your submission are okay. An update will be posted here shortly once the validation checks are passing. |
| 34 | + - name: Update comment |
| 35 | + if: steps.fc.outputs.comment-id != '' |
| 36 | + uses: peter-evans/create-or-update-comment@v1 |
| 37 | + with: |
| 38 | + comment-id: ${{ steps.fc.outputs.comment-id }} |
| 39 | + edit-mode: replace |
| 40 | + body: | |
| 41 | + Thank you for your contribution 🎉, @${{ github.actor }}! |
| 42 | +
|
| 43 | + We're currently running [validation checks](https://github.com${{ github.repository }}/actions/runs/${{ github.run_id }}) to make sure the contents of your submission are okay. An update will be posted here shortly once the validation checks are passing. |
| 44 | + - uses: actions/checkout@v2 |
| 45 | + - uses: actions/setup-python@v2 |
| 46 | + with: |
| 47 | + python-version: 3.8 |
| 48 | + |
| 49 | + - name: Install dependencies |
| 50 | + run: | |
| 51 | + python -m pip install pip --upgrade |
| 52 | + python -m pip install python-frontmatter markdown-it-py pydantic[email] |
| 53 | +
|
| 54 | + - name: Validate input |
| 55 | + run: | |
| 56 | + python .github/workflows/collect-user-submission.py |
| 57 | + exit 0 |
| 58 | +
|
| 59 | + - uses: actions/upload-artifact@v2 |
| 60 | + with: |
| 61 | + name: submission |
| 62 | + path: gallery-submission-input.json |
| 63 | + |
| 64 | + create-pull-request: |
| 65 | + needs: validate-user-submission |
| 66 | + runs-on: ubuntu-latest |
| 67 | + defaults: |
| 68 | + run: |
| 69 | + shell: bash -l {0} |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v2 |
| 72 | + - uses: actions/setup-python@v2 |
| 73 | + with: |
| 74 | + python-version: 3.8 |
| 75 | + - uses: actions/download-artifact@v2 |
| 76 | + with: |
| 77 | + name: submission |
| 78 | + |
| 79 | + - name: Display structure of downloaded artifacts |
| 80 | + run: | |
| 81 | + ls -R |
| 82 | +
|
| 83 | + - name: Install dependencies |
| 84 | + run: | |
| 85 | + python -m pip install pip --upgrade |
| 86 | + python -m pip install ruamel.yaml pre-commit |
| 87 | +
|
| 88 | + - name: Update gallery |
| 89 | + shell: python |
| 90 | + run: | |
| 91 | + import json |
| 92 | + from ruamel.yaml import YAML |
| 93 | +
|
| 94 | + yaml = YAML() |
| 95 | + submission_file = 'gallery-submission-input.json' |
| 96 | + links_file = 'content/links.yaml' |
| 97 | + with open(submission_file) as f: |
| 98 | + data = json.load(f) |
| 99 | +
|
| 100 | + with open(links_file) as f: |
| 101 | + links = yaml.load(f) |
| 102 | +
|
| 103 | + with open(links_file, 'w') as f: |
| 104 | + links.append(data) |
| 105 | + yaml.dump(links, f) |
| 106 | +
|
| 107 | + - name: Run pre-commit hooks |
| 108 | + run: | |
| 109 | + python -m pre_commit run --all-files |
| 110 | +
|
| 111 | + - name: Create pull request |
| 112 | + id: cpr |
| 113 | + uses: peter-evans/create-pull-request@v3 |
| 114 | + with: |
| 115 | + commit-message: 'Update external links gallery' |
| 116 | + committer: GitHub <noreply@github.com> |
| 117 | + author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> |
| 118 | + signoff: false |
| 119 | + branch: external-links-gallery-${{ github.event.issue.number }} |
| 120 | + title: 'Update external links gallery' |
| 121 | + body: | |
| 122 | + Update external links gallery as requested in #${{ github.event.issue.number }}. |
| 123 | +
|
| 124 | + - name: Find Comment |
| 125 | + uses: peter-evans/find-comment@v1 |
| 126 | + id: fc |
| 127 | + with: |
| 128 | + issue-number: ${{ github.event.issue.number }} |
| 129 | + comment-author: 'github-actions[bot]' |
| 130 | + body-includes: We've created a pull request on your behalf |
| 131 | + |
| 132 | + - name: Create comment |
| 133 | + if: steps.fc.outputs.comment-id == '' |
| 134 | + uses: peter-evans/create-or-update-comment@v1 |
| 135 | + with: |
| 136 | + issue-number: ${{ github.event.issue.number }} |
| 137 | + body: | |
| 138 | + @${{ github.actor }}, your submission looks great! We've created a pull request on your behalf using the information you provided. |
| 139 | +
|
| 140 | + The pull request can be accessed from this url: ${{ steps.cpr.outputs.pull-request-url }}. |
| 141 | +
|
| 142 | + - name: Update comment |
| 143 | + if: steps.fc.outputs.comment-id != '' |
| 144 | + uses: peter-evans/create-or-update-comment@v1 |
| 145 | + with: |
| 146 | + comment-id: ${{ steps.fc.outputs.comment-id }} |
| 147 | + edit-mode: replace |
| 148 | + body: | |
| 149 | + @${{ github.actor }}, your submission looks great! We've created a pull request on your behalf using the information you provided. |
| 150 | +
|
| 151 | + The pull request can be accessed from this url: ${{ steps.cpr.outputs.pull-request-url }}. |
0 commit comments