From f5d825ed63b29dcbcc60fa4914befb17f14be59b Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Thu, 24 Aug 2023 16:52:33 +0200 Subject: [PATCH] Save the comment in an output variable. - Save the comment, as a JSON document, in an output variable. --- README.md | 20 +++++++++++++++++++- action.yml | 13 ++++++++++++- src/fast-forward.sh | 9 +++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e7ea1cf..9c5d7b3 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,10 @@ the repository. ## Disabling Comments If you prefer to disable comments, you can set the `comment` input -variable to `false` like so: +variable to `false`. The `comment` is also written to the `comment` +output variable so it is possible to use it in a successive step. The +format is a JSON document with a single key, `body`. Here's an +example: ```yaml name: pull-request @@ -128,7 +131,22 @@ jobs: steps: - name: Checking if fast forwarding is possible + id: fast-forward uses: sequoia-pgp/fast-forward@main with: comment: false + - name: Display comment + env: + COMMENT: ${{ steps.fast-forward.outputs.comment }} + run: echo "The comment is... $COMMENT" ``` + +This would display something like: + +```text +The comment is... { + "body": "..." +} +``` + +Additional fields may be added to the JSON document in the future. diff --git a/action.yml b/action.yml index 1685a35..222f45c 100644 --- a/action.yml +++ b/action.yml @@ -35,10 +35,21 @@ inputs: may also execute some additional RPCs, and so should normally be disabled. default: 0 +outputs: + comment: + description: > + The comment. + + A comment explaining whether fast forwarding is possible, and, + if `merge` is true, whether it was successful. + + The comment is a JSON document with a single field, `body`. + value: ${{ steps.fast-forward.outputs.comment }} runs: using: "composite" steps: - - run: | + - id: fast-forward + run: | export GITHUB_TOKEN=${{ inputs.github_token }} export DEBUG=${{ inputs.debug }} export COMMENT=${{ inputs.comment }} diff --git a/src/fast-forward.sh b/src/fast-forward.sh index 58a99e5..2077ba4 100755 --- a/src/fast-forward.sh +++ b/src/fast-forward.sh @@ -305,6 +305,15 @@ LOG=$(mktemp) COMMENT_CONTENT=$(mktemp) jq -n --rawfile log "$LOG" '{ "body": $log }' >"$COMMENT_CONTENT" +# Set the comment output variable. +{ + # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings + echo "comment<