Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
nwtgck committed May 10, 2020
2 parents ac1207f + 27df0f7 commit c6e2a32
Show file tree
Hide file tree
Showing 9 changed files with 359 additions and 41 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)

## [Unreleased]

## [1.1.0] - 2020-05-10
## Added
* Add "overwrites-pull-request-comment" input

### Changed
* Overwrite comment on pull request by default
- You can use `overwrites-pull-request-comment: false` not to overwrite
* Update dependencies

## [1.0.13] - 2020-05-09
### Changed
* Update dependencies
Expand Down Expand Up @@ -86,7 +95,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.0.13...HEAD
[Unreleased]: https://github.com/nwtgck/actions-netlify/compare/v1.1.0...HEAD
[1.1.0]: https://github.com/nwtgck/actions-netlify/compare/v1.0.13...v1.1.0
[1.0.13]: https://github.com/nwtgck/actions-netlify/compare/v1.0.12...v1.0.13
[1.0.12]: https://github.com/nwtgck/actions-netlify/compare/v1.0.11...v1.0.12
[1.0.11]: https://github.com/nwtgck/actions-netlify/compare/v1.0.10...v1.0.11
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ jobs:
# ...

- name: Deploy to Netlify
uses: nwtgck/actions-netlify@v1.0
uses: nwtgck/actions-netlify@v1.1
with:
publish-dir: './dist'
production-branch: master
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: "Deploy from GitHub Actions"
enable-pull-request-comment: true
enable-commit-comment: true
overwrites-pull-request-comment: true
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
Expand All @@ -49,7 +52,8 @@ jobs:
- `github-token: ${{ secrets.GITHUB_TOKEN }}`
- `deploy-message` A custom deploy message to see on Netlify deployment (e.g. `${{ github.event.pull_request.title }}`)
- `enable-pull-request-comment: true` Comment on pull request (default: true)
- `enable-commit-comment: true` Comment on GitHub commit (default)
- `enable-commit-comment: true` Comment on GitHub commit (default: true)
- `overwrites-pull-request-comment: true` Overwirtes comment on pull request (default: true)

### Outputs
- `deploy-url` A deployment URL generated by Netlify
Expand Down
138 changes: 138 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,144 @@ import {wait} from '../src/wait'
import * as process from 'process'
import * as cp from 'child_process'
import * as path from 'path'
import {defaultInputs} from '../src/inputs'

/**
* With input
* @param inputName
* @param value
* @param f
*/
export async function withInput(
inputName: string,
value: string,
f: () => void | Promise<void>
): Promise<void> {
// (from: https://github.com/actions/toolkit/blob/83dd3ef0f1e5bc93c5ab7072e1edf1715a01ba9d/packages/core/src/core.ts#L71)
const envName = `INPUT_${inputName.replace(/ /g, '_').toUpperCase()}`
process.env[envName] = value
await f()
// NOTE: Not sure this is correct deletion
delete process.env[envName]
}

describe('defaultInputs', () => {
test('publishDir', () => {
withInput('publish-dir', './my_publish_dir', () => {
const publishDir: string = defaultInputs.publishDir()
expect(publishDir).toBe('./my_publish_dir')
})
})

describe('deployMessage', () => {
test('it should be a string when specified', () => {
withInput('deploy-message', 'Deploy with GitHub Actions', () => {
const deployMessage: string | undefined = defaultInputs.deployMessage()
expect(deployMessage).toBe('Deploy with GitHub Actions')
})
})

test('it should be undefined when not specified', () => {
const deployMessage: string | undefined = defaultInputs.deployMessage()
expect(deployMessage).toBe(undefined)
})
})

describe('productionBranch', () => {
test('it should be a string when specified', () => {
withInput('production-branch', 'master', () => {
const productionBranch:
| string
| undefined = defaultInputs.productionBranch()
expect(productionBranch).toBe('master')
})
})

test('it should be undefined when not specified', () => {
const deployMessage: string | undefined = defaultInputs.productionBranch()
expect(deployMessage).toBe(undefined)
})
})

describe('enablePullRequestComment', () => {
test('it should be default value (true) when not specified', () => {
const b: boolean = defaultInputs.enablePullRequestComment()
expect(b).toBe(true)
})

test('it should be true when "true" specified', () => {
withInput('enable-pull-request-comment', 'true', () => {
const b: boolean = defaultInputs.enablePullRequestComment()
expect(b).toBe(true)
})
})

test('it should be true when "false" specified', () => {
withInput('enable-pull-request-comment', 'false', () => {
const b: boolean = defaultInputs.enablePullRequestComment()
expect(b).toBe(false)
})
})
})

describe('enableCommitComment', () => {
test('it should be default value (true) when not specified', () => {
const b: boolean = defaultInputs.enableCommitComment()
expect(b).toBe(true)
})

test('it should be true when "true" specified', () => {
withInput('enable-commit-comment', 'true', () => {
const b: boolean = defaultInputs.enableCommitComment()
expect(b).toBe(true)
})
})

test('it should be true when "false" specified', () => {
withInput('enable-commit-comment', 'false', () => {
const b: boolean = defaultInputs.enableCommitComment()
expect(b).toBe(false)
})
})
})

describe('enableCommitComment', () => {
test('it should be empty string when not specified', () => {
const t: string = defaultInputs.githubToken()
expect(t).toBe('')
})

test('it should be a string when specified', () => {
withInput('github-token', 'DUMMY_GITHUB_TOKEN', () => {
const t: string = defaultInputs.githubToken()
expect(t).toBe('DUMMY_GITHUB_TOKEN')
})
})
})

describe('overwritesPullRequestComment', () => {
test('it should be default value (true) when not specified', () => {
const b: boolean = defaultInputs.overwritesPullRequestComment()
expect(b).toBe(true)
})

test('it should be true when "true" specified', () => {
withInput('overwrites-pull-request-comment', 'true', () => {
const b: boolean = defaultInputs.overwritesPullRequestComment()
expect(b).toBe(true)
})
})

test('it should be true when "false" specified', () => {
withInput('overwrites-pull-request-comment', 'false', () => {
const b: boolean = defaultInputs.overwritesPullRequestComment()
expect(b).toBe(false)
})
})
})
})

// Old tests below

test('throws invalid number', async () => {
const input = parseInt('foo', 10)
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ inputs:
enable-commit-comment:
description: Enable commit comment
required: false
overwrites-pull-request-comment:
description: Overwrites pull request comment
required: false
outputs:
deploy-url:
description: Deploy URL
Expand Down
111 changes: 95 additions & 16 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41876,7 +41876,27 @@ const core = __importStar(__webpack_require__(470));
const github_1 = __webpack_require__(469);
const netlify_1 = __importDefault(__webpack_require__(326));
const path = __importStar(__webpack_require__(622));
function run() {
const inputs_1 = __webpack_require__(840);
const commentIdentifierString = '<!-- NETLIFY DEPLOY COMMENT GENERATED BY ACTIONS_NETLIFY -->';
function findIssueComment(githubClient) {
return __awaiter(this, void 0, void 0, function* () {
const listCommentsRes = yield githubClient.issues.listComments({
owner: github_1.context.issue.owner,
repo: github_1.context.issue.repo,
// eslint-disable-next-line @typescript-eslint/camelcase
issue_number: github_1.context.issue.number
});
const comments = listCommentsRes.data;
for (const comment of comments) {
// If comment contains the comment identifier
if (comment.body.includes(commentIdentifierString)) {
return comment.id;
}
}
return undefined;
});
}
function run(inputs) {
return __awaiter(this, void 0, void 0, function* () {
try {
const netlifyAuthToken = process.env.NETLIFY_AUTH_TOKEN;
Expand All @@ -41886,15 +41906,14 @@ function run() {
process.stdout.write('Netlify credentials not provided, not deployable');
return;
}
const dir = core.getInput('publish-dir', { required: true });
const deployMessage = core.getInput('deploy-message') || undefined;
const productionBranch = core.getInput('production-branch');
// Default: true
const enablePullRequestComment = (core.getInput('enable-pull-request-comment') || 'true') === 'true';
// Default: true
const enableCommitComment = (core.getInput('enable-commit-comment') || 'true') === 'true';
// NOTE: if production-branch is not specified, it is "", so isDraft is always true
const isDraft = github_1.context.ref !== `refs/heads/${productionBranch}`;
const dir = inputs.publishDir();
const deployMessage = inputs.deployMessage();
const productionBranch = inputs.productionBranch();
const enablePullRequestComment = inputs.enablePullRequestComment();
const enableCommitComment = inputs.enableCommitComment();
const overwritesPullRequestComment = inputs.overwritesPullRequestComment();
const isDraft = productionBranch === undefined ||
github_1.context.ref !== `refs/heads/${productionBranch}`;
// Create Netlify API client
const netlifyClient = new netlify_1.default(netlifyAuthToken);
// Resolve publish directory
Expand All @@ -41913,8 +41932,9 @@ function run() {
// Set the deploy URL to outputs for GitHub Actions
core.setOutput('deploy-url', isDraft ? deploy.deploy.deploy_ssl_url : deploy.deploy.ssl_url);
// Get GitHub token
const githubToken = core.getInput('github-token');
const githubToken = inputs.githubToken();
if (githubToken !== '') {
const markdownComment = `${commentIdentifierString}\n${message}`;
// Create GitHub client
const githubClient = new github_1.GitHub(githubToken);
if (enableCommitComment) {
Expand All @@ -41923,7 +41943,7 @@ function run() {
repo: github_1.context.repo.repo,
// eslint-disable-next-line @typescript-eslint/camelcase
commit_sha: github_1.context.sha,
body: message
body: markdownComment
};
// TODO: Remove try
// NOTE: try-catch is experimentally used because commit message may not be done in some conditions.
Expand All @@ -41938,13 +41958,30 @@ function run() {
}
// If it is a pull request and enable comment on pull request
if (github_1.context.issue.number !== undefined && 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
});
return;
}
// 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: message
body: markdownComment
});
}
}
Expand All @@ -41954,7 +41991,7 @@ function run() {
}
});
}
run();
run(inputs_1.defaultInputs);


/***/ }),
Expand Down Expand Up @@ -75483,7 +75520,7 @@ module.exports = setup;
/* 487 */
/***/ (function(module) {

module.exports = {"_from":"@typescript-eslint/[email protected]","_id":"@typescript-eslint/[email protected]","_inBundle":false,"_integrity":"sha512-vxW149bXFXXuBrAak0eKHOzbcu9cvi6iNcJDzEtOkRwGHxJG15chiAQAwhLOsk+86p9GTr/TziYvw+H9kMaIgA==","_location":"/@typescript-eslint/typescript-estree","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"@typescript-eslint/[email protected]","name":"@typescript-eslint/typescript-estree","escapedName":"@typescript-eslint%2ftypescript-estree","scope":"@typescript-eslint","rawSpec":"2.31.0","saveSpec":null,"fetchSpec":"2.31.0"},"_requiredBy":["/@typescript-eslint/experimental-utils","/@typescript-eslint/parser","/detective-typescript"],"_resolved":"https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.31.0.tgz","_shasum":"ac536c2d46672aa1f27ba0ec2140d53670635cfd","_spec":"@typescript-eslint/[email protected]","_where":"/Users/ryo/dev/actions/actions-netlify/node_modules/@typescript-eslint/parser","bugs":{"url":"https://github.com/typescript-eslint/typescript-eslint/issues"},"bundleDependencies":false,"dependencies":{"debug":"^4.1.1","eslint-visitor-keys":"^1.1.0","glob":"^7.1.6","is-glob":"^4.0.1","lodash":"^4.17.15","semver":"^6.3.0","tsutils":"^3.17.1"},"deprecated":false,"description":"A parser that converts TypeScript source code into an ESTree compatible form","devDependencies":{"@babel/code-frame":"^7.8.3","@babel/parser":"^7.8.3","@babel/types":"^7.8.3","@types/babel__code-frame":"^7.0.1","@types/debug":"^4.1.5","@types/glob":"^7.1.1","@types/is-glob":"^4.0.1","@types/lodash":"^4.14.149","@types/semver":"^6.2.0","@types/tmp":"^0.1.0","@typescript-eslint/shared-fixtures":"2.31.0","tmp":"^0.1.0","typescript":"*"},"engines":{"node":"^8.10.0 || ^10.13.0 || >=11.10.1"},"files":["dist","README.md","LICENSE"],"funding":{"type":"opencollective","url":"https://opencollective.com/typescript-eslint"},"gitHead":"176054c2171b682217d6855208e50b15e1712675","homepage":"https://github.com/typescript-eslint/typescript-eslint#readme","keywords":["ast","estree","ecmascript","javascript","typescript","parser","syntax"],"license":"BSD-2-Clause","main":"dist/parser.js","name":"@typescript-eslint/typescript-estree","peerDependenciesMeta":{"typescript":{"optional":true}},"repository":{"type":"git","url":"git+https://github.com/typescript-eslint/typescript-eslint.git","directory":"packages/typescript-estree"},"scripts":{"build":"tsc -b tsconfig.build.json","clean":"tsc -b tsconfig.build.json --clean","format":"prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore","lint":"eslint . --ext .js,.ts --ignore-path='../../.eslintignore'","test":"jest --coverage","typecheck":"tsc -p tsconfig.json --noEmit"},"types":"dist/parser.d.ts","version":"2.31.0"};
module.exports = {"name":"@typescript-eslint/typescript-estree","version":"2.31.0","description":"A parser that converts TypeScript source code into an ESTree compatible form","main":"dist/parser.js","types":"dist/parser.d.ts","files":["dist","README.md","LICENSE"],"engines":{"node":"^8.10.0 || ^10.13.0 || >=11.10.1"},"repository":{"type":"git","url":"https://github.com/typescript-eslint/typescript-eslint.git","directory":"packages/typescript-estree"},"bugs":{"url":"https://github.com/typescript-eslint/typescript-eslint/issues"},"license":"BSD-2-Clause","keywords":["ast","estree","ecmascript","javascript","typescript","parser","syntax"],"scripts":{"build":"tsc -b tsconfig.build.json","clean":"tsc -b tsconfig.build.json --clean","format":"prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore","lint":"eslint . --ext .js,.ts --ignore-path='../../.eslintignore'","test":"jest --coverage","typecheck":"tsc -p tsconfig.json --noEmit"},"dependencies":{"debug":"^4.1.1","eslint-visitor-keys":"^1.1.0","glob":"^7.1.6","is-glob":"^4.0.1","lodash":"^4.17.15","semver":"^6.3.0","tsutils":"^3.17.1"},"devDependencies":{"@babel/code-frame":"^7.8.3","@babel/parser":"^7.8.3","@babel/types":"^7.8.3","@types/babel__code-frame":"^7.0.1","@types/debug":"^4.1.5","@types/glob":"^7.1.1","@types/is-glob":"^4.0.1","@types/lodash":"^4.14.149","@types/semver":"^6.2.0","@types/tmp":"^0.1.0","@typescript-eslint/shared-fixtures":"2.31.0","tmp":"^0.1.0","typescript":"*"},"peerDependenciesMeta":{"typescript":{"optional":true}},"funding":{"type":"opencollective","url":"https://opencollective.com/typescript-eslint"},"gitHead":"176054c2171b682217d6855208e50b15e1712675","_resolved":"https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.31.0.tgz","_integrity":"sha512-vxW149bXFXXuBrAak0eKHOzbcu9cvi6iNcJDzEtOkRwGHxJG15chiAQAwhLOsk+86p9GTr/TziYvw+H9kMaIgA==","_from":"@typescript-eslint/[email protected]"};

/***/ }),
/* 488 */
Expand Down Expand Up @@ -245551,7 +245588,49 @@ exports.ArraySet = ArraySet;

/***/ }),
/* 839 */,
/* 840 */,
/* 840 */
/***/ (function(__unusedmodule, exports, __webpack_require__) {

"use strict";

var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(__webpack_require__(470));
exports.defaultInputs = {
publishDir() {
return core.getInput('publish-dir', { required: true });
},
deployMessage() {
return core.getInput('deploy-message') || undefined;
},
productionBranch() {
return core.getInput('production-branch') || undefined;
},
enablePullRequestComment() {
// Default: true
return (core.getInput('enable-pull-request-comment') || 'true') === 'true';
},
enableCommitComment() {
// Default: true
return (core.getInput('enable-commit-comment') || 'true') === 'true';
},
githubToken() {
return core.getInput('github-token');
},
overwritesPullRequestComment() {
// Default: true
return ((core.getInput('overwrites-pull-request-comment') || 'true') === 'true');
}
};


/***/ }),
/* 841 */,
/* 842 */
/***/ (function(__unusedmodule, exports, __webpack_require__) {
Expand Down
Loading

1 comment on commit c6e2a32

@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.