From cc3545c3f54151cef118033a496c300045184e8e Mon Sep 17 00:00:00 2001 From: snowtafir Date: Sun, 4 Aug 2024 15:26:56 +0800 Subject: [PATCH] add github action to compile --- .github/workflows/build-deploy.yaml | 91 +++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 .github/workflows/build-deploy.yaml diff --git a/.github/workflows/build-deploy.yaml b/.github/workflows/build-deploy.yaml new file mode 100644 index 0000000..d41f688 --- /dev/null +++ b/.github/workflows/build-deploy.yaml @@ -0,0 +1,91 @@ +name: 构建和部署 + +on: + push: + branches: + - dev3 + +permissions: + contents: write + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + steps: + - name: 🚀 检出代码 + uses: actions/checkout@v4 + + - name: 🏗️ 安装 Node.js + uses: actions/setup-node@v4 + with: + node-version: 18 + + - name: 📦 安装 yarn + run: npm install -g yarn + + - name: 📦 列出node版本 + run: | + pwd + node -v + + - name: 📦 列出npm版本 + run: npm -v + + - name: 📦 列出yarn版本 + run: yarn -v + + - name: 🔧 安装依赖 + run: yarn install + + - name: 🛠️ 构建项目 + run: yarn build + + - name: 📂 创建临时目录 + run: mkdir ./../temp_dist/ + + - name: 📄 列出当前目录文件 + run: ls -l + + - name: 🚚 移动构建文件到临时目录 + run: mv ./dist/* ../temp_dist/ + + - name: 🛠️ 配置Git用户信息 + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + + - name: 🔄 获取最新代码 + run: git fetch + + - name: 🔀 切换到main3分支 + run: git checkout main3 + + - name: 🔄 拉取main3分支最新代码 + run: git pull origin main3 + + - name: 📄 列出main3分支文件 + run: ls -l + + - name: 🧹 清理当前目录(保留.git) + run: find . -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} + + + - name: 🚚 从临时目录移动文件到当前目录 + run: mv ./../temp_dist/* ./ + + - name: 🗑️ 删除临时目录 + run: rm -rf ./../temp_dist + + - name: 📄 列出当前目录文件 + run: ls -l + + - name: 📥 添加所有更改到Git + run: git add . + + - name: 💬 提交更改 + run: git commit -m "${{ github.event.head_commit.message }}" + + - name: 🚀 推送到main3分支 + run: git push origin main3 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}