“This is the 16th day of my participation in the First Challenge 2022. For details: First Challenge 2022”

preface

  • GitHub Profile README Generator – Dynamic Latest Blog Posts (GitHub Profile README Generator – Dynamic Latest Blog Posts), Blog -post-workflow
  • This article uses GitHub Actions to get the latest blog subscriptions and displays them on the GitHub home page

Build steps

<1> Configure blog subscriptions (output in RSS or ATOM format) to provide access to related resource files over the Internet

< 2 > workflow is added in the individual main warehouse (. Making/workflows/XXX. Yml), introduce the following configuration file

name: Latest blog post workflow
on:
  schedule:
    # Timer configuration
    - cron: "0 * * * *"
jobs:
  update-readme-with-blog:
    name: Update this repo's README with latest blog posts
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: gautamkrishnar/blog-post-workflow@master
        with:
          max_post_count: "5" Get the number of links
          feed_list: "https://xxx.com/feed.xml" # Blog subscribe address (RSS /Atom format),, comma separated by different addresses
Copy the code

<3> Edit the instructions file readme.md and add references in the appropriate places

<! -- BLOG-POST-LIST:START --> <! -- BLOG-POST-LIST:END -->Copy the code

Based on the above components, the latest article content can be updated regularly. If there is no real-time requirement, in fact, it is sufficient to directly use this scheme. The periodic refresh frequency can be appropriately increased to reduce the error, but in fact, this method is not enough to save resources. Consider setting the repository to automatically update when new articles are updated.

The principle can be summarized as: create a send and receive event separately

The send event is used to “listen for changes in the specified repository branch (the post update operation for the specified blog repository)”, which uses: Repository_dispatch (repository_dispatch) : Create a repository dispatch event

Repository_dispatch sends the curl operation to repository_dispatch whose event type is [xxType]
name: Tigger special repository

on:
  push:
    Trigger Workflow when the Master branch changes
    branches:
      - master
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Send repository dispatch event
        run: | curl -XPOST -u "${{ secrets.USERNAME}}:${{secrets.TOKEN}}" \ -H "Accept: application/vnd.github.everest-preview+json" \ -H "Content-Type: application/json" https://api.github.com/repos/[owner]/[repo]/dispatches \ --data '{"event_type": "xxType"}'          
          Github curl curl curl curl curl curl curl curl
Copy the code

Define a receive event based on a special warehouse automatic push

# Adjust the timer concept to receive events based on the above configuration instructions
name: Latest blog post workflow

on:
  repository_dispatch:
    The type is customizable and needs to match the sent event
    types: [xxType]
  workflow_dispatch:
  
jobs:
  update-readme-with-blog:
    name: Update this repo's README with latest blog posts
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: gautamkrishnar/blog-post-workflow@master
        with:
          max_post_count: "5" Get the number of links
          feed_list: "https://xxx.com/feed.xml" # Blog subscribe address (RSS /Atom format),, comma separated by different addresses
Copy the code