Skip to content

Commit

Permalink
yolo ci
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-bompart committed Feb 6, 2024
1 parent ed78ac0 commit 0276730
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 58 deletions.
4 changes: 4 additions & 0 deletions .github/actions/e2e-clean/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ runs:
shell: bash
if: cancelled() || failure() || success()
run: node ./scripts/cleaning/delete-api-keys.js
- name: Delete test NGSPs
shell: bash
if: cancelled() || failure() || success()
run: node ./scripts/cleaning/delete-ngsp.js
4 changes: 4 additions & 0 deletions .github/workflows/delete-resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ jobs:
timeout-minutes: 30
if: cancelled() || failure() || success()
run: node ./scripts/cleaning/delete-api-keys.js --olderThan 1d
- name: Delete test NGSP
timeout-minutes: 30
if: cancelled() || failure() || success()
run: node ./scripts/cleaning/delete-api-ngsp.js --olderThan 1d
- name: Delete test orgs
timeout-minutes: 30
if: cancelled() || failure() || success()
Expand Down
30 changes: 12 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 45 additions & 2 deletions packages/cli-e2e/__tests__/atomic.specs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {Browser, Page, HTTPResponse} from 'puppeteer';
import type {Browser, Page, HTTPResponse, Platform} from 'puppeteer';
import {captureScreenshots, getNewBrowser, openNewPage} from '../utils/browser';
import {answerPrompt, getProjectPath, setupUIProject} from '../utils/cli';
import {isSuccessfulSearchResponse} from '../utils/platform';
import {getPlatformClient, isSuccessfulSearchResponse} from '../utils/platform';
import {ProcessManager} from '../utils/processManager';
import {Terminal} from '../utils/terminal/terminal';
import {BrowserConsoleInterceptor} from '../utils/browserConsoleInterceptor';
Expand All @@ -10,6 +10,7 @@ import {EOL} from 'os';
import {join, resolve} from 'path';
import {hashElement} from 'folder-hash';
import {existsSync, symlinkSync, unlinkSync} from 'fs';
import PlatformClient from '@coveo/platform-client';

interface BuildAppOptions {
id: string;
Expand Down Expand Up @@ -120,6 +121,16 @@ describe('ui:create:atomic', () => {
),
]);

await Promise.allSettled(
streams.map((stream) =>
buildTerminal
.when(/\(y\)/)
.on(stream)
.do(answerPrompt(`n${EOL}`))
.once()
)
);

await Promise.allSettled(
streams.map((stream) =>
buildTerminal
Expand Down Expand Up @@ -150,6 +161,23 @@ describe('ui:create:atomic', () => {
`${debugName}-${options.id}`
);
};
let freshNgspId: string;
let platformClient: PlatformClient;
beforeAll(async () => {
platformClient = getPlatformClient(
process.env.ORG_ID!,
process.env.PLATFORM_API_KEY!
);
freshNgspId = (
await platformClient.nextGenSearchPages.create({
name: getProjectName('from-platform'),
})
).id;
});

afterAll(async () => {
await platformClient.nextGenSearchPages.delete(freshNgspId);
});

describe.each([
{
Expand All @@ -161,6 +189,21 @@ describe('ui:create:atomic', () => {
},
skipBrowser: false,
},
{
describeName: 'when using a fresh ngsp (--pageId flag specified)',
buildAppOptions: Object.defineProperties(
{
id: 'fresh-ngsp',
skipInstall: false,
},
{
pageId: {
get: () => freshNgspId,
},
}
),
skipBrowser: false,
},
{
describeName: 'when using the default page config (pageId not specified)',
buildAppOptions: {id: 'without-page-id', skipInstall: true},
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/core/src/commands/org/search/dump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export default class Dump extends CLICommand {
}),
...(params.pipeline && {pipeline: params.pipeline}),
...(indexToken !== '' && {indexToken: indexToken}),
})) as SearchResponse;
})) as unknown as SearchResponse;
return results;
} catch (error) {
if (this.isResponseExceededMaximumSizeError(error)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/core/src/commands/ui/create/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const manuallyEnterSearchHub = () =>

export async function promptForSearchHub(client: PlatformClient) {
const createSearchHub = await confirm(
'An API key will be created against your organization. We strongly recommends that you associate this API key with a search hub. Would you like to do so now ? y/n',
'An API key will be created against your organization. We strongly recommends that you associate this API key with a search hub. Would you like to do so now ? (y/n)',
false
);
if (!createSearchHub) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/source/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@coveo/cli-commons": "2.7.15",
"@coveo/platform-client": "52.1.0",
"@coveo/push-api-client": "3.1.15",
"@coveo/push-api-client": "4.0.1",
"@oclif/core": "1.24.0",
"@oclif/plugin-help": "5.1.23",
"@oclif/plugin-plugins": "2.1.12",
Expand Down
45 changes: 12 additions & 33 deletions packages/ui/atomic/create-atomic/src/fetch-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
/**
* @coveo/platform-client's IManifestResponse with simplified configuration
*/
export interface IManifest extends Omit<IManifestResponse, 'config'> {
export interface IManifest extends Omit<IManifestResponse<never>, 'config'> {
config: Pick<ISearchInterfaceConfigurationResponse, 'name'>;
}

Expand All @@ -20,28 +20,22 @@ export async function fetchPageManifest(
platformUrl: string
) {
let manifestGetters = [];
// if (type !== 'next-gen') {
// manifestGetters.push(getLegacyManifest);
// }
if (type !== 'next-gen') {
manifestGetters.push(getLegacyManifest);
}
if (type !== 'legacy') {
manifestGetters.push(getNextGenManifest);
}
for (const manifestGetter of manifestGetters) {
let manifest: IManifest;
try {
manifest = await manifestGetter(
client,
pageId,
apiKey,
orgId,
platformUrl
);
manifest = await manifestGetter(client, pageId);
} catch (error) {
continue;
}
return replaceResultsPlaceholder(manifest);
}
throw 'PANIC';
throw new Error('Could not fetch the page manifest');
}

function replaceResultsPlaceholder(manifestResponse: IManifest) {
Expand Down Expand Up @@ -69,26 +63,11 @@ async function getLegacyManifest(

async function getNextGenManifest(
client: PlatformClient,
pageId: string,
apiKey: string,
orgId: string,
platformUrl: string
pageId: string
): Promise<IManifest> {
return (
await fetch(
`http://localhost:8222/rest/organizations/${orgId}/searchpage/v1/interfaces/${pageId}/manifest`,
{
headers: {
Authorization: `Bearer ${apiKey}`,
},
body: {
//@ts-ignore shush, it works.
pagePlaceholders: {
results: '--results--',
},
},
method: 'POST',
}
)
).json() as Promise<IManifest>;
return await client.nextGenSearchPages.manifest(pageId, {
pagePlaceholders: {
results: '--results--',
},
});
}
40 changes: 40 additions & 0 deletions scripts/cleaning/delete-ngsp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const {homedir} = require('os');
const {join} = require('path');
const {config} = require('dotenv');
const {getClient, yargGenerator, wasCreatedBefore} = require('./utils');
config({path: join(homedir(), '.env')});

async function deleteNgsp(platform, idsToDelete) {
for (const id of idsToDelete) {
console.log(`Deleting ${id}`);
await platform.nextGenSearchPages.delete(id);
}
console.log(`\nDeleted ${idsToDelete.length} API keys`);
}

async function main(amount, unit) {
const {
ORG_ID: testOrgId,
TEST_RUN_ID: testRunId,
PLATFORM_API_KEY: accessToken,
PLATFORM_ENV: env,
} = process.env;
const platform = getClient(accessToken, env, testOrgId);
try {
const pages = await platform.nextGenSearchPages.list({filter: 'cli-id'});

const cliApiKeys = pages
.filter(page=>page.name.includes(testRunId))
.filter(wasCreatedBefore(amount, unit));

await deleteNgsp(platform, cliApiKeys);
} catch (error) {
console.log(error);
process.exit(1);
}
}

const argv = yargGenerator('NGSP');

const {amount, unit} = argv.olderThan;
main(amount, unit);
8 changes: 6 additions & 2 deletions scripts/cleaning/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ function getClient(accessToken, env, organizationId) {
}

function wasCreatedBefore(amount, unit) {
return (key) => {
return (resource) => {
const limit = moment().subtract(amount, unit);
return moment(key.createdDate).isBefore(limit);
for (const createField of ['createdDate', 'created']) {
if (resource[createField]) {
return moment(resource[createField]).isBefore(limit);
}
}
};
}

Expand Down

0 comments on commit 0276730

Please sign in to comment.