diff --git a/.github/masterci.txt b/.github/masterci.txt new file mode 100644 index 0000000..63f62f8 --- /dev/null +++ b/.github/masterci.txt @@ -0,0 +1,225 @@ +name: Test +on: + push: + branches: + - dev + +concurrency: + group: ${{ github.workflow }} + +env: + REGION: europe-west2 + IMAGE_TAG: ${{ github.sha }} + REPOSITORY: gha-build-artifacts + +jobs: + changes: + runs-on: ubuntu-latest + permissions: + contents: read + + outputs: + client: ${{ steps.filter.outputs.client }} + klaviyo: ${{ steps.filter.outputs.klaviyo }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + client: + - 'apps/client/**' + klaviyo: + - 'apps/klaviyo/**' + + build-client: + needs: changes + name: Build and push Client docker image + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + + env: + PROJECT_ID: yuzu-development-client + SERVICE: client + + steps: + - name: Checkout + uses: actions/checkout@v4 + + + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + # Authenticate Docker to Google Cloud Artifact Registry + - name: Docker Auth + id: docker-auth + uses: docker/login-action@v3 + with: + username: 'oauth2accesstoken' + password: '${{ steps.auth.outputs.access_token }}' + registry: '${{ env.REGION }}-docker.pkg.dev' + + # Build and push the Docker image to Google Cloud Artifact Registry + - name: Build Docker image + id: docker-build + uses: docker/build-push-action@v5 + with: + context: ./ + file: ./apps/${{ env.SERVICE }}/Dockerfile + target: runner # Set the desired build target here + push: true + tags: | + ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }} + ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:latest + cache-from: type=gha + cache-to: type=gha,mode=max + build-args: | + "ALGOLIA_APPLICATION_ID=${{ secrets.CORE_ALGOLIA_APP_ID }}" + "ALGOLIA_API_KEY=${{ secrets.CORE_ALGOLIA_PUBLIC_API_KEY }}" + "NUXT_ALGOLIA_API_KEY=${{ secrets.CORE_ALGOLIA_API_KEY }}" + + build-klaviyo: + needs: changes + if: ${{ needs.changes.outputs.klaviyo == 'true' || needs.changes.outputs.sdk == 'true' }} + name: Build and push Klaviyo docker image + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + + env: + PROJECT_ID: yuzu-development-klaviyo + SERVICE: klaviyo + + steps: + - name: Checkout + uses: actions/checkout@v4 + + + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + # Authenticate Docker to Google Cloud Artifact Registry + - name: Docker Auth + id: docker-auth + uses: docker/login-action@v3 + with: + username: 'oauth2accesstoken' + password: '${{ steps.auth.outputs.access_token }}' + registry: '${{ env.REGION }}-docker.pkg.dev' + + # Build and push the Docker image to Google Cloud Artifact Registry + - name: Build Docker image + id: docker-build + uses: docker/build-push-action@v5 + with: + context: ./ + file: ./apps/${{ env.SERVICE }}/Dockerfile + target: runner # Set the desired build target here + push: true + tags: | + ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }} + ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + needs: changes + if: ${{ needs.changes.outputs.skulabs == 'true' || needs.changes.outputs.sdk == 'true' }} + name: Build and push SKULabs docker image + runs-on: ubuntu-latest + environment: development + permissions: + contents: read + id-token: write + + env: + PROJECT_ID: yuzu-development-skulabs + SERVICE: skulabs + + steps: + - name: Checkout + uses: actions/checkout@v4 + + + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + # Authenticate Docker to Google Cloud Artifact Registry + - name: Docker Auth + id: docker-auth + uses: docker/login-action@v3 + with: + username: 'oauth2accesstoken' + password: '${{ steps.auth.outputs.access_token }}' + registry: '${{ env.REGION }}-docker.pkg.dev' + + # Build and push the Docker image to Google Cloud Artifact Registry + - name: Build Docker image + id: docker-build + uses: docker/build-push-action@v5 + with: + context: ./ + file: ./apps/${{ env.SERVICE }}/Dockerfile + target: runner # Set the desired build target here + push: true + tags: | + ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }} + ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + deploy-client: + name: Deploy Client + runs-on: ubuntu-latest + needs: [build-client] + permissions: + id-token: write + + env: + PROJECT_ID: yuzu-development-client + SERVICE: client + + outputs: + url: ${{ steps.deploy-client.outputs.url }} + + steps: + - name: Deploy Client to Cloud Run + id: deploy-client + uses: google-github-actions/deploy-cloudrun@v2 + with: + project_id: ${{ env.PROJECT_ID }} + service: ${{ env.SERVICE }} + region: ${{ env.REGION }} + image: ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }} + + deploy-klaviyo: + name: Deploy Klaviyo + runs-on: ubuntu-latest + needs: [build-klaviyo] + permissions: + id-token: write + + env: + PROJECT_ID: yuzu-development-klaviyo + SERVICE: klaviyo + + outputs: + url: ${{ steps.deploy-klaviyo.outputs.url }} + + steps: + - name: Deploy Klaviyo to Cloud Run + id: deploy-klaviyo + uses: google-github-actions/deploy-cloudrun@v2 + with: + project_id: ${{ env.PROJECT_ID }} + service: ${{ env.SERVICE }} + region: ${{ env.REGION }} + image: ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6301f87..3357518 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ name: CI on: pull_request: - branches: [dev] + branches: [main] types: [opened, synchronize, reopened] permissions: @@ -36,5 +36,11 @@ jobs: - name: Install dependencies run: pnpm install + - name: Setup environment + run: | + mkdir -p .env + cp .github/env/.env.ci .env/.env + env: + NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: ${{ secrets.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY }} - name: Build run: pnpm build diff --git a/.github/workflows/masterci.yml b/.github/workflows/masterci.yml new file mode 100644 index 0000000..3820d93 --- /dev/null +++ b/.github/workflows/masterci.yml @@ -0,0 +1,118 @@ +name: Test +on: + pull_request: + branches: [dev] + types: [opened, synchronize, reopened] + +concurrency: + group: ${{ github.workflow }} + +env: + REGION: europe-west2 + IMAGE_TAG: ${{ github.sha }} + REPOSITORY: gha-build-artifacts + +jobs: + changes: + runs-on: ubuntu-latest + permissions: + contents: read + + outputs: + client: ${{ steps.filter.outputs.client }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + client: + - 'apps/client/**' + + build: + needs: changes + # if: ${{ needs.changes.outputs.client == 'true' }} + name: Build and Test + timeout-minutes: 15 + runs-on: ubuntu-latest + env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: "metafest" + + steps: + - name: Check out code + uses: actions/checkout@v4 + with: + fetch-depth: 2 + + - uses: pnpm/action-setup@v3 + with: + version: 8 + + - name: Setup Node.js environment + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: "pnpm" + + - name: Install dependencies + run: pnpm install + + - name: Build + run: pnpm build + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: build-output + path: apps/client/.next + retention-days: 1 + + deploy-client: + name: Deploy Client + runs-on: ubuntu-latest + needs: [build] + permissions: + contents: read + id-token: write + defaults: + run: + working-directory: apps/client + + env: + CLERK_API_KEY: ${{ secrets.CLERK_API_KEY }} + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + + steps: + - name: Check out code + uses: actions/checkout@v4 + + - uses: pnpm/action-setup@v3 + with: + version: 8 + + - name: Setup Node.js environment + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: "pnpm" + + - name: Download build artifacts + uses: actions/download-artifact@v4 + with: + name: build-output + path: apps/client/.next + + - name: Install Vercel CLI + run: pnpm install -g vercel + + - name: Pull Vercel Environment Variables + run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} + + - name: Deploy to Vercel + run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }} \ No newline at end of file