From 1a49f5222b897b84a75ed804ba813a541588c1d5 Mon Sep 17 00:00:00 2001 From: Chris Gruel Date: Tue, 8 Jun 2021 09:14:00 -0400 Subject: [PATCH] outputs support in the action --- README.md | 25 +++++++++++++++++++++++++ action.yml | 8 ++++++-- github-action/entrypoint.sh | 6 ++++-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 57ca864d..36fa319b 100644 --- a/README.md +++ b/README.md @@ -209,3 +209,28 @@ yq e '.a.b | length' f1.yml f2.yml ## Known Issues / Missing Features - `yq` attempts to preserve comment positions and whitespace as much as possible, but it does not handle all scenarios (see https://github.com/go-yaml/yaml/tree/v3 for details) + +## GitHub Action + +If we want to use the yq action to look up a value from within a YAML file inside the repo, we can do this: + +```yml + - uses: actions/checkout@v2 + - name: Get SDK Version from config + id: lookupSdkVersion + uses: mikefarah/yq@master + with: + cmd: yq eval '.renutil.version' 'config.yml' + - name: Restore Cache + id: restore-cache + uses: actions/cache@v2 + with: + path: ../renpy + key: ${{ runner.os }}-sdk-${{ steps.lookupSdkVersion.outputs.result }} + restore-keys: | + ${{ runner.os }}-sdk + # ... more +``` +You can even lookup how the GitHub action [itself is configured](https://github.com/mikefarah/yq/issues/844#issuecomment-856700574) + +If you [enable step debug logging](https://docs.github.com/en/actions/managing-workflow-runs/enabling-debug-logging#enabling-step-debug-logging), you can see additional information about the exact command sent as well as the response returned within the GitHub Action logs. diff --git a/action.yml b/action.yml index e8de93f7..e6beb159 100644 --- a/action.yml +++ b/action.yml @@ -1,11 +1,15 @@ name: 'yq - portable yaml processor' description: 'create, read, update, delete, merge, validate and do more with yaml' -icon: command -color: gray-dark +branding: + icon: command + color: gray-dark inputs: cmd: description: 'The Command which should be run' required: true +outputs: + result: + description: "The complete result from the yq command being run" runs: using: 'docker' image: 'github-action/Dockerfile' diff --git a/github-action/entrypoint.sh b/github-action/entrypoint.sh index af5e6ab8..ec6e6b62 100755 --- a/github-action/entrypoint.sh +++ b/github-action/entrypoint.sh @@ -1,4 +1,6 @@ #!/bin/sh -l -echo "$1" -eval $1 +echo "::debug::\$cmd: $1" +RESULT=$(eval "$1") +echo "::debug::\$RESULT: $RESULT" +echo ::set-output name=result::"$RESULT"