GitHub Action“Generate Snake”在README的预览中未显示GIF
我正在尝试在我的个人资料README上设置“GitHub Contribution Snake”动画。我遵循了好几个教程。运行工作流时,我只看到了GIF或 SVG的那一部分。
这是我的yml文件路径。

# GitHub Action for generating a contribution graph with a snake eating your contributions.
name: Generate Snake
# Controls when the action will run. This action runs every 6 hours.
on:
schedule:
# every 6 hours
- cron: "0 */6 * * *"
# This command allows us to run the Action automatically from the Actions tab.
workflow_dispatch:
# 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:
# Checks repo under $GITHUB_WORKSHOP, so your job can access it
- uses: actions/checkout@v2
# Generates the snake
- uses: Platane/snk@master
id: snake-gif
with:
github_user_name: M1rzoni
# these next 2 lines generate the files on a branch called "output". This keeps the main branch from cluttering up.
gif_out_path: dist/github-contribution-grid-snake.gif
svg_out_path: dist/github-contribution-grid-snake.svg
# show the status of the build. Makes it easier for debugging (if there's any issues).
- run: git status
# Push the changes
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: master
force: true
- uses: crazy-max/[email protected]
with:
# the output branch we mentioned above
target_branch: output
build_dir: dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
这是我在运行工作流后得到的结果。

解决方案
你是在 dist 目录生成这些文件,但随后你的工作流执行了两次不同的推送操作。
你可能不需要
`ad-m/github-push-action`
这个将内容推送到 master 的步骤。生成的蛇形文件应该只发布到 output 分支。
移除此步骤:
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: master
force: true
然后保留将 dist 推送到 output 的GitHub Pages部署步骤。
另外,请确保你的README指向来自 output 分支的生成文件,例如:
`
或者使用原始URL:
https://raw.githubusercontent.com/M1rzoni/M1rzoni/output/github-contribution-grid-snake.svg
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。