+
80
-

github pages如何实现commit push提交后自动更新部署?

github pages如何实现commit push提交后自动更新部署?


网友回复

+
0
-

可以使用GitHub Actions 实现:

GitHub Actions 是 GitHub 提供的一项强大的持续集成和持续交付(CI/CD)功能。通过使用 GitHub Actions,你可以在代码库中自动化各种任务,如构建、测试、部署等。它允许你将工作流定义为一系列的任务,这些任务可以响应特定的事件自动运行。

概念解析:Workflows(工作流):工作流是一组按顺序执行的 Jobs,用于定义一系列任务的执行顺序和逻辑。

Events(事件):事件是触发工作流执行的条件,例如代码推送、问题创建、标签创建等。

Jobs(任务):一个工作流由多个任务组成,每个任务可以包含多个步骤(Steps),步骤可以是可执行的 shell 脚本或预定义的 Action。

Actions(动作):动作是预定义的任务单元,可以是一个复杂的任务,用于封装可重用的逻辑。

Runners(运行器):运行器是执行工作流的机器,由 GitHub 提供。

工作流由一个或多个任务组成,每个任务可以包含多个步骤和动作。工作流需要被一个或多个事件触发,并由运行器执行。当工作流成功执行后,它将实现预定的目标。

在项目的根目录下新建.github/workflows目录static.yml,内容如下:

# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages

on:
  # Runs on pushes targeting the default branch
  push:
    branches: ["main"]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
  group: "pages"
  cancel-in-progress: false

jobs:
  # Single deploy job since we're just deploying
  deploy:
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Setup Pages
        uses: actions/configure-pages@v4
      - name: Upload artifact
        uses: actions/upload-pages-artifact@v3
        with:
          # Upload entire repository
          path: '.'
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4

上传到git后打开action,就可以看到这个流程了,运行就好了

800_auto

设置page下的build and deployment,是只当分支有push更新时自动build触发

800_auto

我知道答案,我要回答