【发布时间】:2022-01-13 14:17:17
【问题描述】:
我有一个包含 api 文档的 github 存储库。在与 master 合并时,我想使用 github 操作来做两件事:
- “构建” - 使用 python 脚本更新 index.html 文件
- “部署” - 将 repo 的内容同步到 S3
这是(简化的)回购结构:
.github/
|-- workflows/
|-- main.yml
|-- build.py
dist/
|-- index.html
build.py 是 Python 脚本,它将通过替换 dist/index.html 中的一些变量来“构建”模板。 dist 文件夹的内容随后会使用此 github 操作同步到 AWS S3:
name: Upload Website
on:
push:
branches:
- master
jobs:
# updates index.html:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Run a one-line script
run: python ./.github/workflows/build.py
...
- name: commit changed files
run: git commit -m "Auto adding config files"
- name: fetch from master
run: git fetch origin master
- name: push code to master
run: git push origin HEAD:master
# deploys latest version to s3:
deploy:
runs-on: ubuntu-latest
steps:
uses: actions/checkout@v1
- name: Deploy static site to S3 bucket
run: aws s3 sync ./dist <BUCKET DESTINATION>
部署部分本身可以正常工作,但我在构建部分遇到问题。这会导致无限循环吗?该操作设置为在推送到 master 时运行,但该操作还将更新的模板推送到 master。如果是,我该如何避免这种情况?
我正在关注 this 构建部分的示例。
【问题讨论】:
-
构建部件的目的是什么?
标签: github github-actions