GitHub主页贪吃蛇

背景介绍

	看见别人仓库的热力值贪吃蛇狠狠心动了然后就研究了下实现方法其实就是使用github的工作流来完成获取数据和动画加载的

下面是我研究的一种实现方法

实现方法

	1. 首先建立一个和自己github用户名相同的公开仓库这个仓库中的README.md文件会默认显示在你的github主页上
	2. 在仓库中建立的.github/workflows下建立一个main.yml的文件内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# GitHub Action for generating a contribution graph with a snake eating your contributions.
name: Generate Snake

# Controls when the action will run.
on:
schedule:
# every 12 hours
- cron: "0 */12 * * *"

# This command allows us to run the Action automatically from the Actions tab.
workflow_dispatch:

# Also run on every push on the master branch
push:
branches:
- main

# The sequence of runs in this workflow:
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Clone repo
uses: actions/checkout@v3

- name: Generate the snake files in './dist/'
uses: Platane/snk@v3
id: snake-gif
with:
github_user_name: ${{ github.repository_owner }}
outputs: |
dist/github-contribution-grid-snake.svg
dist/github-contribution-grid-snake-dark.svg?palette=github-dark
dist/github-contribution-grid-snake.gif?color_snake=orange&color_dots=#bfd6f6,#8dbdff,#64a1f4,#4b91f1,#3c7dd9
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Show build status
run: git status

- name: Push new files to the output branch
uses: crazy-max/ghaction-github-pages@v3.1.0
with:
target_branch: output
build_dir: dist
commit_message: Update snake animations
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

	3.开启工作流访问权限点击Settings/Actions/Genaral选项卡下的Workflow permissions基于读写权限否则会显示权限不足
	4.在你仓库中修改README.md添加如下内容

1
<img alt="snake eating my contributions" src="https://raw.githubusercontent.com/youer_username/youer_username/output/github-contribution-grid-snake.svg" />