# https://github.com/actions/create-release
name: release

on:
  push:
    tags:
      - 'v*'
  workflow_dispatch:

# 设置上海时区
env:
  TZ: Asia/Shanghai

jobs:
  publish:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [ latest ]
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Use Node.js 🚀
        with:
          node-version: '16.15.0'
          registry-url: https://registry.npmjs.org/
        uses: actions/setup-node@v2
      - name: Cache yarn modules  🚀
        uses: actions/cache@v2
        env:
          cache-name: cache-yarn-modules
        with:
          path: '**/node_modules'
          key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-
      - run: yarn install && npm publish --access=public
        env:
          NODE_AUTH_TOKEN: ${{secrets.npm_token}}
      - name: Prepare the changelog from the tag message
        run: |
          VERSION=${GITHUB_REF/refs\/tags\//}
          echo "Setting release version to $VERSION"
          echo "release_version=$VERSION" >> $GITHUB_ENV
