This commit is contained in:
eric sciple 2019-12-10 18:38:53 -05:00
parent 1e6a918852
commit 89cbb18acd
4 changed files with 82 additions and 19 deletions

52
dist/index.js vendored
View File

@ -2597,6 +2597,44 @@ function paginatePlugin(octokit) {
} }
/***/ }),
/***/ 153:
/***/ (function(__unusedmodule, exports, __webpack_require__) {
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const coreCommand = __importStar(__webpack_require__(431));
/**
* Indicates whether the POST action is running
*/
exports.IsPost = !!process.env['STATE_isPost'];
/**
* The repository path for the POST action. The value is empty during the MAIN action.
*/
exports.RepositoryPath = process.env['STATE_repositoryPath'];
/**
* Save the repository path so the POST action can retrieve the value.
*/
function setRepositoryPath(repositoryPath) {
coreCommand.issueCommand('save-state', { name: 'repositoryPath' }, repositoryPath);
}
exports.setRepositoryPath = setRepositoryPath;
// Publish a variable so that when the POST action runs, it can determine it should run the cleanup logic.
// This is necessary since we don't have a separate entry point.
if (!exports.IsPost) {
coreCommand.issueCommand('save-state', { name: 'isPost' }, 'true');
}
/***/ }), /***/ }),
/***/ 168: /***/ 168:
@ -2751,7 +2789,7 @@ const coreCommand = __importStar(__webpack_require__(431));
const gitSourceProvider = __importStar(__webpack_require__(293)); const gitSourceProvider = __importStar(__webpack_require__(293));
const inputHelper = __importStar(__webpack_require__(821)); const inputHelper = __importStar(__webpack_require__(821));
const path = __importStar(__webpack_require__(622)); const path = __importStar(__webpack_require__(622));
const cleanupRepositoryPath = process.env['STATE_repositoryPath']; const stateHelper = __importStar(__webpack_require__(153));
function run() { function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
@ -2775,7 +2813,7 @@ function run() {
function cleanup() { function cleanup() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
yield gitSourceProvider.cleanup(cleanupRepositoryPath); yield gitSourceProvider.cleanup(stateHelper.RepositoryPath);
} }
catch (error) { catch (error) {
core.warning(error.message); core.warning(error.message);
@ -2783,7 +2821,7 @@ function cleanup() {
}); });
} }
// Main // Main
if (!cleanupRepositoryPath) { if (!stateHelper.IsPost) {
run(); run();
} }
// Post // Post
@ -5049,22 +5087,20 @@ var __importStar = (this && this.__importStar) || function (mod) {
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(__webpack_require__(470)); const core = __importStar(__webpack_require__(470));
const coreCommand = __importStar(__webpack_require__(431));
const fs = __importStar(__webpack_require__(747)); const fs = __importStar(__webpack_require__(747));
const fsHelper = __importStar(__webpack_require__(618)); const fsHelper = __importStar(__webpack_require__(618));
const gitCommandManager = __importStar(__webpack_require__(289)); const gitCommandManager = __importStar(__webpack_require__(289));
const githubApiHelper = __importStar(__webpack_require__(464));
const io = __importStar(__webpack_require__(1)); const io = __importStar(__webpack_require__(1));
const path = __importStar(__webpack_require__(622)); const path = __importStar(__webpack_require__(622));
const refHelper = __importStar(__webpack_require__(227)); const refHelper = __importStar(__webpack_require__(227));
const githubApiHelper = __importStar(__webpack_require__(464)); const stateHelper = __importStar(__webpack_require__(153));
const authConfigKey = `http.https://github.com/.extraheader`; const authConfigKey = `http.https://github.com/.extraheader`;
function getSource(settings) { function getSource(settings) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
// Repository URL // Repository URL
core.info(`Syncing repository: ${settings.repositoryOwner}/${settings.repositoryName}`); core.info(`Syncing repository: ${settings.repositoryOwner}/${settings.repositoryName}`);
const repositoryUrl = `https://github.com/${encodeURIComponent(settings.repositoryOwner)}/${encodeURIComponent(settings.repositoryName)}`; const repositoryUrl = `https://github.com/${encodeURIComponent(settings.repositoryOwner)}/${encodeURIComponent(settings.repositoryName)}`;
// Set intra-task state for cleanup
coreCommand.issueCommand('save-state', { name: 'repositoryPath' }, settings.repositoryPath);
// Remove conflicting file path // Remove conflicting file path
if (fsHelper.fileExistsSync(settings.repositoryPath)) { if (fsHelper.fileExistsSync(settings.repositoryPath)) {
yield io.rmRF(settings.repositoryPath); yield io.rmRF(settings.repositoryPath);
@ -5088,6 +5124,8 @@ function getSource(settings) {
yield githubApiHelper.downloadRepository(settings.accessToken, settings.repositoryOwner, settings.repositoryName, settings.ref, settings.commit, settings.repositoryPath); yield githubApiHelper.downloadRepository(settings.accessToken, settings.repositoryOwner, settings.repositoryName, settings.ref, settings.commit, settings.repositoryPath);
} }
else { else {
// Save state for POST action
stateHelper.setRepositoryPath(settings.repositoryPath);
// Initialize the repository // Initialize the repository
if (!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))) { if (!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))) {
yield git.init(); yield git.init();

View File

@ -3,10 +3,11 @@ import * as coreCommand from '@actions/core/lib/command'
import * as fs from 'fs' import * as fs from 'fs'
import * as fsHelper from './fs-helper' import * as fsHelper from './fs-helper'
import * as gitCommandManager from './git-command-manager' import * as gitCommandManager from './git-command-manager'
import * as githubApiHelper from './github-api-helper'
import * as io from '@actions/io' import * as io from '@actions/io'
import * as path from 'path' import * as path from 'path'
import * as refHelper from './ref-helper' import * as refHelper from './ref-helper'
import * as githubApiHelper from './github-api-helper' import * as stateHelper from './state-helper'
import {IGitCommandManager} from './git-command-manager' import {IGitCommandManager} from './git-command-manager'
const authConfigKey = `http.https://github.com/.extraheader` const authConfigKey = `http.https://github.com/.extraheader`
@ -32,13 +33,6 @@ export async function getSource(settings: ISourceSettings): Promise<void> {
settings.repositoryOwner settings.repositoryOwner
)}/${encodeURIComponent(settings.repositoryName)}` )}/${encodeURIComponent(settings.repositoryName)}`
// Set intra-task state for cleanup
coreCommand.issueCommand(
'save-state',
{name: 'repositoryPath'},
settings.repositoryPath
)
// Remove conflicting file path // Remove conflicting file path
if (fsHelper.fileExistsSync(settings.repositoryPath)) { if (fsHelper.fileExistsSync(settings.repositoryPath)) {
await io.rmRF(settings.repositoryPath) await io.rmRF(settings.repositoryPath)
@ -79,6 +73,9 @@ export async function getSource(settings: ISourceSettings): Promise<void> {
settings.repositoryPath settings.repositoryPath
) )
} else { } else {
// Save state for POST action
stateHelper.setRepositoryPath(settings.repositoryPath)
// Initialize the repository // Initialize the repository
if ( if (
!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git')) !fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))

View File

@ -3,8 +3,7 @@ import * as coreCommand from '@actions/core/lib/command'
import * as gitSourceProvider from './git-source-provider' import * as gitSourceProvider from './git-source-provider'
import * as inputHelper from './input-helper' import * as inputHelper from './input-helper'
import * as path from 'path' import * as path from 'path'
import * as stateHelper from './state-helper'
const cleanupRepositoryPath = process.env['STATE_repositoryPath'] as string
async function run(): Promise<void> { async function run(): Promise<void> {
try { try {
@ -31,14 +30,14 @@ async function run(): Promise<void> {
async function cleanup(): Promise<void> { async function cleanup(): Promise<void> {
try { try {
await gitSourceProvider.cleanup(cleanupRepositoryPath) await gitSourceProvider.cleanup(stateHelper.RepositoryPath)
} catch (error) { } catch (error) {
core.warning(error.message) core.warning(error.message)
} }
} }
// Main // Main
if (!cleanupRepositoryPath) { if (!stateHelper.IsPost) {
run() run()
} }
// Post // Post

29
src/state-helper.ts Normal file
View File

@ -0,0 +1,29 @@
import * as core from '@actions/core'
import * as coreCommand from '@actions/core/lib/command'
/**
* Indicates whether the POST action is running
*/
export const IsPost = !!process.env['STATE_isPost']
/**
* The repository path for the POST action. The value is empty during the MAIN action.
*/
export const RepositoryPath = process.env['STATE_repositoryPath'] as string
/**
* Save the repository path so the POST action can retrieve the value.
*/
export function setRepositoryPath(repositoryPath: string) {
coreCommand.issueCommand(
'save-state',
{name: 'repositoryPath'},
repositoryPath
)
}
// Publish a variable so that when the POST action runs, it can determine it should run the cleanup logic.
// This is necessary since we don't have a separate entry point.
if (!IsPost) {
coreCommand.issueCommand('save-state', {name: 'isPost'}, 'true')
}