fCC 成都社区 Coffee & Code 周末编程自习室 2025年8月24日 #48
This file contains hidden or 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: Generate Markdown | |
on: | |
issues: | |
types: | |
- labeled | |
- edited | |
jobs: | |
generate-markdown: | |
if: github.event.issue.state == 'open' && contains(github.event.issue.labels.*.name, 'Article') | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
issues: write | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v4 | |
- id: issue-parser | |
uses: stefanbuck/github-issue-parser@v3 | |
with: | |
template-path: ".github/ISSUE_TEMPLATE/new-article.yml" | |
- name: Generate Markdown file | |
env: | |
GH_TOKEN: ${{ github.token }} | |
FILE_NAME: ${{ steps.issue-parser.outputs.issueparser_file_name }} | |
CATEGORY: ${{ steps.issue-parser.outputs.issueparser_category }} | |
THUMBNAIL: ${{ steps.issue-parser.outputs.issueparser_thumbnail }} | |
run: | | |
FILE_PATH=Article/$CATEGORY/$FILE_NAME | |
cat <<EOF > _posts/$FILE_PATH.md | |
--- | |
title: "${{ github.event.issue.title }}" | |
date: ${{ steps.issue-parser.outputs.issueparser_date || github.event.issue.created_at }} | |
updated: ${{ steps.issue-parser.outputs.issueparser_updated }} | |
categories: [Article, $CATEGORY] | |
tags: [${{ steps.issue-parser.outputs.issueparser_tags }}] | |
authors: [${{ steps.issue-parser.outputs.issueparser_authors }}] | |
original: ${{ steps.issue-parser.outputs.issueparser_original }} | |
toc: true | |
thumbnail: $(echo $THUMBNAIL | grep -oE 'https?://[^ \)]+' | head -n 1) | |
--- | |
${{ steps.issue-parser.outputs.issueparser_content }} | |
EOF | |
POST_URL=$(echo "https://fcc-cd.dev/$FILE_PATH" | tr '[:upper:]' '[:lower:]') | |
COMMENT_BODY="After the linked PR merged, the article will be posted at: $POST_URL" | |
gh issue comment ${{ github.event.issue.number }} --body "$COMMENT_BODY" | |
- uses: peter-evans/create-pull-request@v7 | |
with: | |
title: "[add] ${{ github.event.issue.title }} article" | |
body: "closes #${{ github.event.issue.number }}" | |
author: "${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>" |