Skip to content

Commit

Permalink
Merge branch 'release/1.1.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
nwtgck committed Aug 20, 2020
2 parents f757ba9 + b014bc2 commit 0798b5c
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 145 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)

## [Unreleased]

## [1.1.7] - 2020-08-20
### Added
* Add "'github-deployment-environment" input to specify environment name of GitHub Deployments

## [1.1.6] - 2020-08-17
### Changed
* Update dependencies
Expand Down Expand Up @@ -126,7 +130,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
* Deploy to Netlify
* Comment on GitHub PR

[Unreleased]: https://github.com/nwtgck/actions-netlify/compare/v1.1.6...HEAD
[Unreleased]: https://github.com/nwtgck/actions-netlify/compare/v1.1.7...HEAD
[1.1.7]: https://github.com/nwtgck/actions-netlify/compare/v1.1.6...v1.1.7
[1.1.6]: https://github.com/nwtgck/actions-netlify/compare/v1.1.5...v1.1.6
[1.1.5]: https://github.com/nwtgck/actions-netlify/compare/v1.1.4...v1.1.5
[1.1.4]: https://github.com/nwtgck/actions-netlify/compare/v1.1.3...v1.1.4
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:
- `alias` Specifies the prefix for the deployment URL (default: Netlify build ID)
- `alias: ${{ github.head_ref }}` replicates the [branch deploy prefix](https://docs.netlify.com/site-deploys/overview/#definitions)
- `alias: deploy-preview-${{ github.event.number }}` replicates the [deploy preview prefix](https://docs.netlify.com/site-deploys/overview/#definitions)
- `github-deployment-environment` Environment name of GitHub Deployments

### Paths are relative to the project's root
All paths (eg, `publish-dir`, `netlify-config-path`, `functions-dir`) are relative to the project's root or absolute paths.
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ inputs:
alias:
description: Specifies the prefix for the deployment URL
required: false
github-deployment-environment:
description: Environment name of GitHub Deployments
required: false
outputs:
deploy-url:
description: Deploy URL
Expand Down
140 changes: 69 additions & 71 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186207,6 +186207,7 @@ function createGitHubDeployment(githubClient, environmentUrl, environment) {
});
}
function run(inputs) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
const netlifyAuthToken = process.env.NETLIFY_AUTH_TOKEN;
Expand Down Expand Up @@ -186252,81 +186253,75 @@ function run(inputs) {
core.setOutput('deploy-url', deployUrl);
// Get GitHub token
const githubToken = inputs.githubToken();
if (githubToken !== '') {
const markdownComment = `${commentIdentifierString}\n${message}`;
// Create GitHub client
const githubClient = github_1.getOctokit(githubToken);
if (enableCommitComment) {
const commitCommentParams = {
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
// eslint-disable-next-line @typescript-eslint/camelcase
commit_sha: github_1.context.sha,
body: markdownComment
};
// TODO: Remove try
// NOTE: try-catch is experimentally used because commit message may not be done in some conditions.
try {
// Comment to the commit
yield githubClient.repos.createCommitComment(commitCommentParams);
}
catch (err) {
// eslint-disable-next-line no-console
console.error(err, JSON.stringify(commitCommentParams, null, 2));
}
}
if (github_1.context.issue.number === undefined) {
try {
const environment = productionDeploy ? 'production' : 'commit';
// Create GitHub Deployment
yield createGitHubDeployment(githubClient, deployUrl, environment);
}
catch (err) {
// eslint-disable-next-line no-console
console.error(err);
}
}
// If it is a pull request and enable comment on pull request
if (github_1.context.issue.number !== undefined) {
if (enablePullRequestComment) {
let commentId = undefined;
if (overwritesPullRequestComment) {
// Find issue comment
commentId = yield findIssueComment(githubClient);
}
// NOTE: if not overwrite, commentId is always undefined
if (commentId !== undefined) {
// Update comment of the deploy URL
yield githubClient.issues.updateComment({
owner: github_1.context.issue.owner,
repo: github_1.context.issue.repo,
// eslint-disable-next-line @typescript-eslint/camelcase
comment_id: commentId,
body: markdownComment
});
}
else {
// Comment the deploy URL
yield githubClient.issues.createComment({
// eslint-disable-next-line @typescript-eslint/camelcase
issue_number: github_1.context.issue.number,
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
body: markdownComment
});
}
}
try {
const environmentUrl = deploy.deploy.deploy_ssl_url;
// Create GitHub Deployment
yield createGitHubDeployment(githubClient, environmentUrl, 'pull request');
if (githubToken === '') {
return;
}
const markdownComment = `${commentIdentifierString}\n${message}`;
// Create GitHub client
const githubClient = github_1.getOctokit(githubToken);
if (enableCommitComment) {
const commitCommentParams = {
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
// eslint-disable-next-line @typescript-eslint/camelcase
commit_sha: github_1.context.sha,
body: markdownComment
};
// TODO: Remove try
// NOTE: try-catch is experimentally used because commit message may not be done in some conditions.
try {
// Comment to the commit
yield githubClient.repos.createCommitComment(commitCommentParams);
}
catch (err) {
// eslint-disable-next-line no-console
console.error(err, JSON.stringify(commitCommentParams, null, 2));
}
}
// If it is a pull request and enable comment on pull request
if (github_1.context.issue.number !== undefined) {
if (enablePullRequestComment) {
let commentId = undefined;
if (overwritesPullRequestComment) {
// Find issue comment
commentId = yield findIssueComment(githubClient);
}
// NOTE: if not overwrite, commentId is always undefined
if (commentId !== undefined) {
// Update comment of the deploy URL
yield githubClient.issues.updateComment({
owner: github_1.context.issue.owner,
repo: github_1.context.issue.repo,
// eslint-disable-next-line @typescript-eslint/camelcase
comment_id: commentId,
body: markdownComment
});
}
catch (err) {
// eslint-disable-next-line no-console
console.error(err);
else {
// Comment the deploy URL
yield githubClient.issues.createComment({
// eslint-disable-next-line @typescript-eslint/camelcase
issue_number: github_1.context.issue.number,
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
body: markdownComment
});
}
}
}
try {
const environment = (_a = inputs.githubDeploymentEnvironment()) !== null && _a !== void 0 ? _a : (productionDeploy
? 'production'
: github_1.context.issue.number !== undefined
? 'pull request'
: 'commit');
// Create GitHub Deployment
yield createGitHubDeployment(githubClient, deployUrl, environment);
}
catch (err) {
// eslint-disable-next-line no-console
console.error(err);
}
}
catch (error) {
core.setFailed(error.message);
Expand Down Expand Up @@ -261629,6 +261624,9 @@ exports.defaultInputs = {
},
alias() {
return core.getInput('alias') || undefined;
},
githubDeploymentEnvironment() {
return core.getInput('github-deployment-environment') || undefined;
}
};

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "actions-netlify",
"version": "1.1.6",
"version": "1.1.7",
"private": true,
"description": "GitHub Actions for Netlify",
"main": "lib/main.js",
Expand Down
4 changes: 4 additions & 0 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface Inputs {
overwritesPullRequestComment(): boolean
netlifyConfigPath(): string | undefined
alias(): string | undefined
githubDeploymentEnvironment(): string | undefined
}

export const defaultInputs: Inputs = {
Expand Down Expand Up @@ -54,5 +55,8 @@ export const defaultInputs: Inputs = {
},
alias() {
return core.getInput('alias') || undefined
},
githubDeploymentEnvironment(): string | undefined {
return core.getInput('github-deployment-environment') || undefined
}
}
134 changes: 63 additions & 71 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,87 +118,79 @@ export async function run(inputs: Inputs): Promise<void> {

// Get GitHub token
const githubToken = inputs.githubToken()
if (githubToken !== '') {
const markdownComment = `${commentIdentifierString}\n${message}`
if (githubToken === '') {
return
}
const markdownComment = `${commentIdentifierString}\n${message}`

// Create GitHub client
const githubClient = getOctokit(githubToken)
// Create GitHub client
const githubClient = getOctokit(githubToken)

if (enableCommitComment) {
const commitCommentParams = {
owner: context.repo.owner,
repo: context.repo.repo,
// eslint-disable-next-line @typescript-eslint/camelcase
commit_sha: context.sha,
body: markdownComment
}
// TODO: Remove try
// NOTE: try-catch is experimentally used because commit message may not be done in some conditions.
try {
// Comment to the commit
await githubClient.repos.createCommitComment(commitCommentParams)
} catch (err) {
// eslint-disable-next-line no-console
console.error(err, JSON.stringify(commitCommentParams, null, 2))
}
if (enableCommitComment) {
const commitCommentParams = {
owner: context.repo.owner,
repo: context.repo.repo,
// eslint-disable-next-line @typescript-eslint/camelcase
commit_sha: context.sha,
body: markdownComment
}

if (context.issue.number === undefined) {
try {
const environment = productionDeploy ? 'production' : 'commit'
// Create GitHub Deployment
await createGitHubDeployment(githubClient, deployUrl, environment)
} catch (err) {
// eslint-disable-next-line no-console
console.error(err)
}
// TODO: Remove try
// NOTE: try-catch is experimentally used because commit message may not be done in some conditions.
try {
// Comment to the commit
await githubClient.repos.createCommitComment(commitCommentParams)
} catch (err) {
// eslint-disable-next-line no-console
console.error(err, JSON.stringify(commitCommentParams, null, 2))
}
}

// If it is a pull request and enable comment on pull request
if (context.issue.number !== undefined) {
if (enablePullRequestComment) {
let commentId: number | undefined = undefined
if (overwritesPullRequestComment) {
// Find issue comment
commentId = await findIssueComment(githubClient)
}

// NOTE: if not overwrite, commentId is always undefined
if (commentId !== undefined) {
// Update comment of the deploy URL
await githubClient.issues.updateComment({
owner: context.issue.owner,
repo: context.issue.repo,
// eslint-disable-next-line @typescript-eslint/camelcase
comment_id: commentId,
body: markdownComment
})
} else {
// Comment the deploy URL
await githubClient.issues.createComment({
// eslint-disable-next-line @typescript-eslint/camelcase
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: markdownComment
})
}
// If it is a pull request and enable comment on pull request
if (context.issue.number !== undefined) {
if (enablePullRequestComment) {
let commentId: number | undefined = undefined
if (overwritesPullRequestComment) {
// Find issue comment
commentId = await findIssueComment(githubClient)
}

try {
const environmentUrl = deploy.deploy.deploy_ssl_url
// Create GitHub Deployment
await createGitHubDeployment(
githubClient,
environmentUrl,
'pull request'
)
} catch (err) {
// eslint-disable-next-line no-console
console.error(err)
// NOTE: if not overwrite, commentId is always undefined
if (commentId !== undefined) {
// Update comment of the deploy URL
await githubClient.issues.updateComment({
owner: context.issue.owner,
repo: context.issue.repo,
// eslint-disable-next-line @typescript-eslint/camelcase
comment_id: commentId,
body: markdownComment
})
} else {
// Comment the deploy URL
await githubClient.issues.createComment({
// eslint-disable-next-line @typescript-eslint/camelcase
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: markdownComment
})
}
}
}

try {
const environment =
inputs.githubDeploymentEnvironment() ??
(productionDeploy
? 'production'
: context.issue.number !== undefined
? 'pull request'
: 'commit')
// Create GitHub Deployment
await createGitHubDeployment(githubClient, deployUrl, environment)
} catch (err) {
// eslint-disable-next-line no-console
console.error(err)
}
} catch (error) {
core.setFailed(error.message)
}
Expand Down

4 comments on commit 0798b5c

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.