Skip to content

Commit

Permalink
v1.1.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
terryknowlton committed Dec 5, 2024
1 parent c77e6ae commit 5845643
Show file tree
Hide file tree
Showing 818 changed files with 398,430 additions and 46,638 deletions.
2 changes: 1 addition & 1 deletion lib/environmentVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ var EnvironmentVariables;
EnvironmentVariables["CI_REPO_NAME"] = "CI_REPO_NAME";
EnvironmentVariables["CI_STRING_TIME"] = "CI_STRING_TIME";
EnvironmentVariables["CI_TIMESTAMP"] = "CI_TIMESTAMP";
})(EnvironmentVariables = exports.EnvironmentVariables || (exports.EnvironmentVariables = {}));
})(EnvironmentVariables || (exports.EnvironmentVariables = EnvironmentVariables = {}));
95 changes: 67 additions & 28 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,51 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
}) : 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;
};
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const github = __importStar(require("@actions/github"));
const environmentVariables_1 = require("./environmentVariables");
const uuid_1 = require("uuid");
async function run() {
const projectId = core.getInput('project-id', { required: false });
const context = github.context;
const event = context.payload;
const projectId = core.getInput('project-id', {
required: false,
});
if (projectId) {
setVariable(environmentVariables_1.EnvironmentVariables.CI_PROJECT_ID, projectId);
}
const context = github.context;
setVariable(environmentVariables_1.EnvironmentVariables.CI, 'true');
setVariable(environmentVariables_1.EnvironmentVariables.CI_NAME, 'github');
// TODO get from toolkit - isn't available in that object presently, found in '${{ github.run_id }}'
// @ts-ignore
const buildId = context?.run_id ?? (0, uuid_1.v4)(); // use UUID until GitHub library starts working
const buildId = context?.runId?.toString() ?? (0, uuid_1.v4)(); // use UUID until GitHub library starts working
setVariable(environmentVariables_1.EnvironmentVariables.CI_BUILD_ID, buildId);
setVariable(environmentVariables_1.EnvironmentVariables.CI_BUILD_APPROVED, 'false');
setVariable(environmentVariables_1.EnvironmentVariables.CI_COMMIT_ID, context?.sha);
const headCommit = event?.head_commit;
const author = headCommit?.author;
setVariable(environmentVariables_1.EnvironmentVariables.CI_COMMIT_MESSAGE, headCommit?.message);
setVariable(environmentVariables_1.EnvironmentVariables.CI_COMMITTER_USERNAME, author?.username);
setVariable(environmentVariables_1.EnvironmentVariables.CI_COMMITTER_EMAIL, author?.email);
setVariable(environmentVariables_1.EnvironmentVariables.CI_COMMITTER_NAME, author?.name);
const event = context.payload;
const eventName = context.eventName;
if (eventName === 'push') {
const pushPayload = event;
populatePushEventCommitDetails(pushPayload, context);
}
else if (eventName === 'pull_request') {
const pullRequestPayload = event;
populatePullRequestEventCommitDetails(pullRequestPayload, context);
}
// TODO add expected description (rather complex to dig up), made by `git describe`
// Expected description format - "2019-07-18.1563481767-1-g7f60" < 'g<first 4 sha char>'
// commit date branched from ^ same sec ^ ^ commit number on branch (0 is the commit you branched from)
Expand All @@ -58,19 +70,46 @@ async function run() {
const nowAsTimeExpectedIsoString = nowAsTimeIsoString.replace(/\.\d{3}Z/, 'Z'); // No millis expect
setVariable(environmentVariables_1.EnvironmentVariables.CI_TIMESTAMP, nowSeconds.toString());
setVariable(environmentVariables_1.EnvironmentVariables.CI_STRING_TIME, nowAsTimeExpectedIsoString);
setVariable(environmentVariables_1.EnvironmentVariables.CI_REPO_NAME, event?.repository?.name);
}
function populatePushEventCommitDetails(pushEvent, context) {
const headCommit = pushEvent.head_commit;
const author = headCommit?.author;
setVariable(environmentVariables_1.EnvironmentVariables.CI_COMMIT_ID, context?.sha);
setVariable(environmentVariables_1.EnvironmentVariables.CI_COMMIT_MESSAGE, headCommit?.message);
setVariable(environmentVariables_1.EnvironmentVariables.CI_COMMITTER_USERNAME, author?.username);
setVariable(environmentVariables_1.EnvironmentVariables.CI_COMMITTER_EMAIL, author?.email ?? '');
setVariable(environmentVariables_1.EnvironmentVariables.CI_COMMITTER_NAME, author?.name);
const branchName = context?.ref?.match(/[^/]+$/)?.[0];
if (branchName) {
setVariable(environmentVariables_1.EnvironmentVariables.CI_BRANCH, branchName);
}
// @ts-ignore - missing lib defs
setVariable(environmentVariables_1.EnvironmentVariables.CI_REPO_NAME, event?.repository?.name);
// TODO The pull request payload is missing in this implementation (tested with PR builds)
// Note: the PR functionality in Codeship is not function from my empirical testing, so this behavior is the same as Codeship
const pullRequest = event?.pull_request;
setVariable(environmentVariables_1.EnvironmentVariables.CI_PULL_REQUEST, pullRequest?.number?.toString() ?? '');
setVariable(environmentVariables_1.EnvironmentVariables.CI_PR_NUMBER, pullRequest?.html_url ?? 'false');
}
function setVariable(name, value) {
async function populatePullRequestEventCommitDetails(pullRequestEvent, context) {
const head = pullRequestEvent.pull_request.head;
setVariable(environmentVariables_1.EnvironmentVariables.CI_BRANCH, head?.ref);
setVariable(environmentVariables_1.EnvironmentVariables.CI_COMMIT_ID, head?.sha);
setVariable(environmentVariables_1.EnvironmentVariables.CI_COMMITTER_USERNAME, pullRequestEvent.sender?.login);
setVariable(environmentVariables_1.EnvironmentVariables.CI_PULL_REQUEST, pullRequestEvent.pull_request.url);
setVariable(environmentVariables_1.EnvironmentVariables.CI_PR_NUMBER, pullRequestEvent.number?.toString());
const GITHUB_TOKEN = core.getInput('github-token');
if (GITHUB_TOKEN) {
const octokit = github.getOctokit(GITHUB_TOKEN);
const response = await octokit.rest.repos.getCommit({
owner: context.repo.owner,
repo: context.repo.repo,
ref: head?.sha,
});
const commit = response.data?.commit;
setVariable(environmentVariables_1.EnvironmentVariables.CI_COMMIT_MESSAGE, commit?.message);
setVariable(environmentVariables_1.EnvironmentVariables.CI_COMMITTER_EMAIL, commit?.author?.email);
setVariable(environmentVariables_1.EnvironmentVariables.CI_COMMITTER_NAME, commit?.author?.name);
}
else {
core.warning('Unable to get commit message for PR. Missing github-token input.');
}
}
function setVariable(name, value = '') {
core.exportVariable(name.toString(), value);
}
run();
155 changes: 153 additions & 2 deletions node_modules/@actions/core/README.md

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

12 changes: 8 additions & 4 deletions node_modules/@actions/core/lib/command.js

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

2 changes: 1 addition & 1 deletion node_modules/@actions/core/lib/command.js.map

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

8 changes: 6 additions & 2 deletions node_modules/@actions/core/lib/core.d.ts

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

Loading

0 comments on commit 5845643

Please sign in to comment.