Skip to content

Commit

Permalink
test: github actions yml
Browse files Browse the repository at this point in the history
  • Loading branch information
yanfeng.guan committed May 14, 2024
1 parent b2e50bc commit 14869ca
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 33 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: learn-github-actions
run-name: ${{ github.actor }} is learning GitHub Actions
on: [push]
jobs:
check-bats-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm install -g bats
- run: bats -v
48 changes: 48 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1 +1,49 @@

# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
# github actions 中文文档 https://docs.github.com/cn/actions/getting-started-with-github-actions

name: deploy for dev

on:
push:
branches:
- 'dev' # 只针对 dev 分支
paths:
- '.github/workflows/*'
# - '__test__/**' # dev 不需要立即测试
- 'src/**'
- 'Dockerfile'
- 'docker-compose.yml'
- 'bin/*'

jobs:
deploy-dev:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: set ssh key # 临时设置 ssh key
run: |
mkdir -p ~/.ssh/
echo "${{secrets.WFP_ID_RSA}}" > ~/.ssh/id_rsa # secret 在这里配置 https://github.com/imooc-lego/biz-editor-server/settings/secrets
chmod 600 ~/.ssh/id_rsa
ssh-keyscan "182.92.xxx.xxx" >> ~/.ssh/known_hosts
- name: deploy # 部署
run: |
ssh [email protected] "
# 【注意】用 work 账号登录,手动创建 /home/work/imooc-lego 目录
# 然后 git clone https://username:[email protected]/imooc-lego/biz-editor-server.git -b dev (私有仓库,使用 github 用户名和密码)
# 记得删除 origin ,否则会暴露 github 密码
cd /home/work/imooc-lego/biz-editor-server;
git remote add origin https://wangfupeng1988:${{secrets.WFP_PASSWORD}}@github.com/imooc-lego/biz-editor-server.git;
git checkout dev;
git pull origin dev; # 重新下载最新代码
git remote remove origin; # 删除 origin ,否则会暴露 github 密码
# 启动 docker
docker-compose build editor-server; # 和 docker-compose.yml service 名字一致
docker-compose up -d;
"
- name: delete ssh key # 删除 ssh key
run: rm -rf ~/.ssh/id_rsa
1 change: 1 addition & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# github actions 中文文档 https://docs.github.com/cn/actions/getting-started-with-github-actions

name: test
run-name: ${{ github.actor }} is learning GitHub Actions

on:
push:
Expand Down
30 changes: 0 additions & 30 deletions .github/workflows/main.yml

This file was deleted.

13 changes: 12 additions & 1 deletion CD_CD.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
learn for using Github Actions

- copy from [gitee repo: editor-server](https://gitee.com/zhelingwang/editor-server.git)
- commit message: refactor: add comment and adjust commitlint cmd
- copy at commit message: refactor: add comment and adjust commitlint cmd

## 主要内容
- 使用 giub actions 进行CI/CD
Expand All @@ -13,6 +13,17 @@ learn for using Github Actions
## Github Actions
github提供的CI/CD平台, 用于创建工作流程,当你执行 push 或 merge 到 master 时自动执行构建, 测试或部署到生产环境.

划分两个workflows:
1. test.yml: dev分支, 自动构建, 部署到测试机器
2. deploy.yml: master分支, 自动化测试
3. 每当创建一个 v*.*.* 格式的 release 或 tag 版本时, 自动部署应用, 支持回滚

### 基本概念
- workflows: 包含若干个任务且可配置的自动化流程, 通过一个 yaml 文件来定义配置
- 构成workflow几个基本组件以及流程: events -> runner to run jobs -> several steps
- 上述流程都是多对一关系




## Docker
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"sync:m2d": "cross-env NODE_ENV=development node ./src/scripts/sync-model2db.js",
"lint": "npx eslint",
"lint/fix": "npx eslint --fix \"src/**/*.js\"",
"commitlint": "commitlint --edit",
"prepare": "husky"
"commitlint": "commitlint --edit"
},
"dependencies": {
"debug": "^4.1.1",
Expand Down

0 comments on commit 14869ca

Please sign in to comment.