name: Build and Docker on: push: branches: [main, develop] tags: - 'v*' pull_request: branches: [main, develop] workflow_dispatch: concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} cancel-in-progress: true env: REGISTRY: registry.cn-hangzhou.aliyuncs.com IMAGE_NAME: ${{ github.repository }} jobs: build: name: Build Project runs-on: ubuntu-latest timeout-minutes: 30 outputs: image_tag: ${{ steps.meta.outputs.tags }} steps: - name: Checkout repository uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20' cache: 'pnpm' - name: Install pnpm uses: pnpm/action-setup@v4 with: version: 8 run_install: false - name: Get pnpm store directory id: pnpm-cache shell: bash run: | echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT - name: Setup pnpm cache uses: actions/cache@v4 with: path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-pnpm-store- - name: Setup Turbo cache uses: actions/cache@v4 with: path: .turbo key: ${{ runner.os }}-turbo-${{ github.sha }} restore-keys: | ${{ runner.os }}-turbo- - name: Install dependencies run: pnpm install --frozen-lockfile - name: Build project run: pnpm build - name: Upload build artifacts uses: actions/upload-artifact@v4 with: name: build-artifacts path: | apps/**/dist apps/**/.next services/**/dist packages/**/dist retention-days: 7 docker: name: Build and Push Docker Image needs: build runs-on: ubuntu-latest if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/v')) permissions: contents: read packages: write steps: - name: Checkout repository uses: actions/checkout@v4 - name: Download build artifacts uses: actions/download-artifact@v4 with: name: build-artifacts - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to Aliyun Container Registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ secrets.ALIYUN_REGISTRY_USERNAME }} password: ${{ secrets.ALIYUN_REGISTRY_PASSWORD }} - name: Extract metadata for Docker id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=sha - name: Build and push Docker image uses: docker/build-push-action@v5 with: context: . push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max