Skip to content
This repository was archived by the owner on Oct 28, 2022. It is now read-only.

[DRAFT] Various changes #25

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
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: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
},
"rules": {
"camelcase": "off",
"import/no-namespace": "off"
"import/no-namespace": "off",
"i18n-text/no-en": "off",
"import/no-unresolved": "off"
},
"env": {
"node": true,
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Dependency directory
node_modules
website

# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs
Expand Down Expand Up @@ -96,6 +97,5 @@ Thumbs.db

# Ignore built ts files
__tests__/runner/*
lib

/dist/typescript*
30 changes: 15 additions & 15 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Netlify Deploy Action
description: Netlify deployments via GitHub actions
author: Alex Gabites <https://github.com/South-Paw>
name: Netlify Advanced Deploy Action
description: Netlify Deploy Attempt with PR comments
author: Hebilicious - Forked <https://github.com/South-Paw>
branding:
color: purple
icon: package
runs:
using: "node12"
main: "dist/index.js"
using: 'node16'
main: 'lib/index.js'
inputs:
# Required inputs
github-token:
Expand All @@ -25,11 +25,11 @@ inputs:
comment-on-commit:
description: If `true` AND the context of the action is a `commit` then the action will comment on the SHA.
required: false
default: "false"
default: 'false'
comment-on-pull-request:
description: If `true` AND the context of the action is a `pull_request` then the action will comment on the PR.
required: false
default: "false"
default: 'false'
github-deployment-environment:
description: The name of the GitHub environment to deploy to.
required: false
Expand All @@ -39,19 +39,19 @@ inputs:
github-deployment-is-transient:
description: Specifies if the given environment is specific to the deployment and will no longer exist at some point in the future.
required: false
default: "false"
default: 'false'
github-deployment-is-production:
description: Specifies if the given environment is one that end-users directly interact with.
required: false
default: "true"
default: 'true'
github-deployment-should-report-status:
description: If `true` AND `github-env` is set then the action will report the status of environment deployments on pull requests.
required: false
default: "true"
default: 'true'
dry-run:
description: Run the action but don't actually deploy to Netlify or comment on the commit/PR
required: false
default: "false"
default: 'false'
# Other optional inputs (see: https://github.com/netlify/js-client#deploy--await-clientdeploysiteid-builddir-opts)
functions-dir:
description: The folder of any functions to deploy
Expand All @@ -62,12 +62,12 @@ inputs:
draft:
description: If it is a draft deploy or production deploy
required: false
default: "false"
default: 'false'
message:
description: "A short message to associate with the deploy (Note: setting this will override the default deploy message of `<type>: <title> [short_sha]`)"
description: 'A short message to associate with the deploy (Note: setting this will override the default deploy message of `<type>: <title> [short_sha]`)'
required: false
outputs:
preview-url:
description: "deployment preview URL"
description: 'deployment preview URL'
preview-name:
description: "deployment preview name"
description: 'deployment preview name'
Binary file removed dist/elf_cam_bg.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

424,892 changes: 213 additions & 424,679 deletions dist/index.js

Large diffs are not rendered by default.

209 changes: 209 additions & 0 deletions dist/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
// src/index.ts
import * as core from "@actions/core";
import * as github from "@actions/github";
import * as exec from "@actions/exec";
import * as path from "path";

// src/util.ts
var getDeployUrl = (isDraft, deploy) => isDraft ? deploy.deploy_ssl_url : deploy.ssl_url;
var createCommentMessage = (isDraft, deploy) => isDraft ? `\u{1F680} [DRAFT] Netlify deployed **${deploy == null ? void 0 : deploy.site_name}** :

${deploy == null ? void 0 : deploy.deploy_url}` : `\u{1F389} [PROD] Netlify deployed **${deploy == null ? void 0 : deploy.site_name}** :

${deploy == null ? void 0 : deploy.deploy_url}`;

// src/index.ts
async function run() {
var _a, _b, _c, _d, _e, _f;
try {
const isCommit = Object.keys(github.context.payload).includes("head_commit");
const isPullRequest = Object.keys(github.context.payload).includes("pull_request");
const isRelease = Object.keys(github.context.payload).includes("release");
const {
payload,
sha,
issue: { number },
repo: { owner, repo }
} = github.context;
const shaShort = sha.slice(0, 7);
const deploymentSha = ((_a = payload.pull_request) == null ? void 0 : _a.head.sha) ?? sha;
const commitMessage = isCommit ? (_b = payload.head_commit) == null ? void 0 : _b.message : void 0;
const pullRequestNumber = (_c = payload.pull_request) == null ? void 0 : _c.number;
const pullRequestTitle = isPullRequest ? (_d = payload.pull_request) == null ? void 0 : _d.title : void 0;
const releaseTag = isRelease ? (_e = payload.release) == null ? void 0 : _e.tag_name : void 0;
const releaseTitle = isRelease ? (_f = payload.release) == null ? void 0 : _f.name : void 0;
const githubToken = core.getInput("github-token", { required: true });
const netlifyAuthToken = core.getInput("netlify-auth-token", { required: true });
const siteId = core.getInput("netlify-site-id", { required: true });
const buildDir = core.getInput("build-dir", { required: true });
const commentOnCommit = core.getInput("comment-on-commit") === "true";
const commentOnPullRequest = core.getInput("comment-on-pull-request") === "true";
const githubDeployEnvironment = core.getInput("github-deployment-environment") || void 0;
const githubDeployDescription = core.getInput("github-deployment-description") || void 0;
const githubDeployIsTransient = core.getInput("github-deployment-is-transient") === "true";
const githubDeployIsProduction = core.getInput("github-deployment-is-production") === "true";
const githubDeployReportStatus = core.getInput("github-deployment-should-report-status") === "true";
const dryRun = core.getInput("dry-run") === "true";
const draft = core.getInput("draft") === "true";
const functionsDir = core.getInput("functions-dir") || void 0;
let message = core.getInput("message");
const octokit = github.getOctokit(githubToken);
if (!message) {
message = `Build [${shaShort}]`;
if (isCommit) {
message = `Commit: ${commitMessage} [${shaShort}]`;
}
if (isPullRequest) {
message = `PR: ${pullRequestTitle} [${shaShort}]`;
}
if (isRelease) {
message = `Release: ${releaseTitle} [${releaseTag}]`;
}
}
if (dryRun) {
process.stdout.write(`Action is running dry - there won't be any outputs from this run.
`);
}
process.stdout.write(`Deploying ${draft ? "draft " : ""}to Netlify...
`);
let deploy;
if (!dryRun) {
try {
const siteDir = path.resolve(process.cwd(), buildDir);
const fnDir = functionsDir ? path.resolve(process.cwd(), functionsDir) : void 0;
const functions = fnDir ? `--functions ${fnDir}` : "";
const production = draft ? "" : "--prod";
const auth = `--auth ${netlifyAuthToken}`;
const result = await exec.getExecOutput(`netlify deploy --site ${siteId} ${auth} --dir ${siteDir} ${production} ${functions} --message "${message}" --json`);
deploy = JSON.parse(result.stdout);
console.dir(deploy, { depth: null });
core.setOutput("preview-name", deploy == null ? void 0 : deploy.site_name);
core.setOutput("preview-url", deploy == null ? void 0 : deploy.deploy_url);
} catch (error) {
process.stderr.write("netlify deploy command failed\n ...");
process.stderr.write(`${JSON.stringify(error, null, 2)}
`);
core.setFailed(error.message);
}
if (!deploy) {
core.setFailed("Failed to deploy to Netlify!");
return;
}
} else {
process.stdout.write(`[Dry run] Netlify deploy message: "${message}"
`);
}
const body = dryRun ? createCommentMessage(draft, {
name: "dry-run",
deploy_ssl_url: "http://example.com",
ssl_url: "http://example.com"
}) : createCommentMessage(draft, deploy);
if (isCommit && commentOnCommit) {
process.stdout.write(`Commenting on commit ${shaShort} (SHA: ${sha})
`);
if (!dryRun) {
try {
await octokit.rest.repos.createCommitComment({
owner,
repo,
commit_sha: sha,
body
});
} catch (error) {
process.stderr.write("creating commit comment failed\n");
process.stderr.write(`${JSON.stringify(error, null, 2)}
`);
core.setFailed(error.message);
}
} else {
process.stdout.write(`[Dry run] GitHub commit comment: "${body}"
`);
}
}
if (commentOnPullRequest) {
process.stdout.write(`Commenting on pull request #${pullRequestNumber}
`);
if (!dryRun) {
try {
await octokit.rest.issues.createComment({
owner,
repo,
issue_number: number,
body
});
} catch (error) {
process.stderr.write("creating pull request comment failed\n");
process.stderr.write(`${JSON.stringify(error, null, 2)}
`);
core.setFailed(error.message);
}
} else {
process.stdout.write(`[Dry run] GitHub pull request comment: "${body}"
`);
}
}
if (githubDeployEnvironment) {
if (!dryRun) {
process.stdout.write(`Creating deployment for "${githubDeployEnvironment}"
`);
try {
const deployment = await octokit.rest.repos.createDeployment({
owner,
repo,
ref: deploymentSha,
auto_merge: false,
required_contexts: [],
environment: githubDeployEnvironment,
description: githubDeployDescription,
transient_environment: githubDeployIsTransient,
production_environment: githubDeployIsProduction
});
await octokit.rest.repos.createDeploymentStatus({
owner,
repo,
deployment_id: deployment.data.id,
state: "success",
environment_url: getDeployUrl(draft, deploy)
});
} catch (error) {
process.stderr.write("creating deployment failed\n");
process.stderr.write(`${JSON.stringify(error, null, 2)}
`);
core.setFailed(error.message);
}
} else {
process.stdout.write(`[Dry run] GitHub deployment env: "${githubDeployEnvironment}"
`);
}
if (!dryRun) {
if (githubDeployReportStatus) {
process.stdout.write(`Creating commit status for SHA: "${deploymentSha}"
`);
try {
await octokit.rest.repos.createCommitStatus({
sha: deploymentSha,
owner,
repo,
state: "success",
context: "action-netlify-deploy",
target_url: getDeployUrl(draft, deploy),
description: "action-netlify-deploy status"
});
} catch (error) {
process.stderr.write("creating commit status failed\n");
process.stderr.write(`${JSON.stringify(error, null, 2)}
`);
core.setFailed(error.message);
}
}
} else {
process.stdout.write(`[Dry run] GitHub commit status "success" on "${deploymentSha}"
`);
}
}
} catch (error) {
process.stderr.write(JSON.stringify(error, null, 2));
core.setFailed(error.message);
}
}
run();
57 changes: 0 additions & 57 deletions dist/thread.js

This file was deleted.

Loading