Skip to content

Commit

Permalink
ci:
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustav-Eikaas committed Jan 3, 2024
1 parent d892c4d commit 717fb5e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/manual-deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ jobs:
env:
#Runs out of memory when bundling more apps otherwise even though concurrency is 1
NODE_OPTIONS: '--max_old_space_size=4096'
run: npx turbo run fprd:deploy --filter=${{inputs.appKey}} --concurrency 1 -- --token ${{ steps.get-fusion-token.outputs.token }}
run: npx turbo run fprd:deploy --filter=${{inputs.appKey}} --concurrency 1 -- --token ${{ steps.get-fusion-token.outputs.token }} --ai '${{secrets.ai}}' --sha '${{github.sha}}'
32 changes: 25 additions & 7 deletions github-action/src/releaseMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,48 @@ import { prepareBundle } from './utils/prepareBundle.js';
import { makeManifest } from './utils/makeManifest.js';
import { zipBundle } from './utils/zipBundle.js';
import { uploadBundle } from './utils/uploadBundle.js';
import { patchAppConfig } from './utils/patchAppConfig.js';

const prodUrl = 'https://fusion-s-portal-fprd.azurewebsites.net';

const program = new Command();

program.name('Release');

type ReleaseArgs = {
token: string;
ai: string;
pr: string;
sha: string;
};
program
.command('release')
.option('-T, --token <token>', 'change the working directory')
.option('-T, --token <token>', 'azure token')
.option('-pr, --pr <pr>', 'Pr number')
.option('-ai, --ai <ai>', 'ai key')
.option('-sha, --sha <sha>', 'commit sha')
.action(async (args) => {
if (!args.token) {
throw new Error('Missing az token');
}
const r: ReleaseArgs = args;
setSecret(args.token);
release(args.token);
setSecret(args.ai);
release(r);
});

await program.parseAsync();

export async function release(token: string) {
const r = parsePackageJson();
if (!r.name) {
export async function release(config: ReleaseArgs) {
const pkg = parsePackageJson();
if (!pkg.name) {
throw new Error(
`No name in package json, cannot deploy unknown app at path ${process.cwd()}`
);
}

if (shouldSkipProd()) {
warning(`Prod skipped for ${r.name} because a prod.skip file was found`);
warning(`Prod skipped for ${pkg.name} because a prod.skip file was found`);
return;
}

Expand All @@ -47,7 +59,13 @@ export async function release(token: string) {

const zipped = zipBundle();

await uploadBundle(prodUrl, token, r.name, zipped);
await uploadBundle(prodUrl, config.token, pkg.name, zipped);
await patchAppConfig(
{ ai: config.ai, commit: config.sha },
config.token,
pkg.name,
prodUrl
);
}

function shouldSkipProd() {
Expand Down
2 changes: 1 addition & 1 deletion github-action/src/releasePr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type ReleaseArgs = {

program
.command('release')
.option('-T, --token <token>', 'change the working directory')
.option('-T, --token <token>', 'azure token')
.option('-pr, --pr <pr>', 'Pr number')
.option('-ai, --ai <ai>', 'ai key')
.option('-sha, --sha <sha>', 'commit sha')
Expand Down
6 changes: 2 additions & 4 deletions github-action/src/utils/patchAppConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ export async function patchAppConfig<T extends Record<PropertyKey, unknown> = {}
);
if (patchResponse.message.statusCode !== 200) {
logInfo(
`Failed to patch client config with pr number, Code: ${patchResponse.message.statusCode}`,
`Failed to patch client config, Code: ${patchResponse.message.statusCode}`,
'Red'
);
throw new Error(
`Failed to patch client config with pr number, ${await patchResponse.readBody()}`
);
throw new Error(`Failed to patch client config, ${await patchResponse.readBody()}`);
}
logInfo(`Sucessfully patched client config for ${appKey}`, 'Green');
}

0 comments on commit 717fb5e

Please sign in to comment.