diff --git a/Makefile b/Makefile index 9e55e0b..08aaf31 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,11 @@ clean: npm run clean .PHONY: install -install: +install: npm install .PHONY: build -build: +build: npm run build .PHONY: test @@ -21,12 +21,12 @@ coverage: build npm run coverage .PHONY: all -all: +all: npm run all .PHONY: release release: all - npm prune --production + npm prune --production .PHONY: semantic-release semantic-release: @@ -58,4 +58,4 @@ tag-major: check-version check-version: ifndef VERSION $(error VERSION not defined) -endif \ No newline at end of file +endif \ No newline at end of file diff --git a/README.md b/README.md index a37c9bd..2adb957 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,10 @@ A simple Github Action that allows us to update the status of a commit. GitHub does not update the status of a commit when running workflow and therefore tools that rely on the context/status of a given commit are not compatible with it. -Currently the action supports `pull_request` and `push` events: -* When the event is `pull_request`, the action will set the status to the last commit in the pull request at the moment the workflow was triggered. -* When the event is `push`, the action will set the status to the last commit pushed at the moment the workflow was triggered. +Currently the action supports `pull_request`, `pull_request_target`, `merge_group`, and `push` events: + +* When the event is `pull_request` or `pull_request_target`, the action will set the status to the last commit in the pull request at the moment the workflow was triggered. +* When the event is `push` or `merge_group`, the action will set the status to the last commit pushed at the moment the workflow was triggered. ## Input Parameters @@ -35,7 +36,7 @@ If set to `error` it will set status commit `error`. ## Input Parameters specific to `pull_request` event -_These parameters are all optional and are used only for pull requests_ +_These parameters are all optional and are used only for pull requests._ | Name | Description | |---|---| @@ -52,11 +53,11 @@ By default, if we don't add `permissions` to the workflow or the job, the action * If we just want to set the status commit we need to be sure the job (or the whole workflow) has the permission: `statuses: write` * If we want to add a comment we need to be sure the job (or the whole workflow) has the permissions: `pull-requests: write` -## Examples +## Examples ### Action sets push commit to pending status -``` +```yaml name: Test on: [push] @@ -71,12 +72,12 @@ jobs: ### Action sets push commit to pending status with specific permissions -``` +```yaml name: Test on: [push] -permissions: +permissions: statuses: write jobs: @@ -87,10 +88,9 @@ jobs: - uses: ouzi-dev/commit-status-updater@v2 ``` - ### Action sets push commit to pending status with custom name -``` +```yaml name: Test on: [push] @@ -107,7 +107,7 @@ jobs: ### Action sets push commit to pending status on start, and updates check at the end of the workflow -``` +```yaml name: Test on: [push] @@ -126,7 +126,7 @@ jobs: ### Action sets pull request commit to pending status without comment -``` +```yaml name: Test on: [pull_request] @@ -141,7 +141,7 @@ jobs: ### Action sets pull request commit to error status without comment -``` +```yaml name: Test on: [pull_request] @@ -158,7 +158,7 @@ jobs: ### Action sets pull request commit to pending status with comment, and updates check and adds comment at the end of the workflow -``` +```yaml name: Test on: [pull_request] @@ -180,12 +180,12 @@ jobs: ### Action sets pull request commit to pending status with comment, and updates check and adds comment at the end of the workflow with specific permissions -``` +```yaml name: Test on: [pull_request] -permissions: +permissions: statuses: write pull-requests: write @@ -206,7 +206,7 @@ jobs: ### Action with custom hold comments -``` +```yaml name: Test on: [pull_request] @@ -224,10 +224,10 @@ jobs: successComment: "action success!" failComment: "action failed!" ``` - + ### Action no comments, set commit to "error" status and set url, description and specific name -``` +```yaml name: Test on: [pull_request] @@ -247,7 +247,7 @@ jobs: ### Action with specific token and setting status check in commits in forks -``` +```yaml name: Test on: [pull_request] @@ -265,12 +265,12 @@ jobs: ## Integration with Prow -An example is [Prow](https://github.com/kubernetes/test-infra/tree/master/prow#readme) which uses the Github Status API to read the status of a given commit. +An example is [Prow](https://github.com/kubernetes/test-infra/tree/master/prow#readme) which uses the Github Status API to read the status of a given commit. Using this actions you can tell tide to not skip optional contexts and effectively wait for a GitHub Workflow to pass before merging. ### Example with Tide -``` +```yaml tide: context_options: # Treat unknown contexts as required @@ -279,4 +279,4 @@ tide: ## Development -__Important: Before pushing your changes run `make release` to generate all the correct files and clean stuff, etc...__ \ No newline at end of file +__Important: Before pushing your changes run `make release` to generate all the correct files and clean stuff, etc...__ diff --git a/dist/index.js b/dist/index.js index fe5bf69..fcdcb65 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,3 +1,6 @@ +// Code generated via make release - DO NOT EDIT + + /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ @@ -60,7 +63,7 @@ class GithubHelper { initialize() { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11; return __awaiter(this, void 0, void 0, function* () { - if (github_1.context.eventName === 'pull_request') { + if (['pull_request', 'pull_request_target'].includes(github_1.context.eventName)) { this.isPR = true; this.owner = (_e = (_d = (_c = (_b = (_a = github_1.context.payload) === null || _a === void 0 ? void 0 : _a.pull_request) === null || _b === void 0 ? void 0 : _b.head) === null || _c === void 0 ? void 0 : _c.repo) === null || _d === void 0 ? void 0 : _d.owner) === null || _e === void 0 ? void 0 : _e.login; this.repo = (_j = (_h = (_g = (_f = github_1.context.payload) === null || _f === void 0 ? void 0 : _f.pull_request) === null || _g === void 0 ? void 0 : _g.head) === null || _h === void 0 ? void 0 : _h.repo) === null || _j === void 0 ? void 0 : _j.name; @@ -71,7 +74,7 @@ class GithubHelper { this.baseOwner = (_2 = (_1 = (_0 = (_z = (_y = github_1.context.payload) === null || _y === void 0 ? void 0 : _y.pull_request) === null || _z === void 0 ? void 0 : _z.base) === null || _0 === void 0 ? void 0 : _0.repo) === null || _1 === void 0 ? void 0 : _1.owner) === null || _2 === void 0 ? void 0 : _2.login; this.baseRepoName = (_6 = (_5 = (_4 = (_3 = github_1.context.payload) === null || _3 === void 0 ? void 0 : _3.pull_request) === null || _4 === void 0 ? void 0 : _4.base) === null || _5 === void 0 ? void 0 : _5.repo) === null || _6 === void 0 ? void 0 : _6.name; } - if (github_1.context.eventName === 'push') { + if (['push', 'merge_group'].includes(github_1.context.eventName)) { this.isPR = false; this.owner = (_9 = (_8 = (_7 = github_1.context.payload) === null || _7 === void 0 ? void 0 : _7.repository) === null || _8 === void 0 ? void 0 : _8.owner) === null || _9 === void 0 ? void 0 : _9.login; this.repo = (_11 = (_10 = github_1.context.payload) === null || _10 === void 0 ? void 0 : _10.repository) === null || _11 === void 0 ? void 0 : _11.name; @@ -105,7 +108,18 @@ class GithubHelper { core.info(`Updated build status: ${params.status}`); } catch (error) { - throw new Error(`error while setting context status: ${error.message}`); + /* + There is a point where a merge group has been merged and checks + may be re-run, where this status update does not appear possible + from some context/state reason that is not clear. + Therefore we try to sidestep this a bit and either allow this to + pass or fail without actually updating anything. + */ + const SUCCESS = 'success'; + core.warning(`Unable to properly update build status: ${params.status}`); + if (params.status !== SUCCESS) { + throw new Error(`Check ended with status: ${params.status}`); + } } }); } @@ -455,8 +469,10 @@ const github = __importStar(__nccwpck_require__(5438)); function validateEventType() { return __awaiter(this, void 0, void 0, function* () { if (github.context.eventName !== 'pull_request' && + github.context.eventName !== 'pull_request_target' && + github.context.eventName !== 'merge_group' && github.context.eventName !== 'push') { - throw new Error('Error, action only works for pull_request or push events!'); + throw new Error('Error, action only works for pull_request, pull_request_target, merge_group or push events!'); } }); } diff --git a/package-lock.json b/package-lock.json index 5033f1b..e0896ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,9 @@ "@octokit/webhooks": "^10.3.0", "@octokit/webhooks-types": "^6.5.0", "@vercel/ncc": "^0.34.0", + "cacheable-request": "^10.2.7", + "http-cache-semantics": "^4.1.1", + "json5": "^1.0.2", "npm-check-updates": "^16.3.14", "uuid": "^9.0.0" }, @@ -24,7 +27,7 @@ "@semantic-release/exec": "^6.0.3", "@semantic-release/github": "^8.0.6", "@semantic-release/release-notes-generator": "^10.0.3", - "@types/jest": "^29.2.0", + "@types/jest": "^29.5.14", "@types/node": "^18.11.2", "@types/uuid": "^8.3.4", "@typescript-eslint/eslint-plugin": "^5.40.1", @@ -221,6 +224,19 @@ "url": "https://opencollective.com/babel" } }, + "node_modules/@babel/core/node_modules/json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true, + "license": "MIT", + "bin": { + "json5": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/@babel/core/node_modules/semver": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", @@ -1955,10 +1971,11 @@ } }, "node_modules/@types/jest": { - "version": "29.2.0", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.2.0.tgz", - "integrity": "sha512-KO7bPV21d65PKwv3LLsD8Jn3E05pjNjRZvkm+YTacWhVmykAb07wW6IkZUmQAltwQafNcDUEUrMO2h3jeBSisg==", + "version": "29.5.14", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.14.tgz", + "integrity": "sha512-ZN+4sdnLUbo8EVvVc2ao0GFW6oVrQRPn4K2lglySj7APvSrgzxHiNNK99us4WDMi57xxA2yggblIAMNhXOotLQ==", "dev": true, + "license": "MIT", "dependencies": { "expect": "^29.0.0", "pretty-format": "^29.0.0" @@ -2902,16 +2919,17 @@ } }, "node_modules/cacheable-request": { - "version": "10.2.1", - "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-10.2.1.tgz", - "integrity": "sha512-3tLJyBjGuXw1s5gpKFSG3iS4kaKT4id04dZi98wzHQp/8cqZNweBnrF9J+rrlvrf4M53OdtDGNctNHFias8BEA==", + "version": "10.2.7", + "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-10.2.7.tgz", + "integrity": "sha512-I4SA6mKgDxcxVbSt/UmIkb9Ny8qSkg6ReBHtAAXnZHk7KOSx5g3DTiAOaYzcHCs6oOdHn+bip9T48E6tMvK9hw==", + "license": "MIT", "dependencies": { "@types/http-cache-semantics": "^4.0.1", "get-stream": "^6.0.1", - "http-cache-semantics": "^4.1.0", - "keyv": "^4.5.0", + "http-cache-semantics": "^4.1.1", + "keyv": "^4.5.2", "mimic-response": "^4.0.0", - "normalize-url": "^7.1.0", + "normalize-url": "^8.0.0", "responselike": "^3.0.0" }, "engines": { @@ -2919,11 +2937,12 @@ } }, "node_modules/cacheable-request/node_modules/normalize-url": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-7.2.0.tgz", - "integrity": "sha512-uhXOdZry0L6M2UIo9BTt7FdpBDiAGN/7oItedQwPKh8jh31ZlvC8U9Xl/EJ3aijDHaywXTW3QbZ6LuCocur1YA==", + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-8.0.1.tgz", + "integrity": "sha512-IO9QvjUMWxPQQhs60oOu10CRkWCiZzSUkzbXGGV9pviYl1fXYcvkzQ5jV9z8Y6un8ARoVRl4EtC6v6jNqbaJ/w==", + "license": "MIT", "engines": { - "node": ">=12.20" + "node": ">=14.16" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -5107,9 +5126,10 @@ "dev": true }, "node_modules/http-cache-semantics": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", - "integrity": "sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==" + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz", + "integrity": "sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==", + "license": "BSD-2-Clause" }, "node_modules/http-proxy-agent": { "version": "5.0.0", @@ -6402,7 +6422,8 @@ "node_modules/json-buffer": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", - "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==" + "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==", + "license": "MIT" }, "node_modules/json-parse-better-errors": { "version": "1.0.2", @@ -6442,14 +6463,15 @@ "dev": true }, "node_modules/json5": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.1.tgz", - "integrity": "sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.2.tgz", + "integrity": "sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==", + "license": "MIT", + "dependencies": { + "minimist": "^1.2.0" + }, "bin": { "json5": "lib/cli.js" - }, - "engines": { - "node": ">=6" } }, "node_modules/jsonfile": { @@ -6507,9 +6529,10 @@ } }, "node_modules/keyv": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.0.tgz", - "integrity": "sha512-2YvuMsA+jnFGtBareKqgANOEKe1mk3HKiXu2fRmAfyxG0MJAywNhi5ttWA3PMjl4NmpyjZNbFifR2vNjW1znfA==", + "version": "4.5.4", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", + "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==", + "license": "MIT", "dependencies": { "json-buffer": "3.0.1" } @@ -10965,6 +10988,18 @@ "require-from-string": "^2.0.2" } }, + "node_modules/rc-config-loader/node_modules/json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "license": "MIT", + "bin": { + "json5": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/rc/node_modules/strip-json-comments": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", @@ -12374,6 +12409,19 @@ } } }, + "node_modules/ts-jest/node_modules/json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true, + "license": "MIT", + "bin": { + "json5": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/ts-jest/node_modules/yargs-parser": { "version": "21.1.1", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", @@ -12395,18 +12443,6 @@ "strip-bom": "^3.0.0" } }, - "node_modules/tsconfig-paths/node_modules/json5": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", - "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", - "dev": true, - "dependencies": { - "minimist": "^1.2.0" - }, - "bin": { - "json5": "lib/cli.js" - } - }, "node_modules/tsconfig-paths/node_modules/strip-bom": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", @@ -13194,6 +13230,12 @@ "semver": "^6.3.0" }, "dependencies": { + "json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true + }, "semver": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", @@ -14553,9 +14595,9 @@ } }, "@types/jest": { - "version": "29.2.0", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.2.0.tgz", - "integrity": "sha512-KO7bPV21d65PKwv3LLsD8Jn3E05pjNjRZvkm+YTacWhVmykAb07wW6IkZUmQAltwQafNcDUEUrMO2h3jeBSisg==", + "version": "29.5.14", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.14.tgz", + "integrity": "sha512-ZN+4sdnLUbo8EVvVc2ao0GFW6oVrQRPn4K2lglySj7APvSrgzxHiNNK99us4WDMi57xxA2yggblIAMNhXOotLQ==", "dev": true, "requires": { "expect": "^29.0.0", @@ -15235,23 +15277,23 @@ "integrity": "sha512-+qJyx4xiKra8mZrcwhjMRMUhD5NR1R8esPkzIYxX96JiecFoxAXFuz/GpR3+ev4PE1WamHip78wV0vcmPQtp8w==" }, "cacheable-request": { - "version": "10.2.1", - "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-10.2.1.tgz", - "integrity": "sha512-3tLJyBjGuXw1s5gpKFSG3iS4kaKT4id04dZi98wzHQp/8cqZNweBnrF9J+rrlvrf4M53OdtDGNctNHFias8BEA==", + "version": "10.2.7", + "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-10.2.7.tgz", + "integrity": "sha512-I4SA6mKgDxcxVbSt/UmIkb9Ny8qSkg6ReBHtAAXnZHk7KOSx5g3DTiAOaYzcHCs6oOdHn+bip9T48E6tMvK9hw==", "requires": { "@types/http-cache-semantics": "^4.0.1", "get-stream": "^6.0.1", - "http-cache-semantics": "^4.1.0", - "keyv": "^4.5.0", + "http-cache-semantics": "^4.1.1", + "keyv": "^4.5.2", "mimic-response": "^4.0.0", - "normalize-url": "^7.1.0", + "normalize-url": "^8.0.0", "responselike": "^3.0.0" }, "dependencies": { "normalize-url": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-7.2.0.tgz", - "integrity": "sha512-uhXOdZry0L6M2UIo9BTt7FdpBDiAGN/7oItedQwPKh8jh31ZlvC8U9Xl/EJ3aijDHaywXTW3QbZ6LuCocur1YA==" + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-8.0.1.tgz", + "integrity": "sha512-IO9QvjUMWxPQQhs60oOu10CRkWCiZzSUkzbXGGV9pviYl1fXYcvkzQ5jV9z8Y6un8ARoVRl4EtC6v6jNqbaJ/w==" } } }, @@ -16851,9 +16893,9 @@ "dev": true }, "http-cache-semantics": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", - "integrity": "sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==" + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz", + "integrity": "sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==" }, "http-proxy-agent": { "version": "5.0.0", @@ -17844,9 +17886,12 @@ "dev": true }, "json5": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.1.tgz", - "integrity": "sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==" + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.2.tgz", + "integrity": "sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==", + "requires": { + "minimist": "^1.2.0" + } }, "jsonfile": { "version": "6.1.0", @@ -17889,9 +17934,9 @@ } }, "keyv": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.0.tgz", - "integrity": "sha512-2YvuMsA+jnFGtBareKqgANOEKe1mk3HKiXu2fRmAfyxG0MJAywNhi5ttWA3PMjl4NmpyjZNbFifR2vNjW1znfA==", + "version": "4.5.4", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", + "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==", "requires": { "json-buffer": "3.0.1" } @@ -21077,6 +21122,13 @@ "js-yaml": "^4.0.0", "json5": "^2.1.2", "require-from-string": "^2.0.2" + }, + "dependencies": { + "json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==" + } } }, "react-is": { @@ -22137,6 +22189,12 @@ "yargs-parser": "^21.0.1" }, "dependencies": { + "json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true + }, "yargs-parser": { "version": "21.1.1", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", @@ -22157,15 +22215,6 @@ "strip-bom": "^3.0.0" }, "dependencies": { - "json5": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", - "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", - "dev": true, - "requires": { - "minimist": "^1.2.0" - } - }, "strip-bom": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", diff --git a/package.json b/package.json index 20122c8..f17122c 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "format": "prettier --write **/*.ts", "format-check": "prettier --check **/*.ts", "lint": "eslint src/**/*.ts", - "pack": "ncc build", + "pack": "ncc build && mv dist/index.js dist/index.js.tmp && echo '// Code generated via make release - DO NOT EDIT\n\n' > dist/index.js && cat dist/index.js.tmp >> dist/index.js && rm -f dist/index.js.tmp", "test": "jest", "coverage": "jest --coverage=true", "clean": "rm -rf node_modules && rm -rf lib && rm -rf coverage && rm -rf dist", @@ -40,6 +40,9 @@ "@octokit/webhooks": "^10.3.0", "@octokit/webhooks-types": "^6.5.0", "@vercel/ncc": "^0.34.0", + "cacheable-request": "^10.2.7", + "http-cache-semantics": "^4.1.1", + "json5": "^1.0.2", "npm-check-updates": "^16.3.14", "uuid": "^9.0.0" }, @@ -48,7 +51,7 @@ "@semantic-release/exec": "^6.0.3", "@semantic-release/github": "^8.0.6", "@semantic-release/release-notes-generator": "^10.0.3", - "@types/jest": "^29.2.0", + "@types/jest": "^29.5.14", "@types/node": "^18.11.2", "@types/uuid": "^8.3.4", "@typescript-eslint/eslint-plugin": "^5.40.1", diff --git a/src/githubHelper.ts b/src/githubHelper.ts index a3c16c1..c9dc0d2 100644 --- a/src/githubHelper.ts +++ b/src/githubHelper.ts @@ -34,7 +34,11 @@ class GithubHelper { } private async initialize(): Promise { - if (context.eventName === 'pull_request') { + if ( + ['pull_request', 'pull_request_target'].includes( + context.eventName + ) + ) { this.isPR = true this.owner = context.payload?.pull_request?.head?.repo?.owner?.login this.repo = context.payload?.pull_request?.head?.repo?.name @@ -46,7 +50,11 @@ class GithubHelper { this.baseRepoName = context.payload?.pull_request?.base?.repo?.name } - if (context.eventName === 'push') { + if ( + ['push', 'merge_group'].includes( + context.eventName + ) + ) { this.isPR = false this.owner = context.payload?.repository?.owner?.login this.repo = context.payload?.repository?.name @@ -74,8 +82,9 @@ class GithubHelper { state: params.status, target_url: params.url }) - core.info(`Updated build status: ${params.status}`) + core.info(`Updated build status for ${params.name}: ${params.status}`) } catch (error) { + core.warning(`Unable to properly update build status for ${params.name}: ${params.status}`) throw new Error( `error while setting context status: ${(error as Error).message}` ) diff --git a/src/utils.ts b/src/utils.ts index adcaa2e..4974680 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -3,8 +3,12 @@ import * as github from '@actions/github' export async function validateEventType(): Promise { if ( github.context.eventName !== 'pull_request' && + github.context.eventName !== 'pull_request_target' && + github.context.eventName !== 'merge_group' && github.context.eventName !== 'push' ) { - throw new Error('Error, action only works for pull_request or push events!') + throw new Error( + 'Error, action only works for pull_request, pull_request_target, merge_group or push events!' + ) } }