Skip to content

Commit

Permalink
CI fix
Browse files Browse the repository at this point in the history
  • Loading branch information
benc-uk committed Mar 14, 2024
1 parent e523182 commit 1a9f21e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 44 deletions.
68 changes: 32 additions & 36 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

# ref: master
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 }}"
```

0 comments on commit 1a9f21e

Please sign in to comment.