Skip to content

Commit

Permalink
fix: v2 event-types versioning (#15549)
Browse files Browse the repository at this point in the history
* Added a log for pull_request

* Added labels logging

* Using labels straight from event PR object

* Converting to JSON

* Switching to use payload

* Fixed issue with undefined pr

* Fixed non-mapping issue

* Removed the types

* Added another cache key segment using the head commit sha

* Added separate workflow for labeled action

* Fixed syntax error

* Fixing payload issue

* Added log

* logging full object

* Put e2e back in the names to help find them

* Limited logging

* fix: v2 even-types versioning

* test: old v2 even-types request with VERSION_2024_06_11

* test: old v2 even-types request with VERSION_2024_04_15

---------

Co-authored-by: Keith Williams <[email protected]>
  • Loading branch information
supalarry and keithwillcode authored Jun 24, 2024
1 parent 928dd49 commit 08f4a48
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .github/actions/cache-build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ runs:
key-2: ${{ hashFiles('apps/**/**.[jt]s', 'apps/**/**.[jt]sx', 'packages/**/**.[jt]s', 'packages/**/**.[jt]sx', '!**/node_modules') }}
key-3: ${{ github.event.pull_request.number || github.ref }}
key-4: ${{ github.sha }}
key-5: ${{ github.event.pull_request.head.sha }}
with:
path: |
${{ github.workspace }}/apps/web/.next
${{ github.workspace }}/apps/web/public/embed
**/.turbo/**
**/dist/**
key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.key-1 }}-${{ env.key-2 }}-${{ env.key-3 }}-${{ env.key-4 }}
key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.key-1 }}-${{ env.key-2 }}-${{ env.key-3 }}-${{ env.key-4 }}-${{ env.key-5 }}
- run: |
export NODE_OPTIONS="--max_old_space_size=8192"
yarn build
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/pr-labeled.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: PR Labeled with ready-for-e2e

on:
pull_request_target:
types: [labeled]
branches:
- main
- gh-actions-test-branch
workflow_dispatch:
jobs:
run-e2e-jobs:
name: Run E2E Jobs
runs-on: buildjet-2vcpu-ubuntu-2204
permissions:
pull-requests: read
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/dangerous-git-checkout

- name: Check Label and Retrigger Checks
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const labelName = context.payload.label.name;
const prNumber = context.payload.pull_request.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
if (labelName === 'ready-for-e2e') {
console.log(`Running E2E jobs for PR #${prNumber}...`);
const checkRuns = await github.rest.checks.listForRef({
owner,
repo,
ref: context.payload.pull_request.head.sha,
});
for (const check of checkRuns.data.check_runs) {
console.log('check.name', check.name);
if (check.name.includes('e2e')) {
await github.rest.actions.reRunJob({
owner,
repo,
job_id: check.id,
});
console.log(`Triggering job #${check.id}`);
}
}
console.log(`Triggered E2E checks for PR #${prNumber}`);
} else {
console.log(`Label ${labelName} does not trigger re-running checks.`);
}
9 changes: 4 additions & 5 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: PR Update

on:
pull_request_target:
types: [opened, synchronize, reopened, labeled]
branches:
- main
- gh-actions-test-branch
Expand Down Expand Up @@ -135,28 +134,28 @@ jobs:
secrets: inherit

e2e:
name: Tests
name: e2e
needs: [changes, check-label, build]
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
uses: ./.github/workflows/e2e.yml
secrets: inherit

e2e-app-store:
name: Tests
name: e2e-app-store
needs: [changes, check-label, build]
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
uses: ./.github/workflows/e2e-app-store.yml
secrets: inherit

e2e-embed:
name: Tests
name: e2e-embed
needs: [changes, check-label, build]
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
uses: ./.github/workflows/e2e-embed.yml
secrets: inherit

e2e-embed-react:
name: Tests
name: e2e-embed-react
needs: [changes, check-label, build]
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
uses: ./.github/workflows/e2e-embed-react.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ import { TeamRepositoryFixture } from "test/fixtures/repository/team.repository.
import { UserRepositoryFixture } from "test/fixtures/repository/users.repository.fixture";
import { withApiAuth } from "test/utils/withApiAuth";

import { SUCCESS_STATUS } from "@calcom/platform-constants";
import {
SUCCESS_STATUS,
VERSION_2024_06_11,
VERSION_2024_04_15,
CAL_API_VERSION_HEADER,
} from "@calcom/platform-constants";
import {
EventTypesByViewer,
EventTypesPublic,
Expand Down Expand Up @@ -154,6 +159,7 @@ describe("Event types Endpoints", () => {

return request(app.getHttpServer())
.post("/api/v2/event-types")
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
.send(body)
.expect(201)
.then(async (response) => {
Expand Down Expand Up @@ -184,6 +190,7 @@ describe("Event types Endpoints", () => {

return request(app.getHttpServer())
.patch(`/api/v2/event-types/${eventType.id}`)
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
.send(body)
.expect(200)
.then(async (response) => {
Expand Down Expand Up @@ -288,6 +295,25 @@ describe("Event types Endpoints", () => {
it(`/GET/:id`, async () => {
const response = await request(app.getHttpServer())
.get(`/api/v2/event-types/${eventType.id}`)
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
// note: bearer token value mocked using "withApiAuth" for user which id is used when creating event type above
.set("Authorization", `Bearer whatever`)
.expect(200);

const responseBody: GetEventTypeOutput = response.body;

expect(responseBody.status).toEqual(SUCCESS_STATUS);
expect(responseBody.data).toBeDefined();
expect(responseBody.data.eventType.id).toEqual(eventType.id);
expect(responseBody.data.eventType.title).toEqual(eventType.title);
expect(responseBody.data.eventType.slug).toEqual(eventType.slug);
expect(responseBody.data.eventType.userId).toEqual(user.id);
});

it(`/GET/:id with version VERSION_2024_06_11`, async () => {
const response = await request(app.getHttpServer())
.get(`/api/v2/event-types/${eventType.id}`)
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_11)
// note: bearer token value mocked using "withApiAuth" for user which id is used when creating event type above
.set("Authorization", `Bearer whatever`)
.expect(200);
Expand All @@ -305,6 +331,7 @@ describe("Event types Endpoints", () => {
it(`/GET/:username/public`, async () => {
const response = await request(app.getHttpServer())
.get(`/api/v2/event-types/${username}/public`)
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
// note: bearer token value mocked using "withApiAuth" for user which id is used when creating event type above
.set("Authorization", `Bearer whatever`)
.expect(200);
Expand All @@ -323,6 +350,7 @@ describe("Event types Endpoints", () => {
it(`/GET/:username/:eventSlug/public`, async () => {
const response = await request(app.getHttpServer())
.get(`/api/v2/event-types/${username}/${eventType.slug}/public`)
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
// note: bearer token value mocked using "withApiAuth" for user which id is used when creating event type above
.set("Authorization", `Bearer whatever`)
.expect(200);
Expand All @@ -340,6 +368,7 @@ describe("Event types Endpoints", () => {
it(`/GET/`, async () => {
const response = await request(app.getHttpServer())
.get(`/api/v2/event-types`)
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
// note: bearer token value mocked using "withApiAuth" for user which id is used when creating event type above
.set("Authorization", `Bearer whatever`)
.expect(200);
Expand All @@ -359,6 +388,7 @@ describe("Event types Endpoints", () => {
it(`/GET/public/:username/`, async () => {
const response = await request(app.getHttpServer())
.get(`/api/v2/event-types/${username}/public`)
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
// note: bearer token value mocked using "withApiAuth" for user which id is used when creating event type above
.set("Authorization", `Bearer whatever`)
.expect(200);
Expand All @@ -375,13 +405,17 @@ describe("Event types Endpoints", () => {
it(`/GET/:id not existing`, async () => {
await request(app.getHttpServer())
.get(`/api/v2/event-types/1000`)
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
// note: bearer token value mocked using "withApiAuth" for user which id is used when creating event type above
.set("Authorization", `Bearer whatever`)
.expect(404);
});

it("should delete schedule", async () => {
return request(app.getHttpServer()).delete(`/api/v2/event-types/${eventType.id}`).expect(200);
return request(app.getHttpServer())
.delete(`/api/v2/event-types/${eventType.id}`)
.set(CAL_API_VERSION_HEADER, VERSION_2024_04_15)
.expect(200);
});

afterAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "@/ee/event-types/event-types_2024_04_15/outputs/get-event-types.output";
import { UpdateEventTypeOutput } from "@/ee/event-types/event-types_2024_04_15/outputs/update-event-type.output";
import { EventTypesService_2024_04_15 } from "@/ee/event-types/event-types_2024_04_15/services/event-types.service";
import { VERSION_2024_04_15_VALUE } from "@/lib/api-versions";
import { VERSION_2024_04_15, VERSION_2024_06_11 } from "@/lib/api-versions";
import { GetUser } from "@/modules/auth/decorators/get-user/get-user.decorator";
import { Permissions } from "@/modules/auth/decorators/permissions/permissions.decorator";
import { ApiAuthGuard } from "@/modules/auth/guards/api-auth/api-auth.guard";
Expand Down Expand Up @@ -45,7 +45,7 @@ import { PrismaClient } from "@calcom/prisma";

@Controller({
path: "/v2/event-types",
version: VERSION_2024_04_15_VALUE,
version: [VERSION_2024_04_15, VERSION_2024_06_11],
})
@UseGuards(PermissionsGuard)
@DocsTags("Event types")
Expand Down
1 change: 1 addition & 0 deletions apps/api/v2/src/lib/api-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export const VERSION_2024_06_14_VALUE: VersionValue = VERSION_2024_06_14 as unkn
export const VERSION_2024_06_11_VALUE: VersionValue = VERSION_2024_06_11 as unknown as VersionValue;
export const VERSION_2024_04_15_VALUE: VersionValue = VERSION_2024_04_15 as unknown as VersionValue;

export { VERSION_2024_04_15 };
export { VERSION_2024_06_11 };
export { VERSION_2024_06_14 };

0 comments on commit 08f4a48

Please sign in to comment.