add staging deployment + test to gitea workflow
This commit is contained in:
parent
cde7a1309e
commit
8f75081e6b
@ -18,8 +18,8 @@ jobs:
|
||||
- name: install dependencies
|
||||
run: bun install
|
||||
|
||||
- name: run api integ test
|
||||
run: bun integ-test-api
|
||||
- name: run local integration test
|
||||
run: bun integ-test:local
|
||||
env:
|
||||
ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }}
|
||||
AUTH_TOKEN: ${{ secrets.TWILIO_AUTH_TOKEN }}
|
||||
@ -28,6 +28,25 @@ jobs:
|
||||
DISCORD_BOT_TOKEN: ${{ secrets.DISCORD_BOT_TOKEN }}
|
||||
DISCORD_CLIENT_SECRET: ${{ secrets.DISCORD_CLIENT_SECRET }}
|
||||
|
||||
- name: Deploy Doorman UI and API to staging
|
||||
run: bun run deploy-serverless:staging
|
||||
env:
|
||||
ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }}
|
||||
AUTH_TOKEN: ${{ secrets.TWILIO_AUTH_TOKEN }}
|
||||
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
|
||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
DISCORD_BOT_TOKEN: ${{ secrets.DISCORD_BOT_TOKEN }}
|
||||
DISCORD_CLIENT_SECRET: ${{ secrets.DISCORD_CLIENT_SECRET }}
|
||||
|
||||
- name: Deploy Doorman Buzzer Client to staging
|
||||
run: bun run deploy-buzzer-client:staging
|
||||
env:
|
||||
ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }}
|
||||
AUTH_TOKEN: ${{ secrets.TWILIO_AUTH_TOKEN }}
|
||||
|
||||
- name: run staging integration test
|
||||
run: bun integ-test:staging
|
||||
|
||||
- name: Deploy Doorman UI and API
|
||||
run: bun run deploy-serverless
|
||||
env:
|
||||
|
||||
@ -7,12 +7,15 @@
|
||||
"bun-types": "latest"
|
||||
},
|
||||
"scripts": {
|
||||
"integ-test-api": "bun --filter 'doorman-api' integ-test",
|
||||
"integ-test:local": "bun --filter 'doorman-api' integ-test:local",
|
||||
"integ-test:staging": "bun --filter 'doorman-api' integ-test:staging",
|
||||
"prepare-ui": "bun --filter 'doorman-ui' build && rm -rf packages/doorman-api/assets/* && mkdir -p packages/doorman-api/assets/assets && cp -fr packages/doorman-ui/dist/* packages/doorman-api/assets/ && cp -f packages/doorman-api/assets/index.html packages/doorman-api/assets/assets/index.html",
|
||||
"deploy-serverless": "bun run prepare-ui && bun run build-twilio-api && bun --filter 'doorman-api' deploy",
|
||||
"deploy-serverless:staging": "bun run prepare-ui && bun run build-twilio-api && bun --filter 'doorman-api' deploy:staging",
|
||||
"build-twilio-client": "bun --filter 'doorman-client' build",
|
||||
"build-twilio-api": "bun --filter 'doorman-api' build",
|
||||
"deploy-buzzer-client": "bun run build-twilio-client && bun --filter 'doorman-client' deploy"
|
||||
"deploy-buzzer-client": "bun run build-twilio-client && bun --filter 'doorman-client' deploy",
|
||||
"deploy-buzzer-client:staging": "bun run build-twilio-client && bun --filter 'doorman-client' deploy:staging"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
|
||||
@ -3,12 +3,14 @@
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"integ-test": "bun run build && export $(grep -v '^#' .env.example | grep -v '=$' | xargs) && concurrently --success first --kill-others \"bun run start-twilio\" \"bun test --timeout 30000\"",
|
||||
"integ-test:local": "bun run build && export $(grep -v '^#' .env.example | grep -v '=$' | xargs) && concurrently --success first --kill-others \"bun run start-twilio\" \"bun test --timeout 30000 ./tst/integ-local.test.ts\"",
|
||||
"integ-test:staging": "STAGE=staging bun test --timeout 30000 ./tst/integ-staging.test.ts",
|
||||
"start-twilio": "twilio-run --load-local-env --live --port 8080",
|
||||
"watch-build": "bun run --watch src/index.ts",
|
||||
"start": "concurrently \"bun run watch-build\" \"bun run start-twilio\"",
|
||||
"build": "bun run src/index.ts",
|
||||
"deploy": "twilio-run deploy --load-system-env --env .env.example --service-name doorman --environment=prod --override-existing-project"
|
||||
"deploy": "twilio-run deploy --load-system-env --env .env.example --service-name doorman --environment=prod --override-existing-project",
|
||||
"deploy:staging": "twilio-run deploy --load-system-env --env .env.example --service-name doorman --environment=staging --override-existing-project"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-dynamodb": "^3.821.0",
|
||||
|
||||
@ -1,9 +1,14 @@
|
||||
import { describe, test, expect, beforeAll } from "bun:test";
|
||||
import { waitForService, baseUrl, doorName, buzzerNumber, key } from "./testCommon";
|
||||
import { waitForService, baseUrl, doorName, buzzerNumber, key, buzzerUrl } from "./testCommon";
|
||||
import { DoorStatus } from "../src/types/DoorStatus";
|
||||
import { StatusResponse } from "../src/functions/api/door/status";
|
||||
import { sleep } from "bun";
|
||||
|
||||
// these tests should only run locally
|
||||
if (process.env.STAGE === 'staging') {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
await waitForService(baseUrl);
|
||||
});
|
||||
@ -70,5 +75,3 @@ describe("unlock path works", () => {
|
||||
expect(infoClosed.status).toBe(DoorStatus.CLOSED);
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: add tests for edit / onboard. Not sure how I can automated receive info needed for discord DMs
|
||||
35
packages/doorman-api/tst/integ-staging.test.ts
Normal file
35
packages/doorman-api/tst/integ-staging.test.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { describe, test, expect } from "bun:test";
|
||||
import { buzzerUrl, buzzerNumber, baseUrl, doorName, key } from "./testCommon";
|
||||
import { DoorStatus } from "../src/types/DoorStatus";
|
||||
import { InfoResponseUI } from "../src/functions/api/door/info";
|
||||
|
||||
if (process.env.STAGE !== 'staging') {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// currently these tests only run against STAGING env
|
||||
describe("buzzer client works", () => {
|
||||
test("unknown buzzer should reject", async () => {
|
||||
const unknownBuzzResp = await fetch(buzzerUrl + `?From=1`).then(res => res.text());
|
||||
expect(unknownBuzzResp).toContain("<Reject");
|
||||
});
|
||||
|
||||
test("no auth, should dial fallback numbers", async () => {
|
||||
const noAuthBuzzResp = await fetch(buzzerUrl + `?From=${buzzerNumber}`).then(res => res.text());
|
||||
expect(noAuthBuzzResp).toContain("<Dial");
|
||||
});
|
||||
|
||||
test("sample e2e happy path", async () => {
|
||||
// unlock door
|
||||
const authResp = await fetch(baseUrl + `/api/door/auth?door=${doorName}&key=${key}`);
|
||||
expect(authResp.status).toBe(200);
|
||||
|
||||
// buzzer should return an unlock
|
||||
const buzzerActivatedResp = await fetch(buzzerUrl + `?From=${buzzerNumber}`).then(res => res.text());
|
||||
expect(buzzerActivatedResp).toContain("<Play");
|
||||
|
||||
// door should now be closed
|
||||
const infoResp = await fetch(baseUrl + `/api/door/info?door=${doorName}`).then(res => res.json()) as InfoResponseUI;
|
||||
expect(infoResp.status).toBe(DoorStatus.CLOSED);
|
||||
});
|
||||
});
|
||||
@ -1,8 +1,11 @@
|
||||
export const baseUrl = "http://localhost:8080";
|
||||
export const baseUrl = process.env.STAGE == "staging" ? "https://doorman-6741-staging.twil.io": "http://localhost:8080";
|
||||
export const buzzerUrl = process.env.STAGE == "staging" ? "https://buzzer-2439-staging.twil.io/buzzer-activated": "http://localhost:4500/buzzer-activated";
|
||||
export const doorName = "test";
|
||||
export const buzzerNumber = "6133163433";
|
||||
export const key = "1234";
|
||||
|
||||
console.log("using URL", baseUrl, buzzerUrl);
|
||||
|
||||
export const waitForService = async (url: string, timeout = 30000) => {
|
||||
const start = Date.now();
|
||||
|
||||
@ -15,4 +18,4 @@ export const waitForService = async (url: string, timeout = 30000) => {
|
||||
}
|
||||
}
|
||||
throw new Error(`Service at ${url} did not start within ${timeout}ms`);
|
||||
};
|
||||
};
|
||||
|
||||
@ -8,7 +8,8 @@
|
||||
"start-twilio": "twilio-run --live --port 4500",
|
||||
"start": "concurrently \"bun run watch-build\" \"bun run start-twilio\"",
|
||||
"build": "bun run src/index.ts",
|
||||
"deploy": "twilio-run deploy --load-system-env --env .env.example --service-name buzzer --environment=prod --override-existing-project"
|
||||
"deploy": "twilio-run deploy --load-system-env --env .env.example --service-name buzzer --environment=prod --override-existing-project",
|
||||
"deploy:staging": "twilio-run deploy --load-system-env --env .env.example --service-name buzzer --environment=staging --override-existing-project"
|
||||
},
|
||||
"dependencies": {
|
||||
"@twilio-labs/serverless-runtime-types": "^4.0.1",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user