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 c99b023a..5316ccad 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}`); diff --git a/index.js b/index.js index b08705bf..e74f4fe7 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}`); 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": {