|
| 1 | +name: Frontend CI/CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - 'ui/**' |
| 7 | + - '.github/workflows/frontend-ci-cd.yml' |
| 8 | + branches: |
| 9 | + - main |
| 10 | + pull_request: |
| 11 | + paths: |
| 12 | + - 'ui/**' |
| 13 | + - '.github/workflows/frontend-ci-cd.yml' |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + defaults: |
| 19 | + run: |
| 20 | + working-directory: ./ui |
| 21 | + outputs: |
| 22 | + version: ${{ steps.get_version.outputs.VERSION }} |
| 23 | + steps: |
| 24 | + - name: Checkout code |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Set up Node.js |
| 28 | + uses: actions/setup-node@v4 |
| 29 | + with: |
| 30 | + node-version: '20' |
| 31 | + |
| 32 | + - name: Set up pnpm |
| 33 | + uses: pnpm/action-setup@v2 |
| 34 | + with: |
| 35 | + version: 8 |
| 36 | + |
| 37 | + - name: Get pnpm store directory |
| 38 | + shell: bash |
| 39 | + run: | |
| 40 | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV |
| 41 | +
|
| 42 | + - name: Install dependencies |
| 43 | + run: pnpm install |
| 44 | + |
| 45 | + - name: Build frontend |
| 46 | + run: |
| 47 | + echo "VITE_APP_VERSION=${{ steps.get_version.outputs.VERSION }}" >> .env.production |
| 48 | + pnpm run build |
| 49 | + |
| 50 | + - name: 'Tar files' |
| 51 | + run: tar -cvf dist.tar dist |
| 52 | + |
| 53 | + package: |
| 54 | + needs: build |
| 55 | + runs-on: ubuntu-latest |
| 56 | + steps: |
| 57 | + - name: Checkout code |
| 58 | + uses: actions/checkout@v4 |
| 59 | + |
| 60 | + - name: Download build artifacts |
| 61 | + uses: actions/download-artifact@v4 |
| 62 | + with: |
| 63 | + name: frontend-build |
| 64 | + |
| 65 | + - name: Extract files |
| 66 | + run: | |
| 67 | + tar -xvf dist.tar |
| 68 | +
|
| 69 | + - name: Check file structure |
| 70 | + run: | |
| 71 | + echo "Current directory: $(pwd)" |
| 72 | + echo "Listing dist directory:" |
| 73 | + ls -la dist |
| 74 | +
|
| 75 | + - name: Set up QEMU |
| 76 | + uses: docker/setup-qemu-action@v3 |
| 77 | + |
| 78 | + - name: Set up Docker Buildx |
| 79 | + uses: docker/setup-buildx-action@v3 |
| 80 | + |
| 81 | + - name: Login to Aliyun Container Registry |
| 82 | + uses: docker/login-action@v3 |
| 83 | + with: |
| 84 | + registry: chaitin-registry.cn-hangzhou.cr.aliyuncs.com |
| 85 | + username: ${{ secrets.CT_ALIYUN_USER }} |
| 86 | + password: ${{ secrets.CT_ALIYUN_PASS }} |
| 87 | + |
| 88 | + - name: Package and push |
| 89 | + uses: docker/build-push-action@v5 |
| 90 | + with: |
| 91 | + context: ./ui |
| 92 | + file: ./ui/Dockerfile |
| 93 | + push: true |
| 94 | + platforms: linux/amd64, linux/arm64 |
| 95 | + tags: chaitin-registry.cn-hangzhou.cr.aliyuncs.com/chaitin/monkey-code-frontend:v${{ needs.build.outputs.version }} |
| 96 | + cache-from: type=gha |
| 97 | + cache-to: type=gha,mode=max |
0 commit comments