Skip to content

Commit f184303

Browse files
author
hubert
committed
chore: workflows change
1 parent d90bdf9 commit f184303

File tree

3 files changed

+34
-30
lines changed

3 files changed

+34
-30
lines changed

.github/workflows/check-pr-title.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ on:
77
- edited
88
- synchronize
99

10+
11+
permissions:
12+
statuses: write
13+
1014
jobs:
1115
lint:
12-
runs-on: ubuntu-latest
13-
permissions:
14-
statuses: write
16+
runs-on: ubuntu-latest
1517
steps:
1618
- uses: aslafy-z/conventional-pr-title-action@v3
1719
with:

.github/workflows/commitlint.yml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
# This is a basic workflow to help you get started with Actions
2-
31
name: Check Commit spec
42

5-
# Controls when the action will run.
63
on:
7-
# Triggers the workflow on push or pull request events but only for the formily_next branch
84
push:
95
branches: [master]
106
pull_request:
@@ -13,17 +9,18 @@ on:
139
# Allows you to run this workflow manually from the Actions tab
1410
workflow_dispatch:
1511

16-
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
12+
13+
permissions:
14+
contents: read
15+
pull-requests: read
16+
1717
jobs:
18-
# This workflow contains a single job called "build"
1918
commitlint:
20-
# The type of runner that the job will run on
2119
runs-on: ubuntu-latest
22-
23-
# Steps represent a sequence of tasks that will be executed as part of the job
2420
steps:
25-
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
26-
- uses: actions/checkout@v2
21+
- uses: actions/checkout@v3
2722
with:
2823
fetch-depth: 0=
2924
- uses: wagoid/commitlint-github-action@v3
25+
env:
26+
NODE_PATH: ${{ github.workspace }}/node_modules

.github/workflows/deploy.yml

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ on:
1616
pull_request:
1717
branches: ['master']
1818

19+
env:
20+
REGISTRY: ghcr.io
21+
IMAGE_REPOSITORY: $(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
22+
DOCKER_COMPOSE_DIR: /opt/pomelo
23+
24+
permissions:
25+
contents: read
26+
packages: write
27+
1928
jobs:
2029
cache:
2130
runs-on: ubuntu-latest
@@ -52,7 +61,7 @@ jobs:
5261
- name: Build Submodules
5362
if: steps.submodules-cache.outputs.cache-hit != 'true'
5463
run: yarn build:submodules
55-
build:
64+
docker-build:
5665
needs: cache
5766
runs-on: ubuntu-latest
5867
environment:
@@ -65,9 +74,9 @@ jobs:
6574
- name: Login to GitHub Container Registry
6675
uses: docker/login-action@v1
6776
with:
68-
registry: ghcr.io # 声明镜像源
77+
registry: ${{ env.REGISTRY }} # 声明镜像源
6978
username: ${{ github.actor }} # 当前github 用户名
70-
password: ${{ secrets.GITHUB_TOKEN }} # 需要去 https://github.com/settings/tokens 生成一个 名为 token,注意此token 需要读写 packages 等权限
79+
password: ${{ secrets.GITHUB_TOKEN }} # 当前github token
7180
- name: Set up Node.js
7281
uses: actions/setup-node@v2
7382
with:
@@ -91,13 +100,11 @@ jobs:
91100
- name: Build the Docker image
92101
run:
93102
| # 使用 上一步写的 Dockerfile 构建镜像并发布到私有仓库; 发布完成可以去 https://github.com/aceHubert?tab=packages 查看
94-
docker build . --file Dockerfile --target deploy --cache-from ghcr.io/${{ env.IMAGE_REPOSITORY }}:latest --build-arg BUILD_IGNORE=true --build-arg BUILDKIT_INLINE_CACHE=1 --tag ghcr.io/${{ env.IMAGE_REPOSITORY }}:latest --tag ghcr.io/${{ env.IMAGE_REPOSITORY }}:${{ github.run_id }}-${{ github.ref_name }}
95-
docker push ghcr.io/${{ env.IMAGE_REPOSITORY }}:${{ github.run_id }}-${{ github.ref_name }}
96-
docker push ghcr.io/${{ env.IMAGE_REPOSITORY }}:latest
97-
env:
98-
IMAGE_REPOSITORY: $(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
99-
deploy:
100-
# needs: build
103+
docker build . --file Dockerfile --target deploy --cache-from ${{ env.REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:latest --build-arg BUILD_IGNORE=true --build-arg BUILDKIT_INLINE_CACHE=1 --tag ${{ env.REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:latest --tag ${{ env.REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:${{ github.run_id }}
104+
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:${{ github.run_id }}
105+
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:latest
106+
ssh-deploy:
107+
needs: docker-build
101108
runs-on: ubuntu-latest
102109
environment:
103110
name: 'production'
@@ -110,10 +117,8 @@ jobs:
110117
key: ${{ secrets.SSH_KEY }} # 服务器密码;需要去仓库的 settings/secrets/actions 去创建
111118
port: ${{ secrets.SSH_PORT }} # 服务器端口,默认22;需要去仓库的 settings/secrets/actions 去创建
112119
script: | # 重启更新镜像
113-
cd ${{ env.CONTENT_DIR }}
114-
echo "IMAGE_REPOSITORY=ghcr.io/${{ env.IMAGE_REPOSITORY }}:${{ github.run_id }}-${{ github.ref_name }}" > .env.${{ github.run_id }}
115-
docker login -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} https://ghcr.io
120+
cd ${{ env.DOCKER_COMPOSE_DIR }}
121+
echo "IMAGE_REPOSITORY=${{ env.REGISTRY }}/${{ env.IMAGE_REPOSITORY }}:${{ github.run_id }}" > .env.${{ github.run_id }}
122+
docker login -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} https://${{ env.REGISTRY }}
116123
docker compose --env-file .env.${{ github.run_id }} up --force-recreate -d
117-
env:
118-
CONTENT_DIR: /opt/pomelo
119-
IMAGE_REPOSITORY: $(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
124+
rm -f .env.${{ github.run_id }}

0 commit comments

Comments
 (0)