Skip to content

Commit 29402c9

Browse files
committed
Split main and post actions into separate scripts
1 parent 5425674 commit 29402c9

12 files changed

Lines changed: 9731 additions & 723 deletions

File tree

.github/workflows/build.yml

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,36 @@ name: Build
22

33
on:
44
push:
5-
paths-ignore:
6-
- dist/**
5+
paths:
6+
- "**/*.ts"
7+
- "package.json"
8+
- "tsconfig.json"
9+
- ".github/workflows/build.yml"
710

811
jobs:
912
build:
1013
runs-on: ubuntu-latest
1114
steps:
1215
- uses: actions/checkout@v2
13-
- run: npm i -g @vercel/ncc
14-
- run: npm install
15-
- run: ncc build index.ts --license licenses.txt
16+
- name: Install
17+
run: |
18+
npm i -g @vercel/ncc
19+
npm install
20+
- name: Build
21+
run: |
22+
ncc build main.ts
23+
mv dist/index.js dist/main.js
24+
ncc build post.ts
25+
mv dist/index.js dist/post.js
1626
- name: Commit & push
1727
run: |
18-
git config --global user.name 'Build Workflow'
19-
git config --global user.email 'defaultcommitter@orgflow.io'
20-
git add --force dist/index.js
21-
git add --force dist/licenses.txt
22-
git commit -m "Updates distributables"
23-
git push
28+
git add --all
29+
git add --force dist/main.js
30+
git add --force dist/post.js
31+
git status --porcelain
32+
if [[ `git status --porcelain` ]]; then
33+
git config --global user.name "Build Workflow"
34+
git config --global user.email "defaultcommitter@orgflow.io"
35+
git commit -m "Updates distributables"
36+
git push
37+
fi

.github/workflows/test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
name: Test
1+
name: Test2
22

33
on:
44
push:
55
paths:
6-
- dist/**
6+
- "**/*.js"
7+
- "action.yml"
8+
- ".github/workflows/test.yml"
79

810
jobs:
911

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"<node_internals>/**",
1010
"${workspaceFolder}/node_modules/**/*.js"
1111
],
12-
"program": "${workspaceFolder}/index.ts",
12+
"program": "${workspaceFolder}/main.ts",
1313
"preLaunchTask": "tsc: build",
1414
"outFiles": [
1515
"${workspaceFolder}/dist/**/*.js"

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ outputs:
6464
description: Encryption key that was saved.
6565
runs:
6666
using: node16
67-
main: dist/index.js
68-
post: dist/index.js
67+
main: dist/main.js
68+
post: dist/post.js

dist/licenses.txt

Lines changed: 0 additions & 519 deletions
This file was deleted.

dist/index.js renamed to dist/main.js

Lines changed: 152 additions & 149 deletions
Large diffs are not rendered by default.

dist/post.js

Lines changed: 9485 additions & 0 deletions
Large diffs are not rendered by default.

lib/diag.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import * as core from "@actions/core";
66
import * as io from "@actions/io";
77
import * as artifact from "@actions/artifact";
8+
import * as exec from "@actions/exec";
89
import * as path from "path";
10+
import { readdir } from "fs/promises";
911

1012
const tempDirPath = process.env.RUNNER_TEMP || process.env.TMPDIR;
1113
const artifactRootPath = path.join(tempDirPath, "OrgFlow");
@@ -19,23 +21,45 @@ if (!tempDirPath)
1921
const logDirPath = path.join(artifactRootPath, "logs");
2022
const bundleDirPath = path.join(artifactRootPath, "bundles")
2123

22-
console.log(`Diagnostic log directory: ${logDirPath}`);
23-
console.log(`Diagnostic bundle directory: ${bundleDirPath}`);
24+
core.debug(`Diagnostic log directory: ${logDirPath}`);
25+
core.debug(`Diagnostic bundle directory: ${bundleDirPath}`);
2426

2527
export function setDiagnostics(logFileName: string, logLevel: string)
2628
{
2729
io.mkdirP(logDirPath);
2830
io.mkdirP(bundleDirPath);
2931

32+
const logFilePath = path.join(logDirPath, logFileName);
33+
34+
core.debug(`Setting ORGFLOW_DIAGNOSTICSFILEDIRECTORYPATH=${bundleDirPath}`);
35+
core.debug(`Setting ORGFLOW_LOGFILEPATH=${logFilePath}`);
36+
3037
core.exportVariable("ORGFLOW_DIAGNOSTICBUNDLEMODE", "always");
3138
core.exportVariable("ORGFLOW_DIAGNOSTICSFILEDIRECTORYPATH", bundleDirPath);
32-
const logFilePath = path.join(logDirPath, logFileName);
3339
core.exportVariable("ORGFLOW_LOGFILEPATH", logFilePath);
3440
core.exportVariable("ORGFLOW_LOGLEVEL", logLevel);
3541
}
3642

3743
export async function uploadDiagnosticsArtifact()
3844
{
39-
const client = artifact.create();
40-
await client.uploadArtifact(artifactName, [bundleDirPath, logDirPath], artifactRootPath, { continueOnError: true });
45+
const { stdout } = await exec.getExecOutput("ls", ["-R", artifactRootPath], { silent: true });
46+
47+
core.debug(`Recursive contents of artifact root path '${artifactRootPath}':`);
48+
core.debug(stdout);
49+
50+
const artifactFiles = [
51+
...(await readdir(bundleDirPath)).map(fileName => path.join(bundleDirPath, fileName)),
52+
...(await readdir(logDirPath)).map(fileName => path.join(logDirPath, fileName))
53+
];
54+
55+
if (artifactFiles.length)
56+
{
57+
core.debug(`Uploading ${artifactFiles.length} artifact files: ${artifactFiles.join(", ")}`);
58+
const client = artifact.create();
59+
await client.uploadArtifact(artifactName, artifactFiles, artifactRootPath, { continueOnError: true });
60+
}
61+
else
62+
{
63+
core.debug("No artifact files no upload.");
64+
}
4165
}

index.ts renamed to main.ts

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as core from "@actions/core";
66
import { install } from "./lib/install";
77
import { createEncryptionKey, saveEncryptionKey, saveSalesforceCredentials, setDefaultStack, setLicenseKey } from "./lib/cli";
88
import { setCommitterEmail, setCommitterName, configureGitAuthentication } from "./lib/git";
9-
import { setDiagnostics, uploadDiagnosticsArtifact } from "./lib/diag";
9+
import { setDiagnostics } from "./lib/diag";
1010

1111
export async function run()
1212
{
@@ -149,33 +149,4 @@ export async function run()
149149
}
150150
}
151151

152-
export async function post()
153-
{
154-
try
155-
{
156-
const uploadArtifact =
157-
core.getInput("upload-artifact") ? // getBooleanInput() will throw if input is not present, so guard against that
158-
core.getBooleanInput("upload-artifact") :
159-
true;
160-
161-
if (uploadArtifact)
162-
{
163-
await uploadDiagnosticsArtifact();
164-
}
165-
}
166-
catch (error)
167-
{
168-
core.setFailed(error.message);
169-
}
170-
}
171-
172-
export const isPost = Boolean(process.env['STATE_isPost']);
173-
174-
if (!isPost)
175-
{
176-
run();
177-
}
178-
else
179-
{
180-
post();
181-
}
152+
run();

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)