Github主页添加贪吃蛇小组件

本文介绍了如何使用GitHubActions创建一个自动化脚本,从GitHub用户贡献图生成SVG动画,并将其推送到个人主页。步骤包括设置仓库、创建snake.yml文件、配置工作流程并更新README。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

效果图

1. 创建仓库

首先在github创建一个与用户名同名的仓库,这样仓库的 README 就会自动展示在我们的个人首页。创建时勾选创建 README.md 文件,后边我们要在 README 中写入内容。

2. 创建文件、文件夹
  • 创建 snake.yml 文件

目录结构如下图所示

snake.yml 代码如下:

name: generate animation

on:
  # run automatically every 24 hours
  schedule:
    - cron: "0 */24 * * *" 
  
  # allows to manually run the job at any time
  workflow_dispatch:
  
  # run on every push on the master branch
  push:
    branches:
    - main
    
  

jobs:
  generate:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    
    steps:
      # generates a snake game from a github user (<github_user_name>) contributions graph, output a svg animation at <svg_out_path>
      - name: generate github-contribution-grid-snake.svg
        uses: Platane/snk/svg-only@v3
        with:
          github_user_name: ${{ github.repository_owner }}
          outputs: |
            dist/github-contribution-grid-snake.svg
            dist/github-contribution-grid-snake-dark.svg?palette=github-dark
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          
          
      # push the content of <build_dir> to a branch
      # the content will be available at https://raw.githubusercontent.com/<github_user>/<repository>/<target_branch>/<file> , or as github page
      - name: push github-contribution-grid-snake.svg to the output branch
        uses: crazy-max/ghaction-github-pages@v3.1.0
        with:
          target_branch: output
          build_dir: dist
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3. 修改README

README.md 内容:

![snake](https://raw.githubusercontent.com/仓库名/仓库名/output/github-contribution-grid-snake.svg)

注意:将链接中的仓库名替换为自己的仓库名(即用户名)

4. 修改权限执行工作流
  • 先按下图修改 Actions 的权限

修改权限

  • 然后执行 Run Workflow

Run Workflow

  • 执行成功

执行成功

  • 回到首页查看效果

效果


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端每日三省

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值