Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split main/post steps #113

Merged
merged 1 commit into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ inputs:
description: For non-root dev containers (i.e. where `remoteUser` is specified), the action attempts to make the container user UID and GID match those of the host user. Set this to true to skip this step (defaults to false)
runs:
using: 'node16'
main: 'github-action/dist/index.js'
post: 'github-action/dist/index.js'
main: 'github-action/run-main.js'
post: 'github-action/run-post.js'
post-if: 'success()'
20 changes: 4 additions & 16 deletions azdo-task/DevContainerBuildRun/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,32 +220,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.runPost = exports.runMain = void 0;
const task = __importStar(__nccwpck_require__(347));
const task_1 = __nccwpck_require__(347);
const path_1 = __importDefault(__nccwpck_require__(5622));
const envvars_1 = __nccwpck_require__(9243);
const dev_container_cli_1 = __nccwpck_require__(4624);
const docker_1 = __nccwpck_require__(3758);
const exec_1 = __nccwpck_require__(7757);
function run() {
return __awaiter(this, void 0, void 0, function* () {
console.log('DevContainerBuildRun starting...');
const hasRunMain = task.getTaskVariable('hasRunMain');
if (hasRunMain === 'true') {
console.log('DevContainerBuildRun running post step...');
return yield runPost();
}
else {
console.log('DevContainerBuildRun running main step...');
task.setTaskVariable('hasRunMain', 'true');
return yield runMain();
}
});
}
function runMain() {
var _a, _b, _c, _d, _e, _f, _g;
return __awaiter(this, void 0, void 0, function* () {
try {
task.setTaskVariable('hasRunMain', 'true');
const buildXInstalled = yield docker_1.isDockerBuildXInstalled();
if (!buildXInstalled) {
console.log('### WARNING: docker buildx not available: add a step to set up with docker/setup-buildx-action - see https://github.com/stuartleeks/devcontainer-build-run/blob/main/docs/azure-devops-task.md');
Expand Down Expand Up @@ -345,6 +332,7 @@ function runMain() {
}
});
}
exports.runMain = runMain;
function runPost() {
var _a, _b, _c, _d, _e, _f;
return __awaiter(this, void 0, void 0, function* () {
Expand Down Expand Up @@ -395,7 +383,7 @@ function runPost() {
yield docker_1.pushImage(imageName, imageTag);
});
}
run();
exports.runPost = runPost;


/***/ }),
Expand Down
2 changes: 1 addition & 1 deletion azdo-task/DevContainerBuildRun/dist/index.js.map

Large diffs are not rendered by default.

20 changes: 4 additions & 16 deletions azdo-task/DevContainerBuildRun/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runPost = exports.runMain = void 0;
const task = __importStar(require("azure-pipelines-task-lib/task"));
const task_1 = require("azure-pipelines-task-lib/task");
const path_1 = __importDefault(require("path"));
const envvars_1 = require("../../../common/src/envvars");
const dev_container_cli_1 = require("../../../common/src/dev-container-cli");
const docker_1 = require("./docker");
const exec_1 = require("./exec");
function run() {
return __awaiter(this, void 0, void 0, function* () {
console.log('DevContainerBuildRun starting...');
const hasRunMain = task.getTaskVariable('hasRunMain');
if (hasRunMain === 'true') {
console.log('DevContainerBuildRun running post step...');
return yield runPost();
}
else {
console.log('DevContainerBuildRun running main step...');
task.setTaskVariable('hasRunMain', 'true');
return yield runMain();
}
});
}
function runMain() {
var _a, _b, _c, _d, _e, _f, _g;
return __awaiter(this, void 0, void 0, function* () {
try {
task.setTaskVariable('hasRunMain', 'true');
const buildXInstalled = yield docker_1.isDockerBuildXInstalled();
if (!buildXInstalled) {
console.log('### WARNING: docker buildx not available: add a step to set up with docker/setup-buildx-action - see https://github.com/stuartleeks/devcontainer-build-run/blob/main/docs/azure-devops-task.md');
Expand Down Expand Up @@ -156,6 +143,7 @@ function runMain() {
}
});
}
exports.runMain = runMain;
function runPost() {
var _a, _b, _c, _d, _e, _f;
return __awaiter(this, void 0, void 0, function* () {
Expand Down Expand Up @@ -206,4 +194,4 @@ function runPost() {
yield docker_1.pushImage(imageName, imageTag);
});
}
run();
exports.runPost = runPost;
3 changes: 3 additions & 0 deletions azdo-task/DevContainerBuildRun/run-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { runMain } = require("./dist/index.js");

runMain();
3 changes: 3 additions & 0 deletions azdo-task/DevContainerBuildRun/run-post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { runPost } = require("./dist/index.js");

runPost();
20 changes: 3 additions & 17 deletions azdo-task/DevContainerBuildRun/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,9 @@ import {
import {isDockerBuildXInstalled, pushImage} from './docker'
import {exec} from './exec'

async function run(): Promise<void> {
console.log('DevContainerBuildRun starting...')
const hasRunMain = task.getTaskVariable('hasRunMain')
if (hasRunMain === 'true') {
console.log('DevContainerBuildRun running post step...')
return await runPost()
} else {
console.log('DevContainerBuildRun running main step...')
task.setTaskVariable('hasRunMain', 'true')
return await runMain()
}
}

async function runMain(): Promise<void> {
export async function runMain(): Promise<void> {
try {
task.setTaskVariable('hasRunMain', 'true')
const buildXInstalled = await isDockerBuildXInstalled()
if (!buildXInstalled) {
console.log(
Expand Down Expand Up @@ -143,7 +131,7 @@ async function runMain(): Promise<void> {
}
}

async function runPost(): Promise<void> {
export async function runPost(): Promise<void> {
const pushOption = task.getInput('push') ?? 'filter'
const pushOnFailedBuild =
(task.getInput('pushOnFailedBuild') ?? 'false') === 'true'
Expand Down Expand Up @@ -209,5 +197,3 @@ async function runPost(): Promise<void> {
console.log(`Pushing image ''${imageName}:${imageTag ?? 'latest'}...`)
await pushImage(imageName, imageTag)
}

run()
4 changes: 2 additions & 2 deletions azdo-task/DevContainerBuildRun/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@
"outputVariables": [],
"execution": {
"Node10": {
"target": "dist/index.js",
"target": "run-main.js",
"argumentFormat": ""
}
},
"postjobexecution": {
"Node10": {
"target": "dist/index.js",
"target": "run-post.js",
"argumentFormat": ""
}
}
Expand Down
17 changes: 4 additions & 13 deletions github-action/dist/index.js

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

2 changes: 1 addition & 1 deletion github-action/dist/index.js.map

Large diffs are not rendered by default.

17 changes: 4 additions & 13 deletions github-action/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runPost = exports.runMain = void 0;
const core = __importStar(require("@actions/core"));
const path_1 = __importDefault(require("path"));
const exec_1 = require("./exec");
const dev_container_cli_1 = require("../../common/src/dev-container-cli");
const docker_1 = require("./docker");
const envvars_1 = require("../../common/src/envvars");
function run() {
return __awaiter(this, void 0, void 0, function* () {
const hasRunMain = core.getState('hasRunMain');
if (hasRunMain === 'true') {
return yield runPost();
}
else {
core.saveState('hasRunMain', 'true');
return yield runMain();
}
});
}
function runMain() {
return __awaiter(this, void 0, void 0, function* () {
try {
core.info('Starting...');
core.saveState('hasRunMain', 'true');
const buildXInstalled = yield docker_1.isDockerBuildXInstalled();
if (!buildXInstalled) {
core.warning('docker buildx not available: add a step to set up with docker/setup-buildx-action - see https://github.com/stuartleeks/devcontainer-build-run/blob/main/docs/github-action.md');
Expand Down Expand Up @@ -142,6 +132,7 @@ function runMain() {
}
});
}
exports.runMain = runMain;
function runPost() {
return __awaiter(this, void 0, void 0, function* () {
const pushOption = valueOrDefault(core.getInput('push'), 'filter');
Expand Down Expand Up @@ -176,6 +167,7 @@ function runPost() {
yield docker_1.pushImage(imageName, imageTag);
});
}
exports.runPost = runPost;
function valueOrDefault(value, defaultValue) {
if (!value || value === '') {
return defaultValue;
Expand All @@ -188,4 +180,3 @@ function emptyStringAsUndefined(value) {
}
return value;
}
run();
3 changes: 3 additions & 0 deletions github-action/run-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { runMain } = require("./dist/index.js");

runMain();
3 changes: 3 additions & 0 deletions github-action/run-post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { runPost } = require("./dist/index.js");

runPost();
16 changes: 3 additions & 13 deletions github-action/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,10 @@ import {
import {isDockerBuildXInstalled, pushImage} from './docker'
import {populateDefaults} from '../../common/src/envvars'

async function run(): Promise<void> {
const hasRunMain = core.getState('hasRunMain')
if (hasRunMain === 'true') {
return await runPost()
} else {
core.saveState('hasRunMain', 'true')
return await runMain()
}
}
async function runMain(): Promise<void> {
export async function runMain(): Promise<void> {
try {
core.info('Starting...')
core.saveState('hasRunMain', 'true')
const buildXInstalled = await isDockerBuildXInstalled()
if (!buildXInstalled) {
core.warning(
Expand Down Expand Up @@ -131,7 +123,7 @@ async function runMain(): Promise<void> {
}
}

async function runPost(): Promise<void> {
export async function runPost(): Promise<void> {
const pushOption: string = valueOrDefault(core.getInput('push'), 'filter')
const refFilterForPush: string[] = core.getMultilineInput('refFilterForPush')
const eventFilterForPush: string[] =
Expand Down Expand Up @@ -187,5 +179,3 @@ function emptyStringAsUndefined(value: string): string | undefined {
}
return value
}

run()