Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

work pls #4

Merged
merged 9 commits into from
Jun 10, 2023
72 changes: 55 additions & 17 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
- uses: actions/setup-node@v2
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '12'
node-version: '16'
- name: Build with ncc
run: |
npm install -g yarn
yarn install
yarn run build
- name: Archive dist
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: build
path: dist
Expand All @@ -31,9 +31,9 @@ jobs:
name: "echo-1-test [trigger|by workflow name]"
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Download dist
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: build
path: dist
Expand All @@ -51,9 +51,9 @@ jobs:
name: "echo-2-test [trigger|by workflow filename]"
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Download dist
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: build
path: dist
Expand All @@ -78,9 +78,9 @@ jobs:
name: "long-running-test [trigger+wait|by workflow filename|shoud succeed]"
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Download dist
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: build
path: dist
Expand Down Expand Up @@ -108,9 +108,9 @@ jobs:
name: "failing-test [trigger+wait|by workflow filename|shoud report failure]"
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Download dist
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: build
path: dist
Expand Down Expand Up @@ -139,9 +139,9 @@ jobs:
name: "timeout-test [trigger+wait|by workflow filename|shoud report timed_out]"
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Download dist
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: build
path: dist
Expand All @@ -163,6 +163,38 @@ jobs:
expected: failure
actual: ${{ steps.timeout-workflow.outcome }}

print-workflow-logs-test:
needs: [build]
runs-on: ubuntu-latest
name: "print-workflow-logs-test [trigger+wait|by workflow filename|print logs|shoud report timed_out]"
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Download dist
uses: actions/download-artifact@v3
with:
name: build
path: dist
- name: Invoke 'retrieve-logs' workflow and wait for result using this action
id: print-workflow-logs
uses: ./
with:
workflow: retrieve-logs.yml
token: ${{ secrets.PERSONAL_TOKEN }}
wait-for-completion-interval: 10s
wait-for-completion-timeout: 120s
workflow-logs: print
continue-on-error: true
- uses: nick-invision/assert-action@v1
with:
expected: timed_out
actual: ${{ steps.print-workflow-logs.outputs.workflow-conclusion }}
- uses: nick-invision/assert-action@v1
with:
expected: failure
actual: ${{ steps.print-workflow-logs.outcome }}
# TODO: add assertions on logs

# - name: Invoke external workflow using this action
# uses: ./
# with:
Expand All @@ -172,13 +204,19 @@ jobs:
# ref: master

deploy:
needs: [echo-1-test, echo-2-test, long-running-test, failing-test, timeout-test]
needs:
- echo-1-test
- echo-2-test
- long-running-test
- failing-test
- timeout-test
- print-workflow-logs-test
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Download dist
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: build
path: dist
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/retrieve-logs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Retrieve logs

on:
workflow_dispatch:

jobs:
echo:
runs-on: ubuntu-latest
steps:
- name: Echo message
run: |
for i in {1..500}
do
echo "Hello $i"
sleep 0.1
done

timeout:
runs-on: ubuntu-latest
steps:
- name: Sleep
run: sleep 1200s

more-real-example:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v3
with:
node-version: '16'
- name: Some command with npx
run: |
npx create-react-app example-app
69 changes: 49 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,70 @@ _This action is a fork of `benc-uk/workflow-dispatch` to add support for waiting

## Inputs
### `workflow`
**Required.** The name or the filename or ID of the workflow to trigger and run.
> **Required.** The name or the filename or ID of the workflow to trigger and run.

### `token`

**Required.** A GitHub access token (PAT) with write access to the repo in question. **NOTE.** The automatically provided token e.g. `${{ secrets.GITHUB_TOKEN }}` can not be used, GitHub prevents this token from being able to fire the `workflow_dispatch` and `repository_dispatch` event. [The reasons are explained in the docs](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token).

The solution is to manually create a PAT and store it as a secret e.g. `${{ secrets.PERSONAL_TOKEN }}`
> **Required.** A GitHub access token (PAT) with write access to the repo in question.
>
> **NOTE.** The automatically provided token e.g. `${{ secrets.GITHUB_TOKEN }}` can not be used, GitHub prevents this token from being able to fire the `workflow_dispatch` and `repository_dispatch` event. [The reasons are explained in the docs](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token).
> The solution is to manually create a PAT and store it as a secret e.g. `${{ secrets.PERSONAL_TOKEN }}`

### `inputs`
**Optional.** The inputs to pass to the workflow (if any are configured), this must be a JSON encoded string, e.g. `{ "myInput": "foobar" }`.

All values must be strings (even if they are used as booleans or numbers in the triggered workflow). The triggered workflow should use `fromJson` function to get the right type
> **Optional.** The inputs to pass to the workflow (if any are configured), this must be a JSON encoded string, e.g. `{ "myInput": "foobar" }`.
>
> All values must be strings (even if they are used as booleans or numbers in the triggered workflow). The triggered workflow should use `fromJson` function to get the right type

### `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`
> **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`

### `run-name` (since 3.0.0)
> **Optional.** The default behavior is to get the remote run ID based on the latest workflow name and date, if you have multiple of the same workflow running at the same time it can point to an incorrect run id.
> You can specify the run name to fetch the run ID based on the actual run name.

### `wait-for-completion`
**Optional.** If `true`, this action will actively poll the workflow run to get the result of the triggered workflow. It is enabled by default. If the triggered workflow fails due to either `failure`, `timed_out` or `cancelled` then the step that has triggered the other workflow will be marked as failed too.
> **Optional.** If `true`, this action will actively poll the workflow run to get the result of the triggered workflow. It is enabled by default. If the triggered workflow fails due to either `failure`, `timed_out` or `cancelled` then the step that has triggered the other workflow will be marked as failed too.

### `wait-for-completion-timeout`
**Optional.** The time to wait to mark triggered workflow has timed out. The time must be suffixed by the time unit e.g. `10m`. Time unit can be `s` for seconds, `m` for minutes and `h` for hours. It has no effect if `wait-for-completion` is `false`. Default is `1h`
> **Optional.** The time to wait to mark triggered workflow has timed out. The time must be suffixed by the time unit e.g. `10m`. Time unit can be `s` for seconds, `m` for minutes and `h` for hours. It has no effect if `wait-for-completion` is `false`. Default is `1h`

### `wait-for-completion-interval`
**Optional.** The time to wait between two polls for getting run status. The time must be suffixed by the time unit e.g. `10m`. Time unit can be `s` for seconds, `m` for minutes and `h` for hours. It has no effect if `wait-for-completion` is `false`. Default is `1m`.
**/!\ Do not use a value that is too small to avoid `API Rate limit exceeded`**
> **Optional.** The time to wait between two polls for getting run status. The time must be suffixed by the time unit e.g. `10m`. Time unit can be `s` for seconds, `m` for minutes and `h` for hours. It has no effect if `wait-for-completion` is `false`. Default is `1m`.
>
> **/!\ Do not use a value that is too small to avoid `API Rate limit exceeded`**

### `display-workflow-run-url`
**Optional.** If `true`, it displays in logs the URL of the triggered workflow. It is useful to follow the progress of the triggered workflow. It is enabled by default.
> **Optional.** If `true`, it displays in logs the URL of the triggered workflow. It is useful to follow the progress of the triggered workflow. It is enabled by default.

### `display-workflow-run-url-timeout`
**Optional.** The time to wait for getting the workflow run URL. If the timeout is reached, it doesn't fail and continues. Displaying the workflow URL is just for information purpose. The time must be suffixed by the time unit e.g. `10m`. Time unit can be `s` for seconds, `m` for minutes and `h` for hours. It has no effect if `display-workflow-run-url` is `false`. Default is `10m`
> **Optional.** The time to wait for getting the workflow run URL. If the timeout is reached, it doesn't fail and continues. Displaying the workflow URL is just for information purpose. The time must be suffixed by the time unit e.g. `10m`. Time unit can be `s` for seconds, `m` for minutes and `h` for hours. It has no effect if `display-workflow-run-url` is `false`. Default is `10m`

### `display-workflow-run-url-interval`
**Optional.** The time to wait between two polls for getting workflow run URL. The time must be suffixed by the time unit e.g. `10m`. Time unit can be `s` for seconds, `m` for minutes and `h` for hours. It has no effect if `display-workflow-run-url` is `false`. Default is `1m`.
**/!\ Do not use a value that is too small to avoid `API Rate limit exceeded`**
> **Optional.** The time to wait between two polls for getting workflow run URL. The time must be suffixed by the time unit e.g. `10m`. Time unit can be `s` for seconds, `m` for minutes and `h` for hours. It has no effect if `display-workflow-run-url` is `false`. Default is `1m`.
>
> **/!\ Do not use a value that is too small to avoid `API Rate limit exceeded`**

### `workflow-logs`
> **Optional.** Indicate what to do with logs of the triggered workflow:
>
> * `print`: Retrieve the logs for each job of the triggered workflow and print into the logs of the job that triggered the workflow.
> * `ignore`: Do not retrieve log of triggered workflow at all (default).
>
> Only available when `wait-for-completion` is `true`.
>
> Default is `ignore`.


## Outputs
### `workflow-url`
The URL of the workflow run that has been triggered. It may be undefined if the URL couldn't be retrieved (timeout reached) or if `wait-for-completion` and `display-workflow-run-url` are both `false`
> The URL of the workflow run that has been triggered. It may be undefined if the URL couldn't be retrieved (timeout reached) or if `wait-for-completion` and `display-workflow-run-url` are > both `false`

### `workflow-conclusion`
The result of the triggered workflow. May be one of `success`, `failure`, `cancelled`, `timed_out`, `skipped`, `neutral`, `action_required`. The step in your workflow will fail if the triggered workflow completes with `failure`, `cancelled` or `timed_out`. Other workflow conlusion are considered success.
Only available if `wait-for-completion` is `true`
> The result of the triggered workflow. May be one of `success`, `failure`, `cancelled`, `timed_out`, `skipped`, `neutral`, `action_required`. The step in your workflow will fail if the triggered workflow completes with `failure`, `cancelled` or `timed_out`. Other workflow conlusion are considered success.
> Only available if `wait-for-completion` is `true`


## Example usage
Expand Down Expand Up @@ -111,3 +129,14 @@ Only available if `wait-for-completion` is `true`
if: always()
run: echo "Another Workflow conclusion: ${{ steps.trigger-step.outputs.workflow-conclusion }}"
```


## Contributions

Thanks to:

* [samirergaibi](https://github.com/samirergaibi)
* [rui-ferreira](https://github.com/rui-ferreira)
* [robbertvdg](https://github.com/robbertvdg)
* [samit2040](https://github.com/samit2040)
* [jonas-schievink](https://github.com/jonas-schievink)
11 changes: 9 additions & 2 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ inputs:
repo:
description: 'Repo owner & name, slash separated, only set if invoking a workflow in a different repo'
required: false
run-name:
description: 'If specified will select the run ID based on the run name'
required: false
display-workflow-run-url:
description: 'Get the URL of the triggered workflow and display it in logs (useful to follow the progress of the triggered workflow)'
required: false
Expand All @@ -41,11 +44,15 @@ inputs:
description: 'Time to wait (+unit) between two polls to get run status'
required: false
default: 1m
workflow-logs:
description: 'Indicate what to do with logs of the triggered workflow. `ignore` do not retrieve logs from tiggered workflow. `print` retrieves logs from triggered workflow and print in the workflow that triggered the other workflow.'
required: false
default: ignore

runs:
using: 'node12'
using: 'node16'
main: 'dist/index.js'

branding:
color: purple
icon: send
icon: send
Loading