diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..d4ad081 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,32 @@ +name: Deploy to GitHub Pages + +on: + push: + branches: + - main # 当推送到 main 分支时触发 + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: "16" # 你可以根据项目需要调整 Node.js 版本 + + - name: Install dependencies + run: yarn install # 如果使用的是其他包管理工具,调整命令 + + - name: Build the project + run: npm run build # 构建项目,确保构建输出到指定目录(如 ./build 或 ./dist) + + - name: Deploy to GitHub Pages + uses: peaceiris/actions-gh-pages@v3 # 用于推送到 gh-pages 分支 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} # 内置 GitHub Token,用于授权操作 + publish_branch: gh-pages # 部署的分支 + publish_dir: ./build # 构建后的输出目录,根据项目调整(如 ./dist) diff --git a/.github/workflows/npm-publish-github-packages.yml b/.github/workflows/npm-publish-github-packages.yml deleted file mode 100644 index ea2d329..0000000 --- a/.github/workflows/npm-publish-github-packages.yml +++ /dev/null @@ -1,36 +0,0 @@ -# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created -# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages - -name: Node.js Package - -on: - release: - types: [created] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: 20 - - run: npm ci - - run: npm test - - publish-gpr: - needs: build - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: 20 - registry-url: https://npm.pkg.github.com/ - - run: npm ci - - run: npm publish - env: - NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..40a4996 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env sh + +# 确保脚本抛出遇到的错误 +set -e + +# 生成静态文件 +npm run build + +# 进入生成的文件夹 +cd dist + +git init +git add -A +git commit -m 'deploy' + +# 如果发布到 https://.github.io +git push -f git@github.com:cp3hnu/Sudoku.git main:gh-pages + +cd - \ No newline at end of file diff --git a/package.json b/package.json index fc0942c..8b2d547 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "build": "vue-cli-service build", "test:unit": "vue-cli-service test:unit", "test:e2e": "vue-cli-service test:e2e", - "lint": "vue-cli-service lint" + "lint": "vue-cli-service lint", + "deploy": "./deploy.sh" }, "dependencies": { "core-js": "^3.8.3", diff --git a/vue.config.js b/vue.config.js index 0aed899..bc1625e 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,4 +1,5 @@ const { defineConfig } = require("@vue/cli-service"); module.exports = defineConfig({ transpileDependencies: true, + publicPath: process.env.NODE_ENV === "production" ? "/Sudoku/" : "/", });