|
| 1 | +name: Create Article from Issue |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: [opened] |
| 6 | + |
| 7 | +jobs: |
| 8 | + create-article: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + if: contains(github.event.issue.title, 'New article') |
| 11 | + steps: |
| 12 | + - name: Checkout repository |
| 13 | + uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Set up Python |
| 16 | + uses: actions/setup-python@v5 |
| 17 | + with: |
| 18 | + python-version: '3.12' |
| 19 | + |
| 20 | + - name: install chromium |
| 21 | + run: | |
| 22 | + sudo apt-get update |
| 23 | + sudo apt-get install -y chromium-browser libxss1 \ |
| 24 | + fonts-ipafont-gothic fonts-wqy-zenhei \ |
| 25 | + fonts-thai-tlwg fonts-kacst fonts-freefont-ttf \ |
| 26 | + --no-install-recommends |
| 27 | + - run: chromium-browser --version |
| 28 | + |
| 29 | + - name: pipenv install |
| 30 | + run: | |
| 31 | + pip install pipenv |
| 32 | + pipenv install |
| 33 | + - name: npm install |
| 34 | + run: | |
| 35 | + (cd previews && \ |
| 36 | + PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true npm install) |
| 37 | +
|
| 38 | + - name: Extract information from Issue |
| 39 | + id: extract |
| 40 | + run: | |
| 41 | + ISSUE_BODY="${{ github.event.issue.body }}" |
| 42 | +
|
| 43 | + FILEID=$(echo "$ISSUE_BODY" | grep -oP '(?<=\*\*Google doc\*\*: ).*' | sed 's|.*\/d/||' | sed 's|/.*||') |
| 44 | + AUTHOR=$(echo "$ISSUE_BODY" | grep -oP '(?<=\*\*Profile\*\*: ).*') |
| 45 | + TAGS=$(echo "$ISSUE_BODY" | grep -oP '(?<=\*\*Tags\*\*: ).*') |
| 46 | +
|
| 47 | + echo "fileid=$FILEID" >> "$GITHUB_OUTPUT" |
| 48 | + echo "author=$AUTHOR" >> "$GITHUB_OUTPUT" |
| 49 | + echo "tags=$TAGS" >> "$GITHUB_OUTPUT" |
| 50 | +
|
| 51 | + - name: Run the article generation script |
| 52 | + run: | |
| 53 | + pipenv run python scripts/pandoc_google_doc.py \ |
| 54 | + --fileid "${{ steps.extract.outputs.fileid }}" \ |
| 55 | + --author "${{ steps.extract.outputs.author }}" \ |
| 56 | + --tags "${{ steps.extract.outputs.tags }}" |
| 57 | +
|
| 58 | + - name: Commit and push generated article |
| 59 | + run: | |
| 60 | + git config user.name "github-actions[bot]" |
| 61 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 62 | +
|
| 63 | + BRANCH="articles/${{ steps.extract.outputs.fileid }}" |
| 64 | + git checkout -b "$BRANCH" |
| 65 | +
|
| 66 | + git add . |
| 67 | + git commit -m "Generated article from Google Doc ID: ${{ steps.extract.outputs.fileid }}" |
| 68 | + git push origin "$BRANCH" |
| 69 | +
|
| 70 | + - name: Create Pull Request |
| 71 | + id: create_pr |
| 72 | + uses: peter-evans/create-pull-request@v5 |
| 73 | + with: |
| 74 | + title: "Article draft: ${{ steps.extract.outputs.fileid }}" |
| 75 | + body: | |
| 76 | + This PR was automatically generated from issue #${{ github.event.issue.number }}. |
| 77 | +
|
| 78 | + Closes #${{ github.event.issue.number }} |
| 79 | + head: articles/${{ steps.extract.outputs.fileid }} |
| 80 | + base: main |
| 81 | + draft: true |
| 82 | + |
| 83 | + - name: Comment on the original Issue |
| 84 | + uses: peter-evans/create-or-update-comment@v3 |
| 85 | + with: |
| 86 | + issue-number: ${{ github.event.issue.number }} |
| 87 | + body: | |
| 88 | + A pull request has been created to draft your article: [#${{ steps.create_pr.outputs.pull-request-number }}](https://github.com/${{ github.repository }}/pull/${{ steps.create_pr.outputs.pull-request-number }}). |
| 89 | +
|
| 90 | + Thank you for your contribution! 🚀 |
0 commit comments