From 2b4356f4a27c6b70609d5fcc9b639896098e4f46 Mon Sep 17 00:00:00 2001 From: Samuel Date: Mon, 19 Feb 2024 20:32:21 -0500 Subject: [PATCH] Trigger workflow --- README.md | 20 ++++++++++++++++++++ action.yml | 5 ++++- package.json | 2 +- src/index.ts | 14 ++++++++++++++ yarn.lock | 14 +++++++++++++- 5 files changed, 52 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4b4a344..8cbb873 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,23 @@ Auto-update is a minimalist [JavaScript GitHub action](https://help.github.com/e It is the missing piece to really automatically merge pull requests when [strict status checks](https://help.github.com/en/articles/types-of-required-status-checks) are set up to protect against [semantic conflicts](https://bors.tech/essay/2017/02/02/pitch/). Add [.github/workflows/auto-update.yml](.github/workflows/auto-update.yml) to your repository to use this action. + + +#### Triggering CI checks + +Due to Github Action limitations, the CI checks are not triggered when the action is run. To trigger the CI checks, you can use the following code in your workflow file: + +```yaml +jobs: + auto-update-pr: + runs-on: ubuntu-latest + steps: + - uses: tibdex/auto-update@v2 + with: + github_token: ${{ secrets.YOUR_TOKEN }} + workflow_id: 'YOUR_WORKFLOW_ID' +``` +YOUR_TOKEN must have sufficient permissions to trigger the workflow. +YOUR_WORKFLOW_ID is either the name of the workflow file or the id of the workflow. + +Then, make sure you update your workflow file to subscribe to the worfklow_dispatch event. \ No newline at end of file diff --git a/action.yml b/action.yml index b1ca18a..821d639 100644 --- a/action.yml +++ b/action.yml @@ -5,8 +5,11 @@ inputs: github_token: description: Token for the GitHub API. default: ${{ github.token }} + workflow_id: + description: The ID of the workflow to trigger. + required: false runs: - using: node16 + using: node20 main: dist/index.js branding: icon: refresh-cw diff --git a/package.json b/package.json index 5ae7d21..81e7dc2 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "devDependencies": { "@octokit/plugin-paginate-rest": "^5.0.1", "@octokit/webhooks-definitions": "^3.67.3", - "@types/node": "^16.11.7", + "@types/node": "^20.11.19", "@vercel/ncc": "^0.34.0", "eslint-config-prettier": "^8.5.0", "eslint-plugin-import": "^2.26.0", diff --git a/src/index.ts b/src/index.ts index 306d08f..32efa4b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -113,6 +113,20 @@ const handlePullRequest = async ( }, ); info("Updated!"); + + const workflowId = getInput("workflow_id"); + if (!workflowId) { + return; + } + + await octokit.request( + "POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches", + { + ...context.repo, + ref: pullRequest.head.ref, + workflow_id: workflowId, + } + ) } catch (error: unknown) { warning(ensureError(error)); await handleUnupdatablePullRequest(pullRequest, { octokit }); diff --git a/yarn.lock b/yarn.lock index 7e3a71f..87f4edc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -254,11 +254,18 @@ resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c" integrity sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ== -"@types/node@*", "@types/node@^16.11.7": +"@types/node@*": version "16.18.3" resolved "https://registry.yarnpkg.com/@types/node/-/node-16.18.3.tgz#d7f7ba828ad9e540270f01ce00d391c54e6e0abc" integrity sha512-jh6m0QUhIRcZpNv7Z/rpN+ZWXOicUUQbSoWks7Htkbb9IjFQj4kzcX/xFCkjstCj5flMsN8FiSvt+q+Tcs4Llg== +"@types/node@^20.11.19": + version "20.11.19" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.19.tgz#b466de054e9cb5b3831bee38938de64ac7f81195" + integrity sha512-7xMnVEcZFu0DikYjWOlRq7NTPETrm7teqUT2WkQjrTIkEgUyyGdWsj/Zg8bEJt5TNklzbPD1X3fqfsHw3SpapQ== + dependencies: + undici-types "~5.26.4" + "@types/normalize-package-data@^2.4.0", "@types/normalize-package-data@^2.4.1": version "2.4.1" resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301" @@ -2734,6 +2741,11 @@ unc-path-regex@^0.1.2: resolved "https://registry.yarnpkg.com/unc-path-regex/-/unc-path-regex-0.1.2.tgz#e73dd3d7b0d7c5ed86fbac6b0ae7d8c6a69d50fa" integrity sha512-eXL4nmJT7oCpkZsHZUOJo8hcX3GbsiDOa0Qu9F646fi8dT3XuSVopVqAcEiVzSKKH7UoDti23wNX3qGFxcW5Qg== +undici-types@~5.26.4: + version "5.26.5" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" + integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== + universal-user-agent@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/universal-user-agent/-/universal-user-agent-6.0.0.tgz#3381f8503b251c0d9cd21bc1de939ec9df5480ee"