feat(web): enhance code editor functionality (#1945) #227
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: Web UI deploy | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - ".github/workflows/web-deploy.yml" | |
| - "moon/apps/web/**" | |
| - "moon/packages/**" | |
| env: | |
| TIPTAP_PRIVATE_REGISTRY_KEY: ${{ secrets.TIPTAP_PRIVATE_REGISTRY_KEY }} | |
| REGISTRY_ALIAS: m8q5m4u3 | |
| REPOSITORY: mega | |
| GCP_PROJECT_ID: infra-20250121-20260121-0235 | |
| GCP_REPOSITORY: mega | |
| IMAGE_VERSION: 0.1.0-pre-release | |
| permissions: | |
| id-token: write | |
| contents: read | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| build-push-single-arch: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| env_name: [demo, staging, gitmono, buck2hub] | |
| timeout-minutes: 10 | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # ----------------------------- | |
| # AWS login (skip buck2hub) | |
| - name: Configure AWS Credentials | |
| if: matrix.env_name != 'buck2hub' | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: us-east-1 | |
| - name: Login to Amazon ECR Public | |
| if: matrix.env_name != 'buck2hub' | |
| id: login-ecr-public | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| with: | |
| registry-type: public | |
| # ----------------------------- | |
| # GCP login (only buck2hub) | |
| - name: Auth to GCP | |
| if: matrix.env_name == 'buck2hub' | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| credentials_json: ${{ secrets.GCP_SA_KEY }} | |
| - name: Configure docker for GCP | |
| if: matrix.env_name == 'buck2hub' | |
| run: gcloud auth configure-docker us-central1-docker.pkg.dev | |
| # ----------------------------- | |
| # Build & push | |
| - name: Build & push ${{ matrix.env_name }} image | |
| working-directory: moon | |
| env: | |
| REGISTRY: ${{ steps.login-ecr-public.outputs.registry || '' }} | |
| PLATFORM: linux/amd64 | |
| run: | | |
| set -euo pipefail | |
| ARCH_SUFFIX="amd64" | |
| IMAGE_TAG="mega-ui-${{ matrix.env_name }}-${IMAGE_VERSION}-${ARCH_SUFFIX}" | |
| if [ "${{ matrix.env_name }}" = "buck2hub" ]; then | |
| IMAGE_BASE="us-central1-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GCP_REPOSITORY }}/${{ env.REPOSITORY }}" | |
| else | |
| IMAGE_BASE="$REGISTRY/${{ env.REGISTRY_ALIAS }}/${{ env.REPOSITORY }}" | |
| fi | |
| docker buildx build \ | |
| --platform "$PLATFORM" \ | |
| --cache-from type=gha,scope=mega-ui \ | |
| --cache-to type=gha,mode=max,scope=mega-ui \ | |
| --provenance=false \ | |
| --sbom=false \ | |
| --build-arg APP_ENV=${{ matrix.env_name }} \ | |
| -f apps/web/Dockerfile \ | |
| -t "$IMAGE_BASE:$IMAGE_TAG" . \ | |
| --push | |
| manifest: | |
| needs: build-push-single-arch | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| env_name: [demo, staging, gitmono, buck2hub] | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: us-east-1 | |
| - name: Login to Amazon ECR Public | |
| id: login-ecr-public | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| with: | |
| registry-type: public | |
| - name: Create & push manifest for ${{ matrix.env_name }} | |
| env: | |
| REGISTRY: ${{ steps.login-ecr-public.outputs.registry }} | |
| run: | | |
| set -euo pipefail | |
| IMAGE_BASE="$REGISTRY/${{ env.REGISTRY_ALIAS }}/${{ env.REPOSITORY }}" | |
| TAG="mega-ui-${{ matrix.env_name }}-0.1.0-pre-release" | |
| if [ "${{ matrix.env_name }}" = "demo" ]; then | |
| echo "Creating multi-arch manifest for demo (amd64 + arm64)" | |
| docker manifest create "$IMAGE_BASE:$TAG" \ | |
| "$IMAGE_BASE:${TAG}-amd64" \ | |
| "$IMAGE_BASE:${TAG}-arm64" | |
| else | |
| echo "Creating amd64-only manifest for ${{ matrix.env_name }}" | |
| docker manifest create "$IMAGE_BASE:$TAG" \ | |
| "$IMAGE_BASE:${TAG}-amd64" | |
| fi | |
| docker manifest push "$IMAGE_BASE:$TAG" | |
| deploy-aws: | |
| needs: manifest | |
| if: ${{ github.repository == 'web3infra-foundation/mega' }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| strategy: | |
| matrix: | |
| include: | |
| - cluster: gitmega-com | |
| service: mega-frontend-development-service-6dcihwup | |
| - cluster: gitmono-com-mega-app | |
| service: mega-ui-service | |
| steps: | |
| - name: Force ECS redeploy | |
| run: | | |
| aws ecs update-service \ | |
| --cluster ${{ matrix.cluster }} \ | |
| --service ${{ matrix.service }} \ | |
| --force-new-deployment | |
| env: | |
| AWS_REGION: ap-southeast-2 | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| deploy-gcp: | |
| needs: manifest | |
| if: ${{ github.repository == 'web3infra-foundation/mega' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Auth to GCP | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| credentials_json: ${{ secrets.GCP_SA_KEY }} | |
| - name: Deploy to Cloud Run (force new revision) | |
| env: | |
| REGION: asia-east1 | |
| SERVICE_NAME: buck2hub-ui | |
| run: | | |
| set -euo pipefail | |
| IMAGE=$(gcloud run services describe $SERVICE_NAME \ | |
| --project "$GCP_PROJECT_ID" \ | |
| --region "$REGION" \ | |
| --format="value(spec.template.spec.containers[0].image)") | |
| echo "Current image: $IMAGE" | |
| gcloud run deploy $SERVICE_NAME \ | |
| --image "$IMAGE" \ | |
| --region "$REGION" \ | |
| --project "$GCP_PROJECT_ID" \ | |
| --quiet |