94 lines
2.8 KiB
YAML
Raw Normal View History

2024-05-11 07:03:56 +08:00
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
2024-05-11 11:44:49 +08:00
name: halo-theme-dream2.0-plus CI
2024-05-11 07:03:56 +08:00
on:
push:
2024-05-11 10:59:55 +08:00
branches: [ "master", "dev" ]
2024-07-11 13:39:48 +08:00
paths: ["theme.yaml"]
2024-07-13 10:34:47 +08:00
workflow_dispatch:
2024-05-11 07:03:56 +08:00
jobs:
build:
2024-07-11 10:01:47 +08:00
runs-on: ubuntu-latest
2024-05-11 07:03:56 +08:00
strategy:
matrix:
2024-07-11 11:24:01 +08:00
node-version: [20.x]
2024-05-11 07:03:56 +08:00
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
2024-05-11 11:08:04 +08:00
# 迁出代码
2024-05-11 07:03:56 +08:00
- uses: actions/checkout@v4
2024-05-11 11:08:04 +08:00
# 确定构建分支类型
2024-05-11 10:59:55 +08:00
- name: Determine Branch Type
id: determine_branch_type
run: |
branch_type=unknown
if [[ $GITHUB_REF == refs/heads/master ]]; then
branch_type=master
elif [[ $GITHUB_REF == refs/heads/dev ]]; then
branch_type=dev
fi
2024-05-11 11:19:51 +08:00
echo "branch_type=$branch_type" >> $GITHUB_ENV
2024-05-11 10:59:55 +08:00
shell: bash
2024-05-11 11:08:04 +08:00
# 确定构建版本
2024-05-11 09:53:14 +08:00
- name: version
id: version
run: |
2024-07-11 13:39:48 +08:00
version=$(grep 'version:' theme.yaml | sed 's/.*:\s*//')
2024-05-11 09:53:14 +08:00
echo "version=$version" >> $GITHUB_ENV
2024-12-27 15:45:42 +08:00
2024-05-11 07:03:56 +08:00
- name: Use Node.js ${{ matrix.node-version }}
2024-05-11 08:07:20 +08:00
uses: actions/setup-node@v4
2024-05-11 07:03:56 +08:00
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
2024-12-27 15:45:42 +08:00
registry-url: https://registry.npmjs.org/
2024-05-11 07:07:41 +08:00
- name: Install dependencies
2024-05-11 07:08:21 +08:00
run: npm install
2024-12-27 15:45:42 +08:00
2024-12-29 09:22:26 +08:00
# 构建
- name: Build
2024-12-27 16:32:09 +08:00
run: npm run release --tag=${{ env.version }}
2024-05-11 10:15:05 +08:00
2024-07-12 21:03:34 +08:00
# 如果是master分支创建latest的Release否则创建 预览版
2024-05-11 10:15:05 +08:00
- name: Create Release
id: create_release
uses: actions/create-release@latest
env:
2024-05-11 10:26:14 +08:00
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2024-05-11 10:15:05 +08:00
with:
2024-05-11 10:45:49 +08:00
tag_name: ${{ env.version }}
release_name: ${{ env.version }}
2024-05-11 10:15:05 +08:00
body: ${{ github.event.commits[0].message }}
draft: false
2024-07-12 21:03:34 +08:00
prerelease: ${{ env.branch_type != 'master' }}
2024-05-11 10:15:05 +08:00
2024-07-12 21:03:34 +08:00
# 创建Release Asset
2024-05-11 10:15:05 +08:00
- name: Upload Release Asset
2024-07-11 11:48:07 +08:00
id: upload_asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
2024-07-11 13:19:27 +08:00
upload_url: ${{ steps.create_release.outputs.upload_url }}
2024-07-11 11:48:07 +08:00
asset_path: ./dist/halo-theme-dream2.0-plus.zip
2024-07-29 08:06:50 +08:00
asset_name: halo-theme-dream2.0-plus-V${{ env.version }}.zip
2024-07-11 11:48:07 +08:00
asset_content_type: application/zip
2024-12-29 09:22:26 +08:00
2024-12-29 09:34:36 +08:00
- name: npm cache clean
if: ${{ env.branch_type == 'master' }}
run: npm ci
- name: npm cache clean
2024-12-29 09:23:50 +08:00
if: ${{ env.branch_type == 'master' }}
2024-12-29 09:22:26 +08:00
run: npm ci
- name: npm publish
2024-12-29 09:23:50 +08:00
if: ${{ env.branch_type == 'master' }}
2024-12-29 09:22:26 +08:00
run: npm publish --tag=latest
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}