chore: update #1135
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: Frontend Weekly | |
concurrency: | |
group: build_and_deploy | |
cancel-in-progress: true | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build_and_deploy: | |
name: Build and Deploy | |
runs-on: ubuntu-latest | |
# container: | |
# image: garfield998/aliyun-oss-action:latest | |
# credentials: | |
# username: garfield998 | |
# password: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
registry-url: https://registry.npmmirror.com/ | |
### if use Go ### | |
# - name: Set up Go 1.19 | |
# uses: actions/setup-go@v2 | |
# with: | |
# go-version: 1.19 | |
# id: go | |
### if use Yarn ### | |
# - name: Cache node_modules | |
# uses: actions/cache@v3 | |
# id: cache | |
# with: | |
# path: node_modules | |
# key: ${{ runner.os }}-node-${{ hashFiles('yarn.lock') }} | |
# restore-keys: ${{ runner.os }}-node- | |
# - name: Install Dependencies | |
# if: steps.cache.outputs.cache-hit != 'true' | |
# run: yarn install --production --frozen-lockfile | |
# - name: Build | |
# run: yarn build | |
### if use PNPM ### | |
- name: Setup pnpm | |
uses: pnpm/action-setup@v3 | |
with: | |
# 安装最新版本的 PNPM | |
# 注意 PNPM v8 默认启用 lockfile v6 | |
# 正常用 pnpm install 可以刷新 lockfile | |
# 但是 CI 环境装包会带上 `--frozen-lockfile` 参数,不刷新 lcokfile | |
# 如果 lockfile 版本不一致会直接报错 | |
# 此时需要本地手动 pnpm install 刷新 lockfile 再重新构建 | |
version: latest | |
- name: Get pnpm store directory | |
id: pnpm-cache | |
shell: bash | |
run: | | |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT | |
# 注意 PNPM 需要缓存全局 `.pnpm-store` | |
# 工程里面 `node_modules` 只是全局 store 的 symlink | |
# 另外也需要缓存 `node_modules/.cache` | |
# 此目录下包含 Webpack、Babel、ESLint 编译缓存 | |
# 可以用于 build 阶段的构建提速 | |
- name: Cache ~/.pnpm-store | |
uses: actions/cache@v4 | |
env: | |
cache-name: cache-pnpm-store | |
with: | |
path: | | |
${{ steps.pnpm-cache.outputs.STORE_PATH }} | |
node_modules/.cache | |
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-pnpm-store- | |
# 注意 PNPM 缓存的是全局 `.pnpm-store`,工程里面 `node_modules` 只是全局 store 的 symlink | |
# 因此即使缓存命中,仍然需要运行 `pnpm install` 用于创建 symlink | |
# 此处可以加上 `--prefer-offline` 优先用本地缓存 | |
- name: Install Dependencies | |
run: pnpm install --prod --prefer-offline --frozen-lockfile | |
- name: Build | |
run: pnpm build | |
# - name: Login to Docker Hub | |
# uses: docker/login-action@v2 | |
# with: | |
# username: garfield998 | |
# password: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
- name: Upload static assets to Aliyun OSS | |
uses: garfield-dev-team/aliyun-oss-action@v1 | |
with: | |
endpoint: https://oss-cn-hangzhou.aliyuncs.com | |
bucket: frontend-weekly | |
ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }} | |
ACCESS_KEY_SECRET: ${{ secrets.ACCESS_KEY_SECRET }} | |
- name: Deploy | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./build | |
publish_branch: gh-pages | |
full_commit_message: ${{ github.event.head_commit.message }} |