diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index be3e5d1c7..03b0e72a0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,9 +25,13 @@ jobs: - name: Install Dependencies run: npm i -g pnpm && pnpm i - # Run the action on the yarn-workspaces example - - name: Test Action - id: changedAction - uses: ./ - with: - turbo-command: idk --since origin/main -- --token ${{ env.FUSION_TOKEN }} + - name: 'deploy' + shell: bash + run: npx turbo run idk --since origin/main -- --token ${{ env.FUSION_TOKEN }} + + # # Run the action on the yarn-workspaces example + # - name: Test Action + # id: changedAction + # uses: ./ + # with: + # turbo-command: idk --since origin/main -- --token ${{ env.FUSION_TOKEN }} diff --git a/action.yml b/action.yml index eee1ddccb..6bc135f69 100644 --- a/action.yml +++ b/action.yml @@ -14,4 +14,4 @@ outputs: runs: using: 'node16' - main: 'github-action/script/main.js' + main: 'github-action/script/src/main.js' diff --git a/github-action/script/main.js b/github-action/script/main.js deleted file mode 100644 index 9aac4415e..000000000 --- a/github-action/script/main.js +++ /dev/null @@ -1,42 +0,0 @@ -import { execSync } from 'child_process'; -import { join } from 'path'; -import { - getInput, - debug, - setFailed, - setOutput, - setCommandEcho, - notice, - setSecret, -} from '@actions/core'; -const run = async () => { - try { - setCommandEcho(true); - const turboCommand = getInput('turbo-command', { required: true }); - setSecret(turboCommand); - const workingDirectory = getInput('working-directory', { required: false }) ?? './'; - const cwd = join(process.cwd(), workingDirectory); - debug(`Running command: ${turboCommand} in directory ${workingDirectory}`); - - const json = execSync(`npx turbo run ${turboCommand}`, { - cwd: cwd, - encoding: 'utf-8', - }); - - notice(json); - - debug(`Output from Turborepo: ${json}`); - const parsedOutput = JSON.parse(json); - debug(`Packages that changed ${parsedOutput.packages.toString()}`); - notice(`Packages that changed ${parsedOutput.packages.toString()}`); - const changed = !!parsedOutput.packages.length; - setOutput('changed', changed); - } catch (error) { - if (error instanceof Error || typeof error === 'string') { - setFailed(error); - } else { - setFailed('Unknown error occured.'); - } - } -}; -void run(); diff --git a/github-action/script/src/main.js b/github-action/script/src/main.js index 67aad6791..07d4857f3 100644 --- a/github-action/script/src/main.js +++ b/github-action/script/src/main.js @@ -12,6 +12,7 @@ const run = async () => { const json = execSync(`npx turbo run ${turboCommand}`, { cwd: cwd, encoding: 'utf-8', + stdio: 'inherit', }); } catch (error) { diff --git a/github-action/script/src/parsePackageJson.js b/github-action/script/src/parsePackageJson.js deleted file mode 100644 index e96c97d12..000000000 --- a/github-action/script/src/parsePackageJson.js +++ /dev/null @@ -1,5 +0,0 @@ -import fs from 'fs'; -export function parsePackageJson(path = './package.json') { - const blob = fs.readFileSync(path); - return JSON.parse(blob.toString('utf-8')); -} diff --git a/github-action/script/src/releasePr.js b/github-action/script/src/releasePr.js deleted file mode 100644 index 7a72c12a2..000000000 --- a/github-action/script/src/releasePr.js +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env node -import { Command } from 'commander'; -import fs from 'fs'; -import { chdir, cwd } from 'process'; -import { execSync } from 'child_process'; -import { parsePackageJson } from './parsePackageJson.js'; -import { resolve } from 'path'; -import AdmZip from 'adm-zip'; -import { HttpClient } from '@actions/http-client'; -import { Readable } from 'stream'; -import { notice, setSecret } from '@actions/core'; -const program = new Command(); -program.name('Release'); -program - .command('release') - .option('-T, --token ', 'change the working directory') - .action(async (args) => { - if (!args.token) { - throw new Error('Missing az token'); - } - setSecret(args.token); - release(args.token); -}); -await program.parseAsync(); -export async function release(token) { - execSync('echo releasing app'); - notice('building app'); - execSync('tsc -b -f'); - notice('building project'); - ensureProjectBuilds(); - // //Vite build - notice('bundling application'); - prepareBundle(); - // // Create manifest - notice('making manifest'); - makeManifest('./package.json'); - // //zip bundle - notice('zipping bundle'); - const zipped = zipBundle(); - const r = parsePackageJson(); - await uploadBundle(token, r.name, zipped); -} -async function uploadBundle(token, appKey, zipped) { - const client = new HttpClient(); - const headers = { - ['Authorization']: `Bearer ${token}`, - ['Content-Type']: 'application/zip', - ['Content-Disposition']: 'attachment; filename=bundle.zip', - }; - const stream = Readable.from(zipped.toBuffer()); - const r = await client.sendStream('POST', `https://fusion-s-portal-ci.azurewebsites.net/api/apps/${appKey}/versions`, stream, headers); - notice(`bundle uploaded with status code ${r.message.statusCode}`); - if (r.message.statusCode !== 200) { - throw new Error('Bundle failed to upload, fatal error'); - } - // /** Publish bundle */ - // const publishResponse = await client.post( - // `https://fusion-s-portal-ci.azurewebsites.net/api/apps/${appKey}/publish`, - // '', - // headers - // ); -} -function prepareBundle() { - const { name } = parsePackageJson(); - if (!name) { - throw new Error('Missing name in package.json'); - } - execSync('vite build --logLevel silent'); -} -function ensureProjectBuilds() { - const appDir = cwd(); - const rootDir = '../../'; - chdir(rootDir); - execSync(`pnpm ci:build`); - chdir(appDir); -} -export function makeManifest(path) { - const { version, name, ...maybe } = parsePackageJson(path); - if (!version || !name) { - throw new Error('Name or version missing in package.json'); - } - const { major, minor, patch } = splitVersions(version); - /** Some app-manifests have custom short and displaynames */ - const shortName = maybe?.['shortName'] ?? name; - const displayName = maybe?.['displayName'] ?? name[0].toUpperCase() + name.slice(1); - const manifest = { - name: displayName, - shortName: shortName, - key: name, - version: { - major: major, - minor: minor, - patch: patch, - }, - }; - const data = JSON.stringify(manifest, null, 2); - fs.writeFileSync('./dist/app-manifest.json', data); -} -function splitVersions(version) { - const [major, minor, patch] = version.split('.'); - return { - major, - minor, - patch, - }; -} -export function zipBundle() { - const appManifestPath = resolve('./dist/app-manifest.json'); - const bundlePath = resolve('./dist/app-bundle.js'); - var zip = new AdmZip(); - //TODO: scan files in package.json - zip.addLocalFile(appManifestPath); - zip.addLocalFile(bundlePath); - zip.writeZip('./dist/bundle.zip'); - return zip; -} diff --git a/github-action/src/main.ts b/github-action/src/main.ts index 2956917e8..c13e84805 100644 --- a/github-action/src/main.ts +++ b/github-action/src/main.ts @@ -25,6 +25,7 @@ const run = async (): Promise => { const json = execSync(`npx turbo run ${turboCommand}`, { cwd: cwd, encoding: 'utf-8', + stdio: 'inherit', }); } catch (error) { if (error instanceof Error || typeof error === 'string') { diff --git a/github-action/tsconfig.json b/github-action/tsconfig.json index 6a04efda8..1e594d32c 100644 --- a/github-action/tsconfig.json +++ b/github-action/tsconfig.json @@ -15,5 +15,6 @@ "allowSyntheticDefaultImports": true, "outDir": "script" }, - "exclude": ["node_modules"] + "exclude": ["node_modules"], + "include": ["./src/main.ts"] }