From 8f018069ef245071a8a91c7722365020c9576ec8 Mon Sep 17 00:00:00 2001 From: Kamran Ayub Date: Fri, 31 Jul 2020 00:07:15 -0500 Subject: [PATCH 1/6] fix: should work on non-pr builds --- index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b08705bf..588b46c3 100644 --- a/index.js +++ b/index.js @@ -32,14 +32,18 @@ const run = async () => { // not the *latest commit* of the PR which is what Netlify uses. Instead, // have to use github.context.payload.pull_request.head.sha // See: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#pull_request - const commitSha = github.context.payload.pull_request.head.sha; + const isPr = 'pull_request' in github.context.payload; + const commitSha = isPr ? github.context.payload.pull_request.head.sha : github.context.sha; const MAX_TIMEOUT = Number(core.getInput('max_timeout')) || 60; const siteName = core.getInput('site_name'); if (!netlifyToken) { core.setFailed('Please set NETLIFY_TOKEN env variable to your Netlify Personal Access Token secret'); } + if (!commitSha) { core.setFailed('Could not determine GitHub commit'); + } else { + console.log('Using SHA', commitSha, isPr ? ' from PR' : ''); } if (!siteName) { core.setFailed('Required field `site_name` was not provided'); @@ -61,7 +65,7 @@ const run = async () => { // Most likely, it's the first entry in the response // but we correlate it just to be safe const commitDeployment = netlifyDeployments.find( - (d) => d.commit_ref === commitSha && d.context === 'deploy-preview', + (d) => d.commit_ref === commitSha && d.context === (isPr ? 'deploy-preview' : 'production'), ); if (!commitDeployment) { core.setFailed(`Could not find deployment for commit ${commitSha}`); From 5386b85884e2eb007f4377a954fa57715d11bf43 Mon Sep 17 00:00:00 2001 From: Kamran Ayub Date: Fri, 31 Jul 2020 00:16:36 -0500 Subject: [PATCH 2/6] chore: compile --- dist/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index c99b023a..890ffb89 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1838,14 +1838,18 @@ const run = async () => { // not the *latest commit* of the PR which is what Netlify uses. Instead, // have to use github.context.payload.pull_request.head.sha // See: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#pull_request - const commitSha = github.context.payload.pull_request.head.sha; + const isPr = 'pull_request' in github.context.payload; + const commitSha = isPr ? github.context.payload.pull_request.head.sha : github.context.sha; const MAX_TIMEOUT = Number(core.getInput('max_timeout')) || 60; const siteName = core.getInput('site_name'); if (!netlifyToken) { core.setFailed('Please set NETLIFY_TOKEN env variable to your Netlify Personal Access Token secret'); } + if (!commitSha) { core.setFailed('Could not determine GitHub commit'); + } else { + console.log('Using SHA', commitSha, isPr ? ' from PR' : ''); } if (!siteName) { core.setFailed('Required field `site_name` was not provided'); @@ -1867,7 +1871,7 @@ const run = async () => { // Most likely, it's the first entry in the response // but we correlate it just to be safe const commitDeployment = netlifyDeployments.find( - (d) => d.commit_ref === commitSha && d.context === 'deploy-preview', + (d) => d.commit_ref === commitSha && d.context === (isPr ? 'deploy-preview' : 'production'), ); if (!commitDeployment) { core.setFailed(`Could not find deployment for commit ${commitSha}`); From 12db43970161a15b56e81a1bc4c36030aa9ab96c Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 31 Jul 2020 05:18:42 +0000 Subject: [PATCH 3/6] chore(release): 2.0.1 [skip ci] ## [2.0.1](https://github.com/kamranayub/wait-for-netlify-action/compare/v2.0.0...v2.0.1) (2020-07-31) ### Bug Fixes * **package:** always build on pre-commit ([1fec6dd](https://github.com/kamranayub/wait-for-netlify-action/commit/1fec6dd7db4396975eb2929e7a6777bcf67288a9)) --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3db869b3..df674d6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [2.0.1](https://github.com/kamranayub/wait-for-netlify-action/compare/v2.0.0...v2.0.1) (2020-07-31) + + +### Bug Fixes + +* **package:** always build on pre-commit ([1fec6dd](https://github.com/kamranayub/wait-for-netlify-action/commit/1fec6dd7db4396975eb2929e7a6777bcf67288a9)) + # [2.0.0](https://github.com/kamranayub/wait-for-netlify-action/compare/v1.0.0...v2.0.0) (2020-07-31) From 8d57496916c8b82099bff81062f1fe4f1ee160d1 Mon Sep 17 00:00:00 2001 From: Kamran Ayub Date: Fri, 31 Jul 2020 00:22:07 -0500 Subject: [PATCH 4/6] fix(package): typos and path --- action.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index a8a8e0c1..cab75435 100644 --- a/action.yml +++ b/action.yml @@ -15,4 +15,4 @@ outputs: description: "The fully qualified deploy preview URL" runs: using: "node12" - main: "dist/gindex.js" + main: "dist/index.js" diff --git a/package.json b/package.json index e6be5629..1cffea69 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.0.0-development", "private": true, "description": "A GitHub action that waits for a Netlify deployment preview for the current commit being built", - "main": "index.js", + "main": "dist/index.js", "scripts": { "build": "ncc build -o dist index.js", "lint": "eslint --cache --fix index.js", From 96dfce08a1c4f6c483537e8ac99e66d40ee2601a Mon Sep 17 00:00:00 2001 From: Kamran Ayub Date: Fri, 31 Jul 2020 00:33:20 -0500 Subject: [PATCH 5/6] chore: formatting --- .vscode/settings.json | 3 +++ dist/index.js | 2 +- index.js | 2 +- package.json | 7 ++----- 4 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..35c483d8 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "files.eol": "\n" +} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 890ffb89..5316ccad 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1849,7 +1849,7 @@ const run = async () => { if (!commitSha) { core.setFailed('Could not determine GitHub commit'); } else { - console.log('Using SHA', commitSha, isPr ? ' from PR' : ''); + console.log('Using SHA', commitSha, isPr ? 'from PR' : ''); } if (!siteName) { core.setFailed('Required field `site_name` was not provided'); diff --git a/index.js b/index.js index 588b46c3..e74f4fe7 100644 --- a/index.js +++ b/index.js @@ -43,7 +43,7 @@ const run = async () => { if (!commitSha) { core.setFailed('Could not determine GitHub commit'); } else { - console.log('Using SHA', commitSha, isPr ? ' from PR' : ''); + console.log('Using SHA', commitSha, isPr ? 'from PR' : ''); } if (!siteName) { core.setFailed('Required field `site_name` was not provided'); diff --git a/package.json b/package.json index 1cffea69..f5418e77 100644 --- a/package.json +++ b/package.json @@ -42,15 +42,12 @@ }, "husky": { "hooks": { - "pre-commit": "lint-staged", + "pre-commit": "lint-staged && npm run build && git add dist", "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" } }, "lint-staged": { - "./*.js": [ - "eslint --cache --fix", - "npm run build" - ], + "./*.js": "eslint --cache --fix", "*.md": "prettier --write" }, "release": { From 2a69ae018eb4c820a65c0f8801f8cf4da15d1634 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 31 Jul 2020 05:23:57 +0000 Subject: [PATCH 6/6] chore(release): 2.0.2 [skip ci] ## [2.0.2](https://github.com/kamranayub/wait-for-netlify-action/compare/v2.0.1...v2.0.2) (2020-07-31) ### Bug Fixes * **package:** typos and path ([4d21387](https://github.com/kamranayub/wait-for-netlify-action/commit/4d213878739b2b970f2d67b128a332411aa508b3)) --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index df674d6c..6e9fc426 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [2.0.2](https://github.com/kamranayub/wait-for-netlify-action/compare/v2.0.1...v2.0.2) (2020-07-31) + + +### Bug Fixes + +* **package:** typos and path ([4d21387](https://github.com/kamranayub/wait-for-netlify-action/commit/4d213878739b2b970f2d67b128a332411aa508b3)) + ## [2.0.1](https://github.com/kamranayub/wait-for-netlify-action/compare/v2.0.0...v2.0.1) (2020-07-31)