From 1a9f21e594b019a22a41f49a53e23625f9a6dd45 Mon Sep 17 00:00:00 2001 From: Ben Coleman Date: Thu, 14 Mar 2024 16:25:21 +0000 Subject: [PATCH] CI fix --- .github/workflows/build-test.yaml | 68 +++++++++++++++---------------- README.md | 27 ++++++++---- 2 files changed, 51 insertions(+), 44 deletions(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index 37d1b20..26e77d6 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -2,51 +2,47 @@ name: Build & Test on: push: - branches: [ master ] + branches: [master] workflow_dispatch: jobs: build: runs-on: ubuntu-latest steps: - - name: Check out repository - uses: actions/checkout@v2 - - - name: Build with ncc - run: | - npm install - npm run build - - - name: Invoke echo 1 workflow using this action - uses: ./ - with: - workflow: Message Echo 1 - token: ${{ secrets.PERSONAL_TOKEN }} - inputs: '{"message": "blah blah"}' - - - name: Invoke echo 2 workflow using this action - uses: ./ - with: - workflow: echo-2.yaml - token: ${{ secrets.PERSONAL_TOKEN }} - - - name: Invoke echo 1 workflow by id - uses: ./ - with: - workflow: '1854247' - token: ${{ secrets.PERSONAL_TOKEN }} - inputs: '{"message": "Mango jam"}' - - - name: Update repo with build - uses: mikeal/publish-to-github-action@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Check out repository + uses: actions/checkout@v4 + + - name: Build with ncc + run: | + npm install + npm run build + + - name: Invoke echo 1 workflow using this action + uses: ./ + with: + workflow: Message Echo 1 + inputs: '{"message": "blah blah"}' + + - name: Invoke echo 2 workflow using this action + uses: ./ + with: + workflow: echo-2.yaml + + - name: Invoke echo 1 workflow by id + uses: ./ + with: + workflow: "1854247" + inputs: '{"message": "Mango jam"}' + + - name: Update repo with build + uses: mikeal/publish-to-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # - name: Invoke external workflow using this action # uses: ./ # with: - # workflow: Deploy To Kubernetes + # workflow: Deploy To Kubernetes # repo: benc-uk/dapr-store # token: ${{ secrets.PERSONAL_TOKEN }} - # ref: master - \ No newline at end of file + # ref: master diff --git a/README.md b/README.md index fab4686..b608453 100644 --- a/README.md +++ b/README.md @@ -7,15 +7,16 @@ This allows you to chain workflows, the classic use case is have a CI build work For details of the `workflow_dispatch` even see [this blog post introducing this type of trigger](https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/) -*Note 1.* GitHub now has a native way to chain workflows called "reusable workflows". See the docs on [reusing workflows](https://docs.github.com/en/actions/using-workflows/reusing-workflows). This approach is somewhat different from workflow_dispatch but it's worth keeping in mind. +_Note 1._ GitHub now has a native way to chain workflows called "reusable workflows". See the docs on [reusing workflows](https://docs.github.com/en/actions/using-workflows/reusing-workflows). This approach is somewhat different from workflow_dispatch but it's worth keeping in mind. -*Note 2.* The GitHub UI will report flows triggered by this action as "manually triggered" even though they have been run programmatically via another workflow and the API. +_Note 2._ The GitHub UI will report flows triggered by this action as "manually triggered" even though they have been run programmatically via another workflow and the API. -*Note 3.* If you want to reference the target workflow by ID, you will need to list them with the following REST API call `curl https://api.github.com/repos/{{owner}}/{{repo}}/actions/workflows -H "Authorization: token {{pat-token}}"` +_Note 3._ If you want to reference the target workflow by ID, you will need to list them with the following REST API call `curl https://api.github.com/repos/{{owner}}/{{repo}}/actions/workflows -H "Authorization: token {{pat-token}}"` ## Action Inputs ### `workflow` + **Required.** The name, filename or ID of the workflow to be triggered and run. All three possibilities are used when looking for the workflow. e.g. ```yaml @@ -27,26 +28,34 @@ workflow: 1218419 ``` ### `inputs` + **Optional.** The inputs to pass to the workflow (if any are configured), this must be a JSON encoded string, e.g. `{ "myInput": "foobar" }` ### `ref` -**Optional.** The Git reference used with the triggered workflow run. The reference can be a branch, tag, or a commit SHA. If omitted the context ref of the triggering workflow is used. If you want to trigger on pull requests and run the target workflow in the context of the pull request branch, set the ref to `${{ github.event.pull_request.head.ref }}`. + +**Optional.** The Git reference used with the triggered workflow run. The reference can be a branch, tag, or a commit SHA. If omitted the context ref of the triggering workflow is used. If you want to trigger on pull requests and run the target workflow in the context of the pull request branch, set the ref to `${{ github.event.pull_request.head.ref }}`. ### `repo` + **Optional.** The default behavior is to trigger workflows in the same repo as the triggering workflow, if you wish to trigger in another GitHub repo "externally", then provide the owner + repo name with slash between them e.g. `microsoft/vscode`. -- When triggering across repos like this, you **must** provide a `token` (see below), or you will get an *"Resource not accessible by integration"* error. -- If the default branch in the other repo is different from the calling repo, you must provide `ref` input also, or you will get a *"No ref found"* error. +- When triggering across repos like this, you **must** provide a `token` (see below), or you will get an _"Resource not accessible by integration"_ error. +- If the default branch in the other repo is different from the calling repo, you must provide `ref` input also, or you will get a _"No ref found"_ error. ### `token` -**Optional.** By default the standard `github.token`/`GITHUB_TOKEN` will be used and you no longer need to provide your own token here. However when using the `repo` option, you must provide a token here, create a PAT token with repo rights, and pass it here via a secret. This options is also left for backwards compatibility reasons. +**Optional.** By default the standard `github.token`/`GITHUB_TOKEN` will be used and you no longer need to provide your own token here. + +**⚠️ IMPORTANT:** When using the `repo` option to call across repos, you **must** provide the token. In order to do so, create a PAT token with repo rights, and pass it here via a secret, e.g. `${{ secrets.MY_TOKEN }}`. + +This option is also left for backwards compatibility with older versions where this field was mandatory. ## Action Outputs -This Action emits a single output named `workflowId`. +This Action emits a single output named `workflowId`. ## Example usage + ```yaml - name: Invoke workflow without inputs uses: benc-uk/workflow-dispatch@v1 @@ -69,4 +78,6 @@ This Action emits a single output named `workflowId`. workflow: my-workflow.yaml repo: benc-uk/example inputs: '{ "message": "blah blah", "something": false }' + # Required when using the `repo` option. Either a PAT or a token generated from the GitHub app or CLI + token: "${{ secrets.MY_TOKEN }}" ```