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

Commit 07ce847

Browse files
authored
Rename and add additional GitHub deployment inputs (#20)
1 parent 87160d5 commit 07ce847

File tree

6 files changed

+118
-109
lines changed

6 files changed

+118
-109
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
# e.g. `npm run build` for create-react-app
5555

5656
- name: Deploy draft to Netlify
57-
uses: South-Paw/action-netlify-deploy@v1.0.4
57+
uses: South-Paw/action-netlify-deploy@v1.2.0
5858
with:
5959
github-token: ${{ secrets.GITHUB_TOKEN }}
6060
netlify-auth-token: ${{ secrets.NETLIFY_AUTH_TOKEN }}
@@ -78,7 +78,7 @@ jobs:
7878
# e.g. `npm run build` for create-react-app
7979

8080
- name: Deploy production to Netlify
81-
uses: South-Paw/action-netlify-deploy@v1.0.4
81+
uses: South-Paw/action-netlify-deploy@v1.2.0
8282
with:
8383
github-token: ${{ secrets.GITHUB_TOKEN }}
8484
netlify-auth-token: ${{ secrets.NETLIFY_AUTH_TOKEN }}
@@ -115,7 +115,7 @@ jobs:
115115
# e.g. `npm run build` for create-react-app
116116

117117
- name: Deploy draft to Netlify
118-
uses: South-Paw/action-netlify-deploy@v1.0.4
118+
uses: South-Paw/action-netlify-deploy@v1.2.0
119119
with:
120120
github-token: ${{ secrets.GITHUB_TOKEN }}
121121
netlify-auth-token: ${{ secrets.NETLIFY_AUTH_TOKEN }}
@@ -139,7 +139,7 @@ jobs:
139139
# e.g. `npm run build` for create-react-app
140140

141141
- name: Deploy production to Netlify
142-
uses: South-Paw/action-netlify-deploy@v1.0.4
142+
uses: South-Paw/action-netlify-deploy@v1.2.0
143143
with:
144144
github-token: ${{ secrets.GITHUB_TOKEN }}
145145
netlify-auth-token: ${{ secrets.NETLIFY_AUTH_TOKEN }}
@@ -178,7 +178,7 @@ jobs:
178178
# e.g. `npm run build` for create-react-app
179179

180180
- name: Deploy draft to Netlify
181-
uses: South-Paw/action-netlify-deploy@v1.0.4
181+
uses: South-Paw/action-netlify-deploy@v1.2.0
182182
with:
183183
github-token: ${{ secrets.GITHUB_TOKEN }}
184184
netlify-auth-token: ${{ secrets.NETLIFY_AUTH_TOKEN }}
@@ -202,7 +202,7 @@ jobs:
202202
# e.g. `npm run build` for create-react-app
203203

204204
- name: Deploy production to Netlify
205-
uses: South-Paw/action-netlify-deploy@v1.0.4
205+
uses: South-Paw/action-netlify-deploy@v1.2.0
206206
with:
207207
github-token: ${{ secrets.GITHUB_TOKEN }}
208208
netlify-auth-token: ${{ secrets.NETLIFY_AUTH_TOKEN }}

action.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,22 @@ inputs:
3030
description: If `true` AND the context of the action is a `pull_request` then the action will comment on the PR.
3131
required: false
3232
default: "false"
33-
github-env:
33+
github-deployment-environment:
3434
description: The name of the GitHub environment to deploy to.
3535
required: false
36-
github-env-report-status:
37-
description: If `true` AND `github-env` is set then the action will report the status of environment deployments to PRs and commits.
36+
github-deployment-description:
37+
description: Optional description to add to the deployment.
38+
required: false
39+
github-deployment-is-transient:
40+
description: Specifies if the given environment is specific to the deployment and will no longer exist at some point in the future.
41+
required: false
42+
default: "false"
43+
github-deployment-is-production:
44+
description: Specifies if the given environment is one that end-users directly interact with.
45+
required: false
46+
default: "true"
47+
github-deployment-should-report-status:
48+
description: If `true` AND `github-env` is set then the action will report the status of environment deployments on pull requests.
3849
required: false
3950
default: "true"
4051
dry-run:

dist/index.js

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,21 @@ const github = __importStar(__webpack_require__(95438));
5252
const netlify_1 = __importDefault(__webpack_require__(44666));
5353
const path = __importStar(__webpack_require__(85622));
5454
const util_1 = __webpack_require__(64024);
55-
const dryRunDeploy = {
56-
name: 'dry-run',
57-
deploy_ssl_url: 'http://example.com',
58-
ssl_url: 'http://example.com',
59-
};
6055
function run() {
61-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
56+
var _a, _b, _c, _d, _e, _f, _g;
6257
return __awaiter(this, void 0, void 0, function* () {
6358
try {
6459
const isCommit = Object.keys(github.context.payload).includes('head_commit');
6560
const isPullRequest = Object.keys(github.context.payload).includes('pull_request');
6661
const isRelease = Object.keys(github.context.payload).includes('release');
67-
const commitSha = github.context.sha;
68-
const commitShaShort = github.context.sha.slice(0, 7);
69-
const commitMessage = isCommit ? (_b = (_a = github.context.payload) === null || _a === void 0 ? void 0 : _a.head_commit) === null || _b === void 0 ? void 0 : _b.message : undefined;
70-
const pullRequestNumber = (_c = github.context.payload.pull_request) === null || _c === void 0 ? void 0 : _c.number;
71-
const pullRequestTitle = isPullRequest ? (_e = (_d = github.context.payload) === null || _d === void 0 ? void 0 : _d.pull_request) === null || _e === void 0 ? void 0 : _e.title : undefined;
72-
const releaseTag = isRelease ? (_g = (_f = github.context.payload) === null || _f === void 0 ? void 0 : _f.release) === null || _g === void 0 ? void 0 : _g.tag_name : undefined;
73-
const releaseTitle = isRelease ? (_j = (_h = github.context.payload) === null || _h === void 0 ? void 0 : _h.release) === null || _j === void 0 ? void 0 : _j.name : undefined;
62+
const { payload, sha, issue: { number }, repo: { owner, repo }, } = github.context;
63+
const shaShort = sha.slice(0, 7);
64+
const deploymentSha = (_b = (_a = payload.pull_request) === null || _a === void 0 ? void 0 : _a.head.sha) !== null && _b !== void 0 ? _b : sha;
65+
const commitMessage = isCommit ? (_c = payload.head_commit) === null || _c === void 0 ? void 0 : _c.message : undefined;
66+
const pullRequestNumber = (_d = payload.pull_request) === null || _d === void 0 ? void 0 : _d.number;
67+
const pullRequestTitle = isPullRequest ? (_e = payload.pull_request) === null || _e === void 0 ? void 0 : _e.title : undefined;
68+
const releaseTag = isRelease ? (_f = payload.release) === null || _f === void 0 ? void 0 : _f.tag_name : undefined;
69+
const releaseTitle = isRelease ? (_g = payload.release) === null || _g === void 0 ? void 0 : _g.name : undefined;
7470
// Get required inputs
7571
const githubToken = core.getInput('github-token', { required: true });
7672
const netlifyAuthToken = core.getInput('netlify-auth-token', { required: true });
@@ -79,22 +75,28 @@ function run() {
7975
// Get config inputs
8076
const commentOnCommit = core.getInput('comment-on-commit') === 'true';
8177
const commentOnPullRequest = core.getInput('comment-on-pull-request') === 'true';
82-
const githubEnv = core.getInput('github-env') || undefined;
83-
const githubEnvReportStatus = core.getInput('github-env-report-status') === 'true';
78+
const githubDeployEnvironment = core.getInput('github-deployment-environment') || undefined;
79+
const githubDeployDescription = core.getInput('github-deployment-description') || undefined;
80+
const githubDeployIsTransient = core.getInput('github-deployment-is-transient') === 'true';
81+
const githubDeployIsProduction = core.getInput('github-deployment-is-production') === 'true';
82+
const githubDeployReportStatus = core.getInput('github-deployment-should-report-status') === 'true';
8483
const dryRun = core.getInput('dry-run') === 'true';
8584
// Get optional inputs
8685
const configPath = core.getInput('config-path') || undefined;
8786
const draft = core.getInput('draft') === 'true';
8887
const functionsDir = core.getInput('functions-dir') || undefined;
8988
let message = core.getInput('message');
89+
// Create clients
90+
const githubClient = github.getOctokit(githubToken);
91+
const netlifyClient = new netlify_1.default(netlifyAuthToken);
9092
// If there's no explict deploy message input, then make a deploy message from the action's context.
9193
if (!message) {
92-
message = `Build [${commitShaShort}]`;
94+
message = `Build [${shaShort}]`;
9395
if (isCommit) {
94-
message = `Commit: ${commitMessage} [${commitShaShort}]`;
96+
message = `Commit: ${commitMessage} [${shaShort}]`;
9597
}
9698
if (isPullRequest) {
97-
message = `PR: ${pullRequestTitle} [${commitShaShort}]`;
99+
message = `PR: ${pullRequestTitle} [${shaShort}]`;
98100
}
99101
if (isRelease) {
100102
message = `Release: ${releaseTitle} [${releaseTag}]`;
@@ -104,7 +106,6 @@ function run() {
104106
process.stdout.write(`Action is running dry - there won't be any outputs from this run.\n`);
105107
}
106108
process.stdout.write(`Deploying ${draft ? 'draft ' : ''}to Netlify...\n`);
107-
const netlifyClient = new netlify_1.default(netlifyAuthToken);
108109
let deploy;
109110
if (!dryRun) {
110111
try {
@@ -126,11 +127,15 @@ function run() {
126127
else {
127128
process.stdout.write(`[Dry run] Netlify deploy message: "${message}"\n`);
128129
}
129-
const githubClient = github.getOctokit(githubToken);
130-
const body = util_1.createCommentMessage(draft, dryRun ? dryRunDeploy : deploy);
130+
const body = dryRun
131+
? util_1.createCommentMessage(draft, {
132+
name: 'dry-run',
133+
deploy_ssl_url: 'http://example.com',
134+
ssl_url: 'http://example.com',
135+
})
136+
: util_1.createCommentMessage(draft, deploy);
131137
if (isCommit && commentOnCommit) {
132-
process.stdout.write(`Commenting on commit ${commitShaShort} (SHA: ${commitSha})\n`);
133-
const { repo: { owner, repo }, sha, } = github.context;
138+
process.stdout.write(`Commenting on commit ${shaShort} (SHA: ${sha})\n`);
134139
if (!dryRun) {
135140
try {
136141
yield githubClient.repos.createCommitComment({
@@ -147,12 +152,11 @@ function run() {
147152
}
148153
}
149154
else {
150-
process.stdout.write(`[Dry run] Github commit comment: "${body}"\n`);
155+
process.stdout.write(`[Dry run] GitHub commit comment: "${body}"\n`);
151156
}
152157
}
153158
if (isPullRequest && commentOnPullRequest) {
154159
process.stdout.write(`Commenting on pull request #${pullRequestNumber}\n`);
155-
const { repo: { owner, repo }, issue: { number }, } = github.context;
156160
if (!dryRun) {
157161
try {
158162
yield githubClient.issues.createComment({
@@ -169,28 +173,29 @@ function run() {
169173
}
170174
}
171175
else {
172-
process.stdout.write(`[Dry run] Github pull request comment: "${body}"\n`);
176+
process.stdout.write(`[Dry run] GitHub pull request comment: "${body}"\n`);
173177
}
174178
}
175-
const envSha = (_l = (_k = github.context.payload.pull_request) === null || _k === void 0 ? void 0 : _k.head.sha) !== null && _l !== void 0 ? _l : commitSha;
176-
if (githubEnv) {
179+
if (githubDeployEnvironment) {
177180
if (!dryRun) {
178-
process.stdout.write(`Creating deployment for "${githubEnv}"\n`);
179-
const { repo: { owner, repo }, } = github.context;
181+
process.stdout.write(`Creating deployment for "${githubDeployEnvironment}"\n`);
180182
try {
181183
const deployment = yield githubClient.repos.createDeployment({
182-
ref: envSha,
183184
owner,
184185
repo,
185-
environment: githubEnv,
186+
ref: deploymentSha,
186187
auto_merge: false,
187188
required_contexts: [],
189+
environment: githubDeployEnvironment,
190+
description: githubDeployDescription,
191+
transient_environment: githubDeployIsTransient,
192+
production_environment: githubDeployIsProduction,
188193
});
189194
yield githubClient.repos.createDeploymentStatus({
190195
owner,
191196
repo,
192-
state: 'success',
193197
deployment_id: deployment.data.id,
198+
state: 'success',
194199
environment_url: util_1.getDeployUrl(draft, deploy),
195200
});
196201
}
@@ -201,32 +206,31 @@ function run() {
201206
}
202207
}
203208
else {
204-
process.stdout.write(`[Dry run] Github deployment env: "${githubEnv}"\n`);
209+
process.stdout.write(`[Dry run] GitHub deployment env: "${githubDeployEnvironment}"\n`);
205210
}
206211
if (!dryRun) {
207-
if (githubEnvReportStatus) {
208-
process.stdout.write(`Creating commit status for SHA: "${envSha}"\n`);
209-
const { repo: { owner, repo }, } = github.context;
212+
if (githubDeployReportStatus) {
213+
process.stdout.write(`Creating commit status for SHA: "${deploymentSha}"\n`);
210214
try {
211215
yield githubClient.repos.createCommitStatus({
212-
sha: envSha,
216+
sha: deploymentSha,
213217
owner,
214218
repo,
215219
state: 'success',
216220
context: 'action-netlify-deploy',
217221
target_url: util_1.getDeployUrl(draft, deploy),
218-
description: 'Netlify deployment status',
222+
description: 'action-netlify-deploy status',
219223
});
220224
}
221225
catch (error) {
222-
process.stderr.write('creating deployment failed\n');
226+
process.stderr.write('creating commit status failed\n');
223227
process.stderr.write(`${JSON.stringify(error, null, 2)}\n`);
224228
core.setFailed(error.message);
225229
}
226230
}
227231
}
228232
else {
229-
process.stdout.write(`[Dry run] Github status on commit: "${envSha}"\n`);
233+
process.stdout.write(`[Dry run] GitHub commit status "success" on "${deploymentSha}"\n`);
230234
}
231235
}
232236
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@south-paw/action-netlify-deploy",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "Netlify deployments via GitHub actions",
55
"keywords": [],
66
"homepage": "https://github.com/South-Paw/action-netlify-deploy",

0 commit comments

Comments
 (0)