Skip to content

Commit

Permalink
Merge in set-output fixes from the head repo (#2)
Browse files Browse the repository at this point in the history
* Update to node16 (the-actions-org#7)

* Update to Node 16 to address GH warnings

* Update to node 16 on build

* Update dependency actions to Node 16 support

* Update to deps using Node 16

* bugfix: remove ms precision from `triggerDate` (the-actions-org#8)

* bugfix: remove ms precision from `triggerDate`

remove ms precision from `triggerDate` as was the meaning of this previous bug fix the-actions-org#4

* remove redundant Date.now

* Provide run name optional parameter to fetch run id based on name (the-actions-org#6)

* use check listforref to obtain run id

* proper param for run name

* Automated publish: Thu Jun  8 06:14:15 UTC 2023 d0f84d4

* chore(pr): Some adjustments after merge of PRs

* Automated publish: Thu Jun  8 07:01:06 UTC 2023 928e175

* feat(logs): Retrieve and print logs of triggered workflow

Upgrade all dependencies

* chore(logs): Prefix imported logs

* Automated publish: Fri Jun  9 06:55:17 UTC 2023 46e0c62

---------

Co-authored-by: Rui Ferreira <rui-ferreira@users.noreply.github.com>
Co-authored-by: Samir Ergaibi <38135462+samirergaibi@users.noreply.github.com>
Co-authored-by: Robbert van der Gugten <robbertvdg@gmail.com>
Co-authored-by: Automated Publisher <actions@users.noreply.github.com>
Co-authored-by: Aurélien Baudet <Aurelien.baudet@gmail.com>
  • Loading branch information
6 people authored Jun 9, 2023
1 parent 383ae01 commit 8522ca9
Show file tree
Hide file tree
Showing 13 changed files with 7,940 additions and 3,014 deletions.
40 changes: 39 additions & 1 deletion .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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,7 +204,13 @@ 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
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 @@ For details of the `workflow_dispatch` even see [this blog post introducing this

## 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)
7 changes: 7 additions & 0 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,6 +44,10 @@ 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: 'node16'
Expand Down
Loading

0 comments on commit 8522ca9

Please sign in to comment.