Skip to content

Commit c2b3c6d

Browse files
feat(logs): Retrieve and print logs of triggered workflow
Upgrade all dependencies
1 parent fa6e1ad commit c2b3c6d

File tree

12 files changed

+7812
-2957
lines changed

12 files changed

+7812
-2957
lines changed

.github/workflows/build-test.yaml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,38 @@ jobs:
163163
expected: failure
164164
actual: ${{ steps.timeout-workflow.outcome }}
165165

166+
print-workflow-logs-test:
167+
needs: [build]
168+
runs-on: ubuntu-latest
169+
name: "print-workflow-logs-test [trigger+wait|by workflow filename|print logs|shoud report timed_out]"
170+
steps:
171+
- name: Check out repository
172+
uses: actions/checkout@v3
173+
- name: Download dist
174+
uses: actions/download-artifact@v3
175+
with:
176+
name: build
177+
path: dist
178+
- name: Invoke 'retrieve-logs' workflow and wait for result using this action
179+
id: print-workflow-logs
180+
uses: ./
181+
with:
182+
workflow: retrieve-logs.yml
183+
token: ${{ secrets.PERSONAL_TOKEN }}
184+
wait-for-completion-interval: 10s
185+
wait-for-completion-timeout: 120s
186+
workflow-logs: print
187+
continue-on-error: true
188+
- uses: nick-invision/assert-action@v1
189+
with:
190+
expected: timed_out
191+
actual: ${{ steps.print-workflow-logs.outputs.workflow-conclusion }}
192+
- uses: nick-invision/assert-action@v1
193+
with:
194+
expected: failure
195+
actual: ${{ steps.print-workflow-logs.outcome }}
196+
# TODO: add assertions on logs
197+
166198
# - name: Invoke external workflow using this action
167199
# uses: ./
168200
# with:
@@ -172,7 +204,13 @@ jobs:
172204
# ref: master
173205

174206
deploy:
175-
needs: [echo-1-test, echo-2-test, long-running-test, failing-test, timeout-test]
207+
needs:
208+
- echo-1-test
209+
- echo-2-test
210+
- long-running-test
211+
- failing-test
212+
- timeout-test
213+
- print-workflow-logs-test
176214
runs-on: ubuntu-latest
177215
steps:
178216
- name: Check out repository
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Retrieve logs
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
echo:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Echo message
11+
run: for i in {1..5000}; do; echo "Hello $i"; sleep 0.1; done
12+
13+
timeout:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Sleep
17+
run: sleep 1200s
18+
19+
more-real-example:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/setup-node@v3
23+
with:
24+
node-version: '16'
25+
- name: Some command with npx
26+
run: |
27+
npx create-react-app example-app

README.md

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,56 +15,70 @@ _This action is a fork of `benc-uk/workflow-dispatch` to add support for waiting
1515

1616
## Inputs
1717
### `workflow`
18-
**Required.** The name or the filename or ID of the workflow to trigger and run.
18+
> **Required.** The name or the filename or ID of the workflow to trigger and run.
1919
2020
### `token`
2121

22-
**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).
23-
24-
The solution is to manually create a PAT and store it as a secret e.g. `${{ secrets.PERSONAL_TOKEN }}`
22+
> **Required.** A GitHub access token (PAT) with write access to the repo in question.
23+
>
24+
> **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).
25+
> The solution is to manually create a PAT and store it as a secret e.g. `${{ secrets.PERSONAL_TOKEN }}`
2526
2627
### `inputs`
27-
**Optional.** The inputs to pass to the workflow (if any are configured), this must be a JSON encoded string, e.g. `{ "myInput": "foobar" }`.
28-
29-
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
28+
> **Optional.** The inputs to pass to the workflow (if any are configured), this must be a JSON encoded string, e.g. `{ "myInput": "foobar" }`.
29+
>
30+
> 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
3031
3132
### `ref`
32-
**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 }}`
33+
> **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 }}`
3334
3435
### `repo`
35-
**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`
36+
> **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`
3637
3738
### `run-name` (since 3.0.0)
38-
**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.
39-
You can specify the run name to fetch the run ID based on the actual run name.
39+
> **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.
40+
> You can specify the run name to fetch the run ID based on the actual run name.
4041
4142
### `wait-for-completion`
42-
**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.
43+
> **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.
4344
4445
### `wait-for-completion-timeout`
45-
**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`
46+
> **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`
4647
4748
### `wait-for-completion-interval`
48-
**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`.
49-
**/!\ Do not use a value that is too small to avoid `API Rate limit exceeded`**
49+
> **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`.
50+
>
51+
> **/!\ Do not use a value that is too small to avoid `API Rate limit exceeded`**
5052
5153
### `display-workflow-run-url`
52-
**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.
54+
> **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.
5355
5456
### `display-workflow-run-url-timeout`
55-
**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`
57+
> **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`
5658
5759
### `display-workflow-run-url-interval`
58-
**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`.
59-
**/!\ Do not use a value that is too small to avoid `API Rate limit exceeded`**
60+
> **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`.
61+
>
62+
> **/!\ Do not use a value that is too small to avoid `API Rate limit exceeded`**
63+
64+
### `workflow-logs`
65+
> **Optional.** Indicate what to do with logs of the triggered workflow:
66+
>
67+
> * `print`: Retrieve the logs for each job of the triggered workflow and print into the logs of the job that triggered the workflow.
68+
> * `ignore`: Do not retrieve log of triggered workflow at all (default).
69+
>
70+
> Only available when `wait-for-completion` is `true`.
71+
>
72+
> Default is `ignore`.
73+
6074

6175
## Outputs
6276
### `workflow-url`
63-
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`
77+
> 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`
6478
6579
### `workflow-conclusion`
66-
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.
67-
Only available if `wait-for-completion` is `true`
80+
> 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.
81+
> Only available if `wait-for-completion` is `true`
6882
6983

7084
## Example usage
@@ -115,3 +129,14 @@ Only available if `wait-for-completion` is `true`
115129
if: always()
116130
run: echo "Another Workflow conclusion: ${{ steps.trigger-step.outputs.workflow-conclusion }}"
117131
```
132+
133+
134+
## Contributions
135+
136+
Thanks to:
137+
138+
* [samirergaibi](https://github.com/samirergaibi)
139+
* [rui-ferreira](https://github.com/rui-ferreira)
140+
* [robbertvdg](https://github.com/robbertvdg)
141+
* [samit2040](https://github.com/samit2040)
142+
* [jonas-schievink](https://github.com/jonas-schievink)

action.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ inputs:
4444
description: 'Time to wait (+unit) between two polls to get run status'
4545
required: false
4646
default: 1m
47+
workflow-logs:
48+
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.'
49+
required: false
50+
default: ignore
4751

4852
runs:
4953
using: 'node16'

0 commit comments

Comments
 (0)