Merge pull request #18 from yokowu/main #6
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Frontend CI/CD | |
| on: | |
| push: | |
| tags: | |
| - "v[0-9]+.[0-9]+.[0-9]+*" | |
| paths: | |
| - 'ui/**' | |
| - '.github/workflows/frontend-ci-cd.yml' | |
| pull_request: | |
| branches: | |
| - main | |
| paths: | |
| - 'ui/**' | |
| - '.github/workflows/frontend-ci-cd.yml' | |
| env: | |
| REGISTRY: chaitin-registry.cn-hangzhou.cr.aliyuncs.com/monkeycode | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: ./ui | |
| outputs: | |
| version: ${{ steps.get_version.outputs.VERSION }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Set up pnpm | |
| uses: pnpm/action-setup@v2 | |
| with: | |
| version: 8 | |
| - name: Get version | |
| id: get_version | |
| run: | | |
| if [[ $GITHUB_REF == refs/tags/* ]]; then | |
| VERSION=${GITHUB_REF#refs/tags/} | |
| else | |
| VERSION=$(git describe --tags --always --dirty) | |
| fi | |
| echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT | |
| - name: Get pnpm store directory | |
| shell: bash | |
| run: | | |
| echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV | |
| - name: Install dependencies | |
| run: pnpm install | |
| - name: Build frontend | |
| run: | | |
| echo "VITE_APP_VERSION=${{ steps.get_version.outputs.VERSION }}" >> .env.production | |
| pnpm run build | |
| - name: 'Tar files' | |
| run: tar -cvf dist.tar dist | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: frontend-build | |
| path: ./ui/dist.tar | |
| package: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: github.event_name != 'pull_request' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: frontend-build | |
| - name: Extract files | |
| run: | | |
| tar -xvf dist.tar | |
| - name: Check file structure | |
| run: | | |
| echo "Current directory: $(pwd)" | |
| echo "Listing dist directory:" | |
| ls -la dist | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Aliyun Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ secrets.CT_ALIYUN_USER }} | |
| password: ${{ secrets.CT_ALIYUN_PASS }} | |
| - name: Package and push | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ./ui | |
| file: ./ui/.Dockerfile | |
| push: true | |
| platforms: linux/amd64, linux/arm64 | |
| tags: | | |
| ${{ env.REGISTRY }}/frontend:v${{ needs.build.outputs.version }} | |
| ${{ env.REGISTRY }}/frontend:latest | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |