Skip to content

Podcast: Key Takeaways Section #50

Podcast: Key Takeaways Section

Podcast: Key Takeaways Section #50

name: Create Article from Issue
on:
issues:
types: [opened, edited]
permissions:
contents: write
pull-requests: write
issues: write
jobs:
create-article:
runs-on: ubuntu-latest
if: contains(github.event.issue.title, 'New article')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: install chromium
run: |
sudo apt-get update
sudo apt-get install -y chromium-browser libxss1 \
fonts-ipafont-gothic fonts-wqy-zenhei \
fonts-thai-tlwg fonts-kacst fonts-freefont-ttf \
--no-install-recommends
- run: chromium-browser --version
- name: Install pandoc
run: |
sudo apt-get install -y pandoc
- name: Create gitbash alias
run: sudo ln -s /bin/bash /bin/gitbash
- name: uv install
run: |
pip install uv
uv sync
- name: npm install
run: |
(cd previews && \
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true npm install)
- name: Extract information from Issue
id: extract
run: |
echo "${{ github.event.issue.body }}" > issue_body.txt
echo "Extracted issue body:"
cat issue_body.txt
echo "------------------------"
while IFS= read -r line; do
KEY=$(echo "$line" | cut -d':' -f1 | xargs)
VALUE=$(echo "$line" | cut -d':' -f2- | xargs)
if [ "$KEY" = "Title" ]; then
TITLE="$VALUE"
elif [ "$KEY" = "Google doc" ]; then
FILEID="$VALUE"
elif [ "$KEY" = "Profile" ]; then
AUTHOR="$VALUE"
elif [ "$KEY" = "Tags" ]; then
TAGS="$VALUE"
fi
done < issue_body.txt
echo "Extracted values:"
echo "Title: $TITLE"
echo "File ID: $FILEID"
echo "Author: $AUTHOR"
echo "Tags: $TAGS"
echo "------------------------"
echo "title=$TITLE" >> "$GITHUB_OUTPUT"
echo "fileid=$FILEID" >> "$GITHUB_OUTPUT"
echo "author=$AUTHOR" >> "$GITHUB_OUTPUT"
echo "tags=$TAGS" >> "$GITHUB_OUTPUT"
rm issue_body.txt
- name: Run the article generation script
run: |
uv run python scripts/pandoc_google_doc.py \
--fileid "${{ steps.extract.outputs.fileid }}" \
--author "${{ steps.extract.outputs.author }}" \
--tags "${{ steps.extract.outputs.tags }}"
- name: Commit and push generated article
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
BRANCH="articles/${{ steps.extract.outputs.fileid }}"
git checkout -b "$BRANCH"
git add .
git commit -m "Generated article from Google Doc ID: ${{ steps.extract.outputs.fileid }}"
git push origin "$BRANCH"
- name: Create Pull Request
id: create_pr
run: |
gh pr create \
--title "Article draft: ${{ steps.extract.outputs.title }}" \
--body "This PR was automatically generated from issue #${{ github.event.issue.number }}. Closes #${{ github.event.issue.number }}" \
--head "articles/${{ steps.extract.outputs.fileid }}" \
--base main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Comment on the original Issue
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ github.event.issue.number }}
body: |
A pull request has been created to draft your article!
Thank you for your contribution! 🚀