@@ -2,16 +2,21 @@ name: Frontend CI/CD
22
33on :
44 push :
5+ tags :
6+ - " v[0-9]+.[0-9]+.[0-9]+*"
57 paths :
68 - ' ui/**'
79 - ' .github/workflows/frontend-ci-cd.yml'
10+ pull_request :
811 branches :
912 - main
10- pull_request :
1113 paths :
1214 - ' ui/**'
1315 - ' .github/workflows/frontend-ci-cd.yml'
1416
17+ env :
18+ REGISTRY : chaitin-registry.cn-hangzhou.cr.aliyuncs.com/monkeycode
19+
1520jobs :
1621 build :
1722 runs-on : ubuntu-latest
3439 with :
3540 version : 8
3641
42+ - name : Get version
43+ id : get_version
44+ run : |
45+ if [[ $GITHUB_REF == refs/tags/* ]]; then
46+ VERSION=${GITHUB_REF#refs/tags/}
47+ else
48+ VERSION=$(git describe --tags --always --dirty)
49+ fi
50+ echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
51+
3752 - name : Get pnpm store directory
3853 shell : bash
3954 run : |
@@ -43,16 +58,23 @@ jobs:
4358 run : pnpm install
4459
4560 - name : Build frontend
46- run :
61+ run : |
4762 echo "VITE_APP_VERSION=${{ steps.get_version.outputs.VERSION }}" >> .env.production
4863 pnpm run build
4964
5065 - name : ' Tar files'
5166 run : tar -cvf dist.tar dist
5267
68+ - name : Upload build artifacts
69+ uses : actions/upload-artifact@v4
70+ with :
71+ name : frontend-build
72+ path : ./ui/dist.tar
73+
5374 package :
5475 needs : build
5576 runs-on : ubuntu-latest
77+ if : github.event_name != 'pull_request'
5678 steps :
5779 - name : Checkout code
5880 uses : actions/checkout@v4
@@ -81,17 +103,19 @@ jobs:
81103 - name : Login to Aliyun Container Registry
82104 uses : docker/login-action@v3
83105 with :
84- registry : chaitin-registry.cn-hangzhou.cr.aliyuncs.com
106+ registry : ${{ env.REGISTRY }}
85107 username : ${{ secrets.CT_ALIYUN_USER }}
86108 password : ${{ secrets.CT_ALIYUN_PASS }}
87109
88110 - name : Package and push
89111 uses : docker/build-push-action@v5
90112 with :
91113 context : ./ui
92- file : ./ui/Dockerfile
114+ file : ./ui/. Dockerfile
93115 push : true
94116 platforms : linux/amd64, linux/arm64
95- tags : chaitin-registry.cn-hangzhou.cr.aliyuncs.com/chaitin/monkey-code-frontend:v${{ needs.build.outputs.version }}
117+ tags : |
118+ ${{ env.REGISTRY }}/frontend:v${{ needs.build.outputs.version }}
119+ ${{ env.REGISTRY }}/frontend:latest
96120 cache-from : type=gha
97121 cache-to : type=gha,mode=max
0 commit comments