97 lines
2.9 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-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-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-05-11 07:07:41 +08:00
- name: Install dependencies
2024-05-11 07:08:21 +08:00
run: npm install
2024-05-11 09:27:49 +08:00
# Actions构建
2024-05-11 07:18:27 +08:00
- name: Build
2024-05-11 09:53:14 +08:00
run: npm run actions --tag=${{ env.version }}
2024-05-11 10:15:05 +08:00
2024-05-11 10:42:40 +08:00
# 上传构建产物zip
- name: Upload artifacts
2024-07-11 11:15:10 +08:00
uses: actions/upload-artifact@v3
2024-05-11 10:42:40 +08:00
with:
name: halo-theme-dream2.0-plus
2024-05-17 08:16:26 +08:00
path: dist-actions
2024-05-11 10:42:40 +08:00
2024-05-11 11:08:04 +08:00
# 如果是master分支创建Release
2024-05-11 10:15:05 +08:00
- name: Create Release
2024-05-11 11:18:06 +08:00
if: ${{ env.branch_type == 'master' }}
2024-05-11 10:15:05 +08:00
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
prerelease: false
2024-07-11 11:47:36 +08:00
# # 如果是master分支创建Release Asset
# - name: Upload Release Asset
# if: ${{ env.branch_type == 'master' }}
# uses: dwenegar/upload-release-assets@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# release_id: ${{ steps.create_release.outputs.id }}
# assets_path: |
# dist
2024-05-11 11:08:04 +08:00
# 如果是master分支创建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
if: ${{ env.branch_type == 'master' }}
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
asset_name: halo-theme-dream2.0-plus.zip
asset_content_type: application/zip