Skip to content

Commit

Permalink
Deploy Production Code for Commit 008808e 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed May 9, 2022
1 parent 008808e commit 2826d18
Show file tree
Hide file tree
Showing 2,676 changed files with 1,315,302 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules
# node_moduless
now
lib
# lib
38 changes: 38 additions & 0 deletions lib/constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export interface ActionInterface {
/**
* The branch that the action should deploy to.
*
* @default "actions/filedb
*/
branch: string;
/**
* File or Folder path for storage
*/
path: string;
/**
* Token for github
*/
token?: string;
/**
* The folder where your deployment project lives.
*/
workspace: string;
/** The hostname of which the GitHub Workflow is being run on, ie: github.com */
hostname?: string;
/** The repository path, for example JamesIves/github-pages-deploy-action. */
repositoryName?: string;
/**
* Keep history only one commit
*/
singleCommit?: boolean;
/** Defines an SSH private key that can be used during deployment. This can also be set to true to use SSH deployment endpoints if you've already configured the SSH client outside of this package. */
sshKey?: string | boolean | null;
}
export declare const action: ActionInterface;
/** Status codes for the action. */
export declare enum Status {
SUCCESS = "success",
FAILED = "failed",
SKIPPED = "skipped",
RUNNING = "running"
}
61 changes: 61 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Status = exports.action = void 0;
const core_1 = require("@actions/core");
const utils_1 = require("./utils");
const github = __importStar(require("@actions/github"));
const { repository } = github.context.payload;
exports.action = {
branch: (0, core_1.getInput)('branch'),
path: (0, core_1.getInput)('path'),
token: (0, core_1.getInput)('token'),
workspace: (0, core_1.getInput)('workspace') || process.env.GITHUB_WORKSPACE || '.',
repositoryName: !(0, utils_1.isNullOrUndefined)((0, core_1.getInput)('repository-name'))
? (0, core_1.getInput)('repository-name')
: repository && repository.full_name
? repository.full_name
: process.env.GITHUB_REPOSITORY,
singleCommit: !(0, utils_1.isNullOrUndefined)((0, core_1.getInput)('single-commit'))
? (0, core_1.getInput)('single-commit').toLowerCase() === 'true'
: false,
hostname: process.env.GITHUB_SERVER_URL
? (0, utils_1.stripProtocolFromUrl)(process.env.GITHUB_SERVER_URL)
: 'github.com',
sshKey: (0, utils_1.isNullOrUndefined)((0, core_1.getInput)('ssh-key'))
? false
: !(0, utils_1.isNullOrUndefined)((0, core_1.getInput)('ssh-key')) &&
(0, core_1.getInput)('ssh-key').toLowerCase() === 'true'
? true
: (0, core_1.getInput)('ssh-key'),
};
/** Status codes for the action. */
var Status;
(function (Status) {
Status["SUCCESS"] = "success";
Status["FAILED"] = "failed";
Status["SKIPPED"] = "skipped";
Status["RUNNING"] = "running";
})(Status = exports.Status || (exports.Status = {}));
14 changes: 14 additions & 0 deletions lib/git.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ActionInterface, Status } from './constants';
/**
* check storage branch exist
*/
export declare function checkTargetBranchExist(options: ActionInterface): Promise<boolean>;
export declare function checkout(options: ActionInterface): Promise<Status>;
/**
* Save file into worktree
*/
export declare function save(options: ActionInterface): Promise<Status>;
/**
* clean jobs
*/
export declare function cleanupJobs(options: ActionInterface): Promise<void>;
157 changes: 157 additions & 0 deletions lib/git.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.cleanupJobs = exports.save = exports.checkout = exports.checkTargetBranchExist = void 0;
const core_1 = require("@actions/core");
const constants_1 = require("./constants");
const utils_1 = require("./utils");
const once_1 = __importDefault(require("lodash/once"));
const io_1 = require("@actions/io");
const authorName = 'filestorage-action';
const authorEmail = '[email protected]';
const gitAuthor = `${authorName} <${authorEmail}>`;
const init = (0, once_1.default)((options) => __awaiter(void 0, void 0, void 0, function* () {
(0, core_1.info)('Start check branch');
try {
yield (0, utils_1.execute)(`git config --global --add safe.directory "${options.workspace}"`, options.workspace);
}
catch (_a) {
(0, core_1.info)('Unable to set workspace as a safe directory…');
}
yield (0, utils_1.execute)(`git config core.ignorecase false`, options.workspace);
}));
/**
* check storage branch exist
*/
function checkTargetBranchExist(options) {
return __awaiter(this, void 0, void 0, function* () {
const repositoryPath = (0, utils_1.generateRepositoryPath)(options);
return Boolean((yield (0, utils_1.execute)(`git ls-remote --heads ${repositoryPath} refs/heads/${options.branch}`, options.workspace)).stdout);
});
}
exports.checkTargetBranchExist = checkTargetBranchExist;
const temporaryStorageDirectory = '.branch-filestorage-action-temp';
function checkout(options) {
return __awaiter(this, void 0, void 0, function* () {
yield init(options);
const branchExists = yield checkTargetBranchExist(options);
if (!branchExists) {
(0, core_1.info)('Target branch has not been create, skipped');
return constants_1.Status.SKIPPED;
}
yield generateWorktree(options, branchExists);
yield (0, utils_1.execute)(`cp -f ${options.workspace}/${temporaryStorageDirectory}/${options.path} ${options.workspace}/${options.path}`, options.workspace);
return constants_1.Status.SUCCESS;
});
}
exports.checkout = checkout;
/**
* Save file into worktree
*/
function save(options) {
return __awaiter(this, void 0, void 0, function* () {
yield init(options);
const branchExists = yield checkTargetBranchExist(options);
yield generateWorktree(options, branchExists);
yield (0, utils_1.execute)(`cp -f ${options.path} ${options.workspace}/${temporaryStorageDirectory}`, options.workspace);
if (options.singleCommit) {
yield (0, utils_1.execute)(`git add --all .`, `${options.workspace}/${temporaryStorageDirectory}`);
}
// Use git status to check if we have something to commit.
// Special case is singleCommit with existing history, when
// we're really interested if the diff against the upstream branch
// changed.
const checkGitStatus = branchExists && options.singleCommit
? `git diff origin/${options.branch}`
: `git status --porcelain`;
(0, core_1.info)(`Checking if there are files to commit…`);
const hasFilesToCommit = Boolean((yield (0, utils_1.execute)(checkGitStatus, `${options.workspace}/${temporaryStorageDirectory}`, true // This output is always silenced due to the large output it creates.
)).stdout);
if (!options.singleCommit && !hasFilesToCommit) {
// No file changed
return constants_1.Status.SKIPPED;
}
// Commits to GitHub.
yield (0, utils_1.execute)(`git add --all .`, `${options.workspace}/${temporaryStorageDirectory}`);
yield (0, utils_1.execute)(`git commit -m "update filestorage at ${new Date().toISOString()}" --quiet --no-verify --author="${gitAuthor}"`, `${options.workspace}/${temporaryStorageDirectory}`);
(0, core_1.info)(`Force-pushing changes...`);
yield (0, utils_1.execute)(`git push --force origin ${options.branch}`, `${options.workspace}/${temporaryStorageDirectory}`);
(0, core_1.info)(`Changes committed to the ${options.branch} branch… 📦`);
return constants_1.Status.SUCCESS;
});
}
exports.save = save;
/**
* clean jobs
*/
function cleanupJobs(options) {
return __awaiter(this, void 0, void 0, function* () {
yield (0, utils_1.execute)(`chmod -R +rw ${temporaryStorageDirectory}`, options.workspace);
yield (0, utils_1.execute)(`git worktree remove ${temporaryStorageDirectory} --force`, options.workspace);
yield (0, utils_1.execute)(`git branch -D ${options.branch}`, options.workspace);
yield (0, io_1.rmRF)(temporaryStorageDirectory);
});
}
exports.cleanupJobs = cleanupJobs;
/**
* generate worktree
*/
function generateWorktree(options, branchExists) {
return __awaiter(this, void 0, void 0, function* () {
(0, core_1.info)('Creating worktree…');
if (branchExists) {
yield (0, utils_1.execute)(`git fetch --no-recurse-submodules --depth=1 origin ${options.branch}`, options.workspace);
}
yield (0, utils_1.execute)(`git worktree add --no-checkout --detach ${temporaryStorageDirectory}`, options.workspace);
const checkout = new GitCheckout(options.branch);
if (branchExists) {
// There's existing data on the branch to check out
checkout.commitish = `origin/${options.branch}`;
}
if (!branchExists ||
(options.singleCommit && options.branch !== process.env.GITHUB_REF_NAME)) {
/* Create a new history if we don't have the branch, or if we want to reset it.
If the ref name is the same as the branch name, do not attempt to create an orphan of it. */
checkout.orphan = true;
}
yield (0, utils_1.execute)(checkout.toString(), `${options.workspace}/${temporaryStorageDirectory}`);
yield (0, utils_1.execute)(`git config user.name "${authorName}"`, `${options.workspace}/${temporaryStorageDirectory}`);
yield (0, utils_1.execute)(`git config user.email "${authorEmail}"`, `${options.workspace}/${temporaryStorageDirectory}`);
if (!branchExists) {
(0, core_1.info)(`Created the ${options.branch} branch… 🔧`);
// Our index is in HEAD state, reset
yield (0, utils_1.execute)('git reset --hard', `${options.workspace}/${temporaryStorageDirectory}`);
if (!options.singleCommit) {
// New history isn't singleCommit, create empty initial commit
yield (0, utils_1.execute)(`git commit --no-verify --allow-empty -m "Initial ${options.branch} commit" --author="${gitAuthor}"`, `${options.workspace}/${temporaryStorageDirectory}`);
}
}
});
}
class GitCheckout {
constructor(branch) {
this.orphan = false;
this.commitish = null;
this.branch = branch;
}
toString() {
return [
'git',
'checkout',
this.orphan ? '--orphan' : '-B',
this.branch,
this.commitish || '',
].join(' ');
}
}
9 changes: 9 additions & 0 deletions lib/lib.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ActionInterface } from './constants';
/**
* Checkout file from branch
*/
export declare function runCheckout(options: ActionInterface): Promise<void>;
/**
* Save file into branch
*/
export declare function runSave(options: ActionInterface): Promise<void>;
80 changes: 80 additions & 0 deletions lib/lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runSave = exports.runCheckout = void 0;
const core_1 = require("@actions/core");
const constants_1 = require("./constants");
const git_1 = require("./git");
const utils_1 = require("./utils");
/**
* Checkout file from branch
*/
function runCheckout(options) {
return __awaiter(this, void 0, void 0, function* () {
let status = constants_1.Status.RUNNING;
try {
status = yield (0, git_1.checkout)(options);
if (status === constants_1.Status.SUCCESS) {
yield (0, git_1.cleanupJobs)(options);
}
}
catch (error) {
status = constants_1.Status.FAILED;
(0, core_1.setFailed)((0, utils_1.extractErrorMessage)(error));
}
finally {
if (status === constants_1.Status.FAILED) {
(0, core_1.notice)('Checkout file failed! ❌');
}
else if (status === constants_1.Status.SUCCESS) {
(0, core_1.info)('Checkout Completed successfully! ✅');
}
else {
(0, core_1.info)('Exiting early… 📭');
}
(0, core_1.exportVariable)('storage_checkout_status', status);
(0, core_1.setOutput)('storage-checkout-status', status);
}
});
}
exports.runCheckout = runCheckout;
/**
* Save file into branch
*/
function runSave(options) {
return __awaiter(this, void 0, void 0, function* () {
let status = constants_1.Status.RUNNING;
try {
status = yield (0, git_1.save)(options);
if (status === constants_1.Status.SUCCESS) {
yield (0, git_1.cleanupJobs)(options);
}
}
catch (error) {
status = constants_1.Status.FAILED;
(0, core_1.setFailed)((0, utils_1.extractErrorMessage)(error));
}
finally {
if (status === constants_1.Status.FAILED) {
(0, core_1.notice)('Save file failed! ❌');
}
else if (status === constants_1.Status.SUCCESS) {
(0, core_1.info)('Save Completed successfully! ✅');
}
else {
(0, core_1.info)('Exiting early… 📭');
}
(0, core_1.exportVariable)('storage_save_status', status);
(0, core_1.setOutput)('storage-save-status', status);
}
});
}
exports.runSave = runSave;
1 change: 1 addition & 0 deletions lib/main.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
8 changes: 8 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("./constants");
const lib_1 = require("./lib");
/**
* checkout file
*/
(0, lib_1.runCheckout)(constants_1.action);
1 change: 1 addition & 0 deletions lib/post.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
8 changes: 8 additions & 0 deletions lib/post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("./constants");
const lib_1 = require("./lib");
/**
* Save file
*/
(0, lib_1.runSave)(constants_1.action);
Loading

0 comments on commit 2826d18

Please sign in to comment.