Skip to content

Commit

Permalink
ci: 添加自动部署action
Browse files Browse the repository at this point in the history
  • Loading branch information
cp3hnu committed Sep 25, 2024
1 parent 9a87433 commit 4145422
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 37 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -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)
36 changes: 0 additions & 36 deletions .github/workflows/npm-publish-github-packages.yml

This file was deleted.

19 changes: 19 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -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://<USERNAME>.github.io
git push -f git@github.com:cp3hnu/Sudoku.git main:gh-pages

cd -
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions vue.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { defineConfig } = require("@vue/cli-service");
module.exports = defineConfig({
transpileDependencies: true,
publicPath: process.env.NODE_ENV === "production" ? "/Sudoku/" : "/",
});

0 comments on commit 4145422

Please sign in to comment.