From 8e9179a8bb483c82b5ad42da91a9bce977eec85e Mon Sep 17 00:00:00 2001 From: WindyDante <125888129+WindyDante@users.noreply.github.com> Date: Fri, 11 Oct 2024 12:17:33 +0800 Subject: [PATCH] try deploy myself action --- .github/workflows/deploy.yml | 50 ++++++++++++++++++++++++++++++++++ .github/workflows/main.yml | 53 ------------------------------------ package.json | 1 + 3 files changed, 51 insertions(+), 53 deletions(-) create mode 100644 .github/workflows/deploy.yml delete mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..ce3b438 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,50 @@ +name: Build and Deploy +on: + push: + branches: + - master # 这里表示push到master分支就会触发流程,请根据实际情况修改 + pull_request: + branches: + - master + +permissions: + contents: write + +env: + TZ: Asia/Shanghai + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + # 这是github官方的一个action,用于clone该仓库的源码到工作流中, + - name: Checkout 🛎️ + uses: actions/checkout@v4 + + # 安装node + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: 20.17.0 + cache: yarn + + - name: Install and Build + run: | + yarn install + yarn deploy-build + + - name: 获取当前时间 + id: time + shell: bash + run: echo "time=$(date +'%Y-%m-%d %H:%M:%S')" >> ${GITHUB_OUTPUT} + + # 部署 + - name: Deploy 🚀 # 部署 + uses: JamesIves/github-pages-deploy-action@v4 + with: + branch: gh-pages # 部署后提交到那个分支 + folder: docs # 存放build后产物的目录 + commit-message: 发布于:${{ steps.time.outputs.time }} # 提交信息 + # token: ${{ secrets.ACCESS_TOKEN }} # token 同仓库可以不填 + # repository-name: kongxiangyiren/kongxiangyiren.github.io #要部署的仓库 请根据实际情况修改 为 用户名/仓库名 同仓库可以不填 + diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index e47b38a..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: CI Workflow - -on: - push: - branches: - - master - pull_request: - branches: - - master - -permissions: - contents: read - pages: write - id-token: write - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - fetch-depth: 0 # 确保拉取完整的提交历史 - - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: '16' - - - name: Install dependencies - run: npm ci # 使用 ci 命令清理并安装依赖,确保是最新的 - - - name: Build project - run: npm run build - - - name: List build output - run: ls -R docs # 检查 docs 目录是否存在并列出内容 - - - name: Verify docs directory exists - run: | - if [ ! -d "docs" ]; then - echo "docs directory not found." - exit 1 - fi - - - name: Deploy to GitHub Pages - uses: JamesIves/github-pages-deploy-action@v4 - with: - branch: gh-pages # 部署到 gh-pages 分支 - folder: docs # 确保你要部署的文件夹 - clean: true # 清理旧的部署文件 - ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} diff --git a/package.json b/package.json index 851ab9d..1d7e0d3 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "type": "module", "homepage": "https://WindyDante.github.io/vite-project", "scripts": { + "deploy-build": "hexo clean && hexo generate", "dev": "vite", "build": "vite build", "preview": "vite preview"