mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
chore(api-server): bye-bye you served us well (#60520)
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
committed by
GitHub
parent
a90e2757ac
commit
16e461385e
@@ -1,6 +1,3 @@
|
||||
'scope: docs':
|
||||
- docs/**/*
|
||||
|
||||
'scope: curriculum':
|
||||
- curriculum/challenges/**/*
|
||||
|
||||
@@ -8,7 +5,6 @@
|
||||
- client/**/*
|
||||
|
||||
'platform: api':
|
||||
- api-server/**/*
|
||||
- api/**/*
|
||||
|
||||
'scope: tools/scripts':
|
||||
@@ -18,8 +14,6 @@
|
||||
- e2e/**/*
|
||||
|
||||
'scope: i18n':
|
||||
- any: ['curriculum/challenges/**/*', '!curriculum/challenges/english/**/*']
|
||||
- docs/i18n/**/*
|
||||
- client/i18n/**/*
|
||||
- config/crowdin/**/*
|
||||
- shared/config/i18n/**/*
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: CD - Deploy API (Legacy) & Clients
|
||||
name: CD - Deploy - Clients
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
@@ -33,98 +33,9 @@ jobs:
|
||||
;;
|
||||
esac
|
||||
|
||||
api:
|
||||
name: API (Legacy) - [${{ needs.setup-jobs.outputs.tgt_env_short }}]
|
||||
needs: [setup-jobs]
|
||||
runs-on: ubuntu-22.04
|
||||
permissions:
|
||||
deployments: write
|
||||
contents: read
|
||||
environment:
|
||||
name: ${{ needs.setup-jobs.outputs.tgt_env_short }}-api-legacy
|
||||
env:
|
||||
TS_USERNAME: ${{ secrets.TS_USERNAME }}
|
||||
TS_MACHINE_NAME_PREFIX: ${{ secrets.TS_MACHINE_NAME_PREFIX }}
|
||||
steps:
|
||||
- name: Setup and connect to Tailscale network
|
||||
uses: tailscale/github-action@v3
|
||||
with:
|
||||
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
|
||||
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
|
||||
hostname: gha-${{needs.setup-jobs.outputs.tgt_env_short}}-api-legacy-ci-${{ github.run_id }}
|
||||
tags: tag:ci
|
||||
version: latest
|
||||
|
||||
- name: Configure SSH & Check Connection
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "Host *
|
||||
UserKnownHostsFile=/dev/null
|
||||
StrictHostKeyChecking no" > ~/.ssh/config
|
||||
chmod 644 ~/.ssh/config
|
||||
sleep 10
|
||||
for i in {1..3}; do
|
||||
TS_MACHINE_NAME=${TS_MACHINE_NAME_PREFIX}-api-${i}
|
||||
tailscale status | grep -q "$TS_MACHINE_NAME" || { echo "Machine not found"; exit 1; }
|
||||
sleep 1
|
||||
MACHINE_IP=$(tailscale ip -4 $TS_MACHINE_NAME)
|
||||
ssh $TS_USERNAME@$MACHINE_IP "uptime"
|
||||
done
|
||||
|
||||
- name: Deploy API
|
||||
# [NOTE] Use backslashes for expansion on remote machine, example: \$NVM_DIR, etc.
|
||||
run: |
|
||||
GIT_SOURCE_BRANCH=${{ needs.setup-jobs.outputs.tgt_env_branch }}
|
||||
for i in {1..3}; do
|
||||
TS_MACHINE_NAME=${TS_MACHINE_NAME_PREFIX}-api-${i}
|
||||
REMOTE_SCRIPT="
|
||||
set -e
|
||||
echo -e '\nLOG:Deploying API (Legacy) to $TS_MACHINE_NAME...'
|
||||
|
||||
echo -e '\nLOG:Environment setup...'
|
||||
cd /home/$TS_USERNAME/freeCodeCamp
|
||||
export NVM_DIR=\$HOME/.nvm && [ -s "\$NVM_DIR/nvm.sh" ] && source "\$NVM_DIR/nvm.sh"
|
||||
echo -e '\nLOG:Checking available Node.js versions...'
|
||||
nvm ls | grep 'default'
|
||||
echo -e '\nLOG:Checking Node.js version...'
|
||||
node --version
|
||||
|
||||
echo -e '\nLOG:Stopping all PM2 services...'
|
||||
pm2 stop all
|
||||
|
||||
echo -e '\nLOG:Git operations...'
|
||||
git status
|
||||
git clean -f
|
||||
git fetch --all --prune
|
||||
git checkout -f $GIT_SOURCE_BRANCH
|
||||
git reset --hard origin/$GIT_SOURCE_BRANCH
|
||||
git status
|
||||
|
||||
echo -e '\nLOG:Building...'
|
||||
npm i -g pnpm@10
|
||||
pnpm clean:packages
|
||||
pnpm clean:server
|
||||
pnpm install
|
||||
pnpm prebuild
|
||||
pnpm build:curriculum
|
||||
pnpm build:server
|
||||
echo -e '\nLOG:Build completed.'
|
||||
|
||||
echo -e '\nLOG:Starting PM2 reload...'
|
||||
pm2 reload './api-server/ecosystem.config.js'
|
||||
echo -e '\nLOG:PM2 reload completed.'
|
||||
|
||||
pm2 ls
|
||||
pm2 save
|
||||
echo -e '\nLOG:Finished deployment.'
|
||||
"
|
||||
MACHINE_IP=$(tailscale ip -4 $TS_MACHINE_NAME)
|
||||
ssh $TS_USERNAME@$MACHINE_IP "$REMOTE_SCRIPT"
|
||||
done
|
||||
|
||||
client:
|
||||
name: Clients - [${{ needs.setup-jobs.outputs.tgt_env_short }}] [${{ matrix.lang-name-short }}]
|
||||
needs: [setup-jobs, api]
|
||||
needs: [setup-jobs]
|
||||
runs-on: ubuntu-22.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
|
||||
@@ -72,8 +72,8 @@ jobs:
|
||||
name: webpack-stats
|
||||
path: client/public/stats.json
|
||||
|
||||
build-new-api:
|
||||
name: Build New Api (Container)
|
||||
build-api:
|
||||
name: Build API (Container)
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
steps:
|
||||
@@ -91,108 +91,16 @@ jobs:
|
||||
- name: Save Image
|
||||
run: docker save fcc-api > api-artifact.tar
|
||||
|
||||
- name: Upload Api Artifact
|
||||
- name: Upload API Artifact
|
||||
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
|
||||
with:
|
||||
name: api-artifact
|
||||
path: api-artifact.tar
|
||||
|
||||
playwright-run-old-api:
|
||||
name: E2E Test
|
||||
playwright-run-api:
|
||||
name: Run Playwright Tests
|
||||
runs-on: ubuntu-22.04
|
||||
needs: build-client
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
# Not Mobile Safari until we can get it working. Webkit and Mobile
|
||||
# Chrome both work, so hopefully there are no Mobile Safari specific
|
||||
# bugs.
|
||||
browsers: [chromium, firefox, webkit, Mobile Chrome]
|
||||
node-version: [20]
|
||||
|
||||
services:
|
||||
mongodb:
|
||||
image: mongo:8.0
|
||||
ports:
|
||||
- 27017:27017
|
||||
# We need mailhog to catch any emails the api tries to send.
|
||||
mailhog:
|
||||
image: mailhog/mailhog
|
||||
ports:
|
||||
- 1025:1025 # SMTP server (listens for emails)
|
||||
- 8025:8025 # HTTP server (so we can make requests to the api)
|
||||
|
||||
steps:
|
||||
- name: Set Action Environment Variables
|
||||
run: |
|
||||
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
|
||||
|
||||
- name: Checkout Source Files
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
||||
with:
|
||||
submodules: 'recursive'
|
||||
|
||||
- uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4
|
||||
with:
|
||||
name: client-artifact
|
||||
|
||||
- name: Unpack Client Artifact
|
||||
run: |
|
||||
tar -xf client-artifact.tar
|
||||
rm client-artifact.tar
|
||||
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d #v3.0.0
|
||||
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
- name: Set freeCodeCamp Environment Variables
|
||||
run: |
|
||||
cp sample.env .env
|
||||
|
||||
- name: Install and Build
|
||||
run: |
|
||||
pnpm install
|
||||
pnpm run create:shared
|
||||
pnpm run build:curriculum
|
||||
pnpm run build:server
|
||||
|
||||
- name: Seed Database with Certified User
|
||||
run: pnpm run seed:certified-user
|
||||
|
||||
# start-ci uses pm2, so it needs to be installed globally
|
||||
- name: Install pm2
|
||||
run: npm i -g pm2
|
||||
|
||||
- name: Install playwright dependencies
|
||||
run: npx playwright install --with-deps
|
||||
|
||||
- name: Run playwright tests
|
||||
run: |
|
||||
pnpm run start-ci &
|
||||
sleep 10
|
||||
npx playwright test --project="${{ matrix.browsers }}" --grep-invert 'third-party-donation.spec.ts'
|
||||
- uses: actions/upload-artifact@v4
|
||||
if: ${{ !cancelled() }}
|
||||
with:
|
||||
name: playwright-report-old-api-${{ matrix.browsers }}
|
||||
path: playwright/reporter
|
||||
retention-days: 30
|
||||
- name: Upload screenshots
|
||||
if: failure()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: screenshots-old-api-${{ matrix.browsers }}
|
||||
path: playwright/test-results
|
||||
retention-days: 14
|
||||
|
||||
playwright-run-new-api:
|
||||
name: Run Playwright Tests (with new Api)
|
||||
runs-on: ubuntu-22.04
|
||||
needs: [build-client, build-new-api]
|
||||
needs: [build-client, build-api]
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@@ -215,7 +123,7 @@ jobs:
|
||||
tar -xf client-artifact/client-artifact.tar
|
||||
rm client-artifact/client-artifact.tar
|
||||
|
||||
- name: Load Api Image
|
||||
- name: Load API Image
|
||||
run: |
|
||||
docker load < api-artifact/api-artifact.tar
|
||||
rm api-artifact/api-artifact.tar
|
||||
@@ -261,4 +169,4 @@ jobs:
|
||||
with:
|
||||
name: playwright-report-${{ matrix.browsers }}
|
||||
path: playwright/reporter
|
||||
retention-days: 30
|
||||
retention-days: 7
|
||||
|
||||
@@ -11,23 +11,12 @@ concurrency:
|
||||
cancel-in-progress: ${{ !contains(github.ref, 'main') && !contains(github.ref, 'prod-') }}
|
||||
|
||||
jobs:
|
||||
do-everything:
|
||||
name: Build & Test
|
||||
build-client:
|
||||
name: Build Client
|
||||
runs-on: ubuntu-22.04
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [20]
|
||||
services:
|
||||
mongodb:
|
||||
image: mongo:8.0
|
||||
ports:
|
||||
- 27017:27017
|
||||
# We need mailhog to catch any emails the api tries to send.
|
||||
mailhog:
|
||||
image: mailhog/mailhog
|
||||
ports:
|
||||
- 1025:1025
|
||||
|
||||
steps:
|
||||
- name: Checkout Source Files
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
||||
@@ -47,8 +36,7 @@ jobs:
|
||||
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
# cypress-io/github-action caches the store, so we should not cache it
|
||||
# here.
|
||||
cache: pnpm
|
||||
|
||||
- name: Set freeCodeCamp Environment Variables
|
||||
run: |
|
||||
@@ -60,32 +48,124 @@ jobs:
|
||||
- name: Install and Build
|
||||
run: |
|
||||
pnpm install
|
||||
pnpm run create:shared
|
||||
pnpm run build:curriculum
|
||||
pnpm run build:server
|
||||
|
||||
- name: Seed Database with Certified User
|
||||
run: pnpm run seed:certified-user
|
||||
pnpm run build
|
||||
|
||||
- name: Move serve.json to Public Folder
|
||||
run: cp client-config/serve.json client/public/serve.json
|
||||
|
||||
# start-ci uses pm2, so it needs to be installed globally
|
||||
- name: Install pm2
|
||||
run: npm i -g pm2
|
||||
- name: Tar Files
|
||||
run: tar -cf client-artifact.tar client/public
|
||||
|
||||
- name: Upload Client Artifact
|
||||
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
|
||||
with:
|
||||
name: client-artifact
|
||||
path: client-artifact.tar
|
||||
|
||||
build-api:
|
||||
name: Build API (Container)
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Checkout Source Files
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
||||
with:
|
||||
submodules: 'recursive'
|
||||
|
||||
- name: Create Image
|
||||
run: |
|
||||
docker build \
|
||||
-t fcc-api \
|
||||
-f docker/api/Dockerfile .
|
||||
|
||||
- name: Save Image
|
||||
run: docker save fcc-api > api-artifact.tar
|
||||
|
||||
- name: Upload API Artifact
|
||||
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
|
||||
with:
|
||||
name: api-artifact
|
||||
path: api-artifact.tar
|
||||
|
||||
playwright-run-api:
|
||||
name: Run Playwright 3rd Party Donation Tests
|
||||
runs-on: ubuntu-22.04
|
||||
needs: [build-client, build-api]
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
browsers: [chromium]
|
||||
node-version: [20]
|
||||
services:
|
||||
mongodb:
|
||||
image: mongo:8.0
|
||||
ports:
|
||||
- 27017:27017
|
||||
mailhog:
|
||||
image: mailhog/mailhog
|
||||
ports:
|
||||
- 1025:1025
|
||||
steps:
|
||||
- name: Set Action Environment Variables
|
||||
run: |
|
||||
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
|
||||
|
||||
- name: Checkout Source Files
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
||||
|
||||
- uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4
|
||||
|
||||
- name: Unpack Client Artifact
|
||||
run: |
|
||||
tar -xf client-artifact/client-artifact.tar
|
||||
rm client-artifact/client-artifact.tar
|
||||
|
||||
- name: Load API Image
|
||||
run: |
|
||||
docker load < api-artifact/api-artifact.tar
|
||||
rm api-artifact/api-artifact.tar
|
||||
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d #v3.0.0
|
||||
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
- name: Install Dependencies
|
||||
run: pnpm install
|
||||
|
||||
- name: Set freeCodeCamp Environment Variables (needed by api)
|
||||
run: |
|
||||
sed '/STRIPE/d; /PAYPAL/d; /PATREON/d;' sample.env > .env
|
||||
echo 'STRIPE_PUBLIC_KEY=${{ secrets.STRIPE_PUBLIC_KEY }}' >> .env
|
||||
echo 'PAYPAL_CLIENT_ID=${{ secrets.PAYPAL_CLIENT_ID }}' >> .env
|
||||
echo 'PATREON_CLIENT_ID=${{ secrets.PATREON_CLIENT_ID }}' >> .env
|
||||
|
||||
- name: Install playwright dependencies
|
||||
run: npx playwright install --with-deps
|
||||
|
||||
- name: Run playwright tests
|
||||
- name: Install and Build
|
||||
run: |
|
||||
pnpm run start-ci &
|
||||
pnpm install
|
||||
pnpm run create:shared
|
||||
pnpm run build:curriculum
|
||||
|
||||
- name: Start apps
|
||||
run: |
|
||||
docker compose up -d
|
||||
pnpm run serve:client-ci &
|
||||
sleep 10
|
||||
npx playwright test third-party-donation.spec.ts --project=${{ matrix.browsers }}
|
||||
|
||||
- name: Seed Database with Certified User
|
||||
run: pnpm run seed:certified-user
|
||||
|
||||
- name: Run playwright tests
|
||||
run: npx playwright test third-party-donation.spec.ts --project=${{ matrix.browsers }}
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
if: ${{ !cancelled() }}
|
||||
with:
|
||||
name: playwright-report-${{ matrix.browsers }}
|
||||
path: playwright/reporter
|
||||
retention-days: 30
|
||||
retention-days: 7
|
||||
|
||||
Reference in New Issue
Block a user