Deploy #1838
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy | |
on: | |
push: | |
branches: | |
- main | |
schedule: | |
- cron: "0 4,16 * * *" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: | |
- 16.x | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
# 令 GitHub 在 git clone 和 git checkout 后「忘记」使用的 credentials。 | |
# 如果之后需要以另外的身份(如你的 GitHub Bot)执行 git push 操作时(如部署到 GitHub Pages),必须设置为 false。 | |
persist-credentials: false | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
# 缓存 node_modules,缓存机制参见 GitHub 文档:https://help.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows | |
- name: Cache node_modules | |
uses: actions/cache@v4 # 使用 GitHub 官方的缓存 Action。 | |
env: | |
cache-name: blogroll-node-modules | |
with: | |
path: node_modules | |
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }} # 使用 package-lock.json 的 Hash 作为缓存的 key。也可以使用 package.json 代替 | |
# Wrangler 在构建时会在 workers-site 目录下执行 npm i,因此也要缓存这里的 node_modules | |
- name: Cache workers-site/node_modules | |
uses: actions/cache@v4 | |
env: | |
cache-name: workers-site-node-modules | |
with: | |
path: workers-site/node_modules | |
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('workers-site/package-lock.json') }} | |
- run: npm i # 执行 Blogroll 的依赖安装 | |
- run: npm run gen # 相当于 node index.js,生成 opml.xml,opml.json 和 data.json | |
- run: npm run build | |
- name: Deploy to Cloudflare Workers | |
uses: cloudflare/wrangler-action@v3 | |
with: | |
apiToken: ${{ secrets.CF_WORKERS_TOKEN }} # 前一步设置的 Secrets 的名称 | |
# Wrangler Action 也支持使用传统的 Global API Token + Email 的鉴权方式,但不推荐 |