diff --git a/.github/workflows/api.yml b/.github/workflows/ci.yaml similarity index 54% rename from .github/workflows/api.yml rename to .github/workflows/ci.yaml index 6c5848361..3ea751c2d 100644 --- a/.github/workflows/api.yml +++ b/.github/workflows/ci.yaml @@ -1,4 +1,4 @@ -name: api +name: CI/CD on: push: @@ -10,34 +10,40 @@ on: permissions: contents: read - id-token: write + +concurrency: + group: ci-cd-${{ github.ref }} + cancel-in-progress: false jobs: - test: - name: Integration Tests - runs-on: ubuntu-latest + integration-tests: + name: Run Integration Tests + runs-on: ubuntu-26.04 steps: - - name: Checkout + - name: Checkout Code uses: actions/checkout@v7 - - name: Set up Go + - name: Set Up Go uses: actions/setup-go@v7 with: go-version: stable + cache-dependency-path: | + api/go.sum + tests/go.sum - - name: Generate Firebase credentials + - name: Generate Firebase Credentials run: | bash tests/generate-firebase-credentials.sh tests/firebase-credentials.json echo "FIREBASE_CREDENTIALS=$(jq -c . tests/firebase-credentials.json)" >> $GITHUB_ENV - - name: Generate adapter certificates + - name: Generate Adapter Certificates run: bash tests/generate-adapter-certificates.sh tests/certs - name: Start Services working-directory: ./tests run: docker compose up -d --build - - name: Wait for services to be healthy + - name: Wait for Healthy Services working-directory: ./tests run: | echo "Waiting for MongoDB to be healthy..." @@ -74,7 +80,7 @@ jobs: working-directory: ./tests run: | echo "Waiting for seed container to finish..." - docker compose wait seed || true + docker compose wait seed sleep 2 - name: Run Handler Integration Tests @@ -83,11 +89,11 @@ jobs: USER_API_KEY: test-user-api-key run: go test -tags integration -v -timeout 60s ./pkg/handlers - - name: Run Integration Tests + - name: Run End-to-End Integration Tests working-directory: ./tests run: go test -v -timeout 300s ./... - - name: Collect Logs on Failure + - name: Collect Service Logs on Failure if: failure() working-directory: ./tests run: | @@ -98,11 +104,15 @@ jobs: working-directory: ./tests run: docker compose down -v - deploy: - name: Deploy - runs-on: ubuntu-latest - needs: test + deploy-api: + name: Deploy API + runs-on: ubuntu-26.04 + needs: integration-tests if: github.event_name == 'push' && github.ref == 'refs/heads/main' + timeout-minutes: 60 + permissions: + contents: read + id-token: write steps: - name: Authenticate to Google Cloud uses: google-github-actions/auth@v3 @@ -110,16 +120,16 @@ jobs: workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} - - name: Set up Cloud SDK + - name: Set Up Google Cloud SDK uses: google-github-actions/setup-gcloud@v3 - - name: Trigger Cloud Build Deploy + - name: Build and Deploy API run: | BUILD_ID=$(gcloud builds triggers run api-httpsms-com \ --region=global \ --project=httpsms-86c51 \ --sha=${{ github.sha }} \ - --substitutions=_VERSION=${{ github.run_number }} \ + --substitutions=_VERSION=${{ github.run_id }} \ --format="value(metadata.build.id)") echo -e "Cloud Build: \033[34mhttps://console.cloud.google.com/cloud-build/builds/$BUILD_ID?project=httpsms-86c51\033[0m" echo "" @@ -135,12 +145,91 @@ jobs: sleep 30 done + build-web: + name: Build Web + needs: integration-tests + runs-on: ubuntu-26.04 + defaults: + run: + working-directory: ./web + steps: + - name: Checkout Code + uses: actions/checkout@v7 + + - name: Set Up Node.js + uses: actions/setup-node@v7 + with: + node-version: "24.18" + + - name: Set Up pnpm + uses: pnpm/action-setup@v6 + with: + version: 11.11.0 + + - name: Install Web Dependencies + run: pnpm install --trust-lockfile + + - name: Lint Web + run: pnpm lint + + - name: Run Web Tests + run: pnpm test + + - name: Build Web + run: mv .env.production .env && pnpm run generate + + - name: Upload Web Build + uses: actions/upload-artifact@v7 + with: + name: web-build + path: web/.output/public + include-hidden-files: true + if-no-files-found: error + retention-days: 1 + deploy-web: - name: Deploy Web - needs: deploy + name: Deploy Web (${{ matrix.provider }}) + needs: [deploy-api, build-web] + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + runs-on: ubuntu-26.04 permissions: contents: read pull-requests: write deployments: write - uses: ./.github/workflows/web.yml - secrets: inherit + strategy: + fail-fast: false + matrix: + provider: [Cloudflare, Firebase] + steps: + - name: Checkout Code + uses: actions/checkout@v7 + + - name: Set Up Node.js + uses: actions/setup-node@v7 + with: + node-version: "24.18" + + - name: Download Web Build + uses: actions/download-artifact@v8 + with: + name: web-build + path: web/.output/public + + - name: Deploy Web to Cloudflare + if: matrix.provider == 'Cloudflare' + uses: cloudflare/wrangler-action@v4 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + command: pages deploy web/.output/public --project-name=httpsms + gitHubToken: ${{ secrets.GITHUB_TOKEN }} + + - name: Deploy Web to Firebase + if: matrix.provider == 'Firebase' + uses: FirebaseExtended/action-hosting-deploy@500ac625ca2dd40cbd15f7659af953801858032a + with: + repoToken: "${{ secrets.GITHUB_TOKEN }}" + channelId: live + entryPoint: "./web" + firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_HTTPSMS_86C51 }}" + projectId: httpsms-86c51 diff --git a/.github/workflows/web.yml b/.github/workflows/web.yml deleted file mode 100644 index 7ce643d66..000000000 --- a/.github/workflows/web.yml +++ /dev/null @@ -1,90 +0,0 @@ -name: web - -on: - workflow_call: - pull_request: - branches: - - main - -permissions: - contents: read - pull-requests: write - deployments: write - -defaults: - run: - working-directory: ./web - -jobs: - validate: - name: Validate - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: [ubuntu-latest] - node: [24] - - steps: - - name: Checkout ๐Ÿ›Ž - uses: actions/checkout@master - - - uses: pnpm/action-setup@v6 - name: Install pnpm - with: - version: 11.11.0 - - - name: Install dependencies ๐Ÿ“ฆ - run: pnpm install --trust-lockfile - - - name: Run linter ๐Ÿ‘€ - run: pnpm lint - - - name: Run tests ๐Ÿงช - run: pnpm test - - - name: Build ๐Ÿ—๏ธ - run: mv .env.production .env && pnpm run generate - - deploy: - name: Deploy - needs: validate - if: github.event_name == 'push' && github.ref == 'refs/heads/main' - runs-on: ubuntu-latest - - steps: - - name: Checkout ๐Ÿ›Ž - uses: actions/checkout@master - - - name: Setup Node ๐ŸŸข - uses: actions/setup-node@v7 - with: - node-version: "24.18" - - - uses: pnpm/action-setup@v6 - name: Install pnpm - with: - version: 11.11.0 - - - name: Install dependencies ๐Ÿ“ฆ - run: pnpm install --trust-lockfile - - - name: Build ๐Ÿ—๏ธ - run: mv .env.production .env && pnpm run generate - - - name: Cloudflare Deploy ๐Ÿš€ - uses: cloudflare/wrangler-action@v4 - with: - apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - command: pages deploy web/.output/public --project-name=httpsms - gitHubToken: ${{ secrets.GITHUB_TOKEN }} - - - name: Firebase Deploy ๐Ÿš€ - uses: FirebaseExtended/action-hosting-deploy@500ac625ca2dd40cbd15f7659af953801858032a - with: - repoToken: "${{ secrets.GITHUB_TOKEN }}" - channelId: live - entryPoint: "./web" - firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_HTTPSMS_86C51 }}" - projectId: httpsms-86c51 diff --git a/README.md b/README.md index 42a6b0d36..b90eda91e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # httpSMS -[![Web](https://github.com/NdoleStudio/httpsms/actions/workflows/web.yml/badge.svg)](https://github.com/NdoleStudio/httpsms/actions/workflows/web.yml) -[![API](https://github.com/NdoleStudio/httpsms/actions/workflows/api.yml/badge.svg)](https://github.com/NdoleStudio/httpsms/actions/workflows/api.yml) +[![CI/CD](https://github.com/NdoleStudio/httpsms/actions/workflows/ci.yaml/badge.svg)](https://github.com/NdoleStudio/httpsms/actions/workflows/ci.yaml) [![GitHub contributors](https://img.shields.io/github/contributors/NdoleStudio/httpsms)](https://github.com/NdoleStudio/httpsms/graphs/contributors) [![GitHub license](https://img.shields.io/github/license/NdoleStudio/httpsms?color=brightgreen)](https://github.com/NdoleStudio/httpsms/blob/master/LICENSE) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md) diff --git a/api/cloudbuild.yaml b/api/cloudbuild.yaml index ce819104e..1137fb183 100644 --- a/api/cloudbuild.yaml +++ b/api/cloudbuild.yaml @@ -1,6 +1,6 @@ steps: - name: "gcr.io/kaniko-project/executor:v1.23.2" - id: "Build image and push" + id: "Build and Push API Image" dir: "api" args: - "--destination=us.gcr.io/$PROJECT_ID/$_SERVICE_NAME:$_VERSION" @@ -10,7 +10,7 @@ steps: - "--build-arg=VERSION=$_VERSION" - "--snapshot-mode=time" - - id: "Deploy to cloud run" + - id: "Deploy API" name: "gcr.io/cloud-builders/gcloud" entrypoint: "bash" args: diff --git a/tests/README.md b/tests/README.md index 35c144b68..0069fe618 100644 --- a/tests/README.md +++ b/tests/README.md @@ -135,11 +135,18 @@ cd tests && \ ## CI/CD -`.github/workflows/api.yml` generates both the fake Firebase credential and +`.github/workflows/ci.yaml` generates both the fake Firebase credential and the adapter CA/server certificate before building the Compose stack. The workflow runs API handler integration tests and this complete host-side suite, collects service logs on failure, and always tears the stack down. +After integration tests pass, the CI/CD workflow builds the web frontend and +deploys the API in parallel. On pushes to `main`, the web build is deployed to +Cloudflare and Firebase in parallel only after both jobs succeed. Pull requests +run integration tests and web validation/build without deploying. Both the API +and web use the GitHub Actions run ID as their version, preserving increasing +versions across workflow file renames. + ## Test Data | Entity | Value | diff --git a/web/firebase.json b/web/firebase.json index 0a3d84e34..c0b714cb3 100644 --- a/web/firebase.json +++ b/web/firebase.json @@ -1,6 +1,6 @@ { "hosting": { - "public": "dist", + "public": ".output/public", "ignore": ["firebase.json", "**/.*", "**/node_modules/**"], "rewrites": [ { diff --git a/web/nuxt.config.ts b/web/nuxt.config.ts index ae3c47149..1fde102fe 100644 --- a/web/nuxt.config.ts +++ b/web/nuxt.config.ts @@ -113,7 +113,7 @@ export default defineNuxtConfig({ runtimeConfig: { public: { apiBaseUrl: process.env.API_BASE_URL || 'http://localhost:8000', - clientVersion: process.env.GITHUB_RUN_NUMBER || 'dev', + clientVersion: process.env.GITHUB_RUN_ID || 'dev', appUrl: process.env.APP_URL || 'https://httpsms.com', appName: process.env.APP_NAME || 'HTTP SMS', appGithubUrl: