Skip to content

feat: 更换github pages部署方式,支持actions部署 #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 21 additions & 42 deletions .github/workflows/CD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
push:
branches:
- next
- refactor/deploy
workflow_dispatch:

# 环境变量
Expand All @@ -17,12 +18,21 @@ env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

# 设置 GITHUB_TOKEN 的权限,以允许部署到 GitHub Pages
permissions:
contents: read
pages: write
id-token: write

jobs:
# 部署到Github-Pages
deploy-github:
name: 部署到Github-Pages
if: github.repository == '142vip/JavaScriptCollection'
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
if: github.repository == '142vip/JavaScriptCollection'

steps:
- name: Checkout Code
Expand Down Expand Up @@ -52,43 +62,19 @@ jobs:
run: |
./scripts/ci

# 运行构建脚本
- name: Build VuePress Site
run: |
./scripts/bundle build_proxy

# 将README.md同步,利于github pages分支展示
- name: Add Readme.md To Dist
run: |
cp -f README.md docs/.vuepress/dist
# 编译 打包成dist
- name: Build with VitePress
run: pnpm build:proxy

- name: Check GitHub Pages status
uses: crazy-max/ghaction-github-status@v3
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
pages_threshold: major_outage
path: docs/.vuepress/dist

# 获取Git提交信息
- name: Get Commit Info
id: gitInfo
run: |
echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
echo "author=$(git log -1 --pretty=%an)" >> $GITHUB_OUTPUT
echo "email=$(git log -1 --pretty=%ae)" >> $GITHUB_OUTPUT

# 参考:https://github.com/marketplace/actions/github-pages
- name: Deploy To GitHub Page
uses: crazy-max/ghaction-github-pages@v3
with:
target_branch: pages/github
build_dir: docs/.vuepress/dist
commit_message: |
chore(sync): v${{steps.gitInfo.outputs.version}}

部署地址: https://142vip.github.io/JavaScriptCollection
committer: ${{steps.gitInfo.outputs.author}}<${{steps.gitInfo.outputs.email}}>
author: Mr·Sync
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# 部署
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

# 部署到vercel平台
# deploy-vercel:
Expand Down Expand Up @@ -134,13 +120,6 @@ jobs:
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0

# ## 打成压缩包
- name: Create Zip Package
run: |
zip -r JavaScriptCollection.zip . \
-x "node_modules/*" \
-x "*.git*"

# 安装PNPM
- name: PNPM Install
uses: pnpm/action-setup@v4
Expand Down
8 changes: 2 additions & 6 deletions docs/deploy-backup.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const SupportScripts = {
`,
// 镜像存在即删除
`
if [ "$(docker images -q ${imageName} 2> /dev/null)" != "" ];then
if [ "$(docker images -q ${imageName} 2> /dev/null)" != "" ];then
docker rmi ${imageName}
exit 0;
else
Expand All @@ -66,10 +66,8 @@ const SupportScripts = {
]
}


const deployName = process.argv[2]


function getDeployCommand() {
let deployCommand = SupportScripts.Ali
// 部署到阿里云服务器
Expand All @@ -83,12 +81,10 @@ function getDeployCommand() {
return deployCommand
}


// 执行
;(async() => {
;(async () => {
const deployCommand = getDeployCommand()
// console.log(deployCommand)
await execShell(deployCommand)
})()

```
17 changes: 5 additions & 12 deletions docs/microservice/docker-backup.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

# Docker脚本备份


```js
#!/usr/bin/env node

Expand All @@ -15,7 +13,6 @@
const { execShell } = require('./.exec')
const scriptName = process.argv[2]


/**
* 网络基础信息
* - 网络名称
Expand Down Expand Up @@ -66,8 +63,8 @@ const SupportScriptsInNetWork = {
rm: [
// 参数校验
`
if test -z "${dockerNetworkInfo.defaultName}";then
echo "参数错误 网络名称不能为空。脚本执行eg: bash xxx.sh rm 网络名称"
if test -z "${dockerNetworkInfo.defaultName}";then
echo "参数错误 网络名称不能为空。脚本执行eg: bash xxx.sh rm 网络名称"
exit 1;
fi
`,
Expand All @@ -90,7 +87,6 @@ const SupportScriptsInNetWork = {
`
}


function getContainerCommand() {
const name = process.argv[3]

Expand All @@ -110,7 +106,6 @@ function getImageCommand() {
return SupportScriptsInImage.ps
}


function getNetworkCommand() {
const name = process.argv[3]
if (name in SupportScriptsInNetWork) {
Expand All @@ -119,7 +114,6 @@ function getNetworkCommand() {
return SupportScriptsInNetWork.ls
}


// 支持的命令
const SupportScripts = {
ls: 'docker network ls',
Expand All @@ -139,8 +133,8 @@ const SupportScripts = {
rm: [
// 参数校验
`
if test -z "${dockerNetworkInfo.defaultName}";then
echo "参数错误 网络名称不能为空。脚本执行eg: bash xxx.sh rm 网络名称"
if test -z "${dockerNetworkInfo.defaultName}";then
echo "参数错误 网络名称不能为空。脚本执行eg: bash xxx.sh rm 网络名称"
exit 1;
fi
`,
Expand Down Expand Up @@ -175,9 +169,8 @@ function getCommand() {
}
}


// 执行
;(async() => {
;(async () => {
const command = getCommand(scriptName)
await execShell(command)
})()
Expand Down