Skip to content

Commit

Permalink
Save the comment in an output variable.
Browse files Browse the repository at this point in the history
  - Save the comment, as a JSON document, in an output variable.
  • Loading branch information
nwalfield committed Aug 24, 2023
1 parent 114f79b commit f5d825e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
13 changes: 12 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
9 changes: 9 additions & 0 deletions src/fast-forward.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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<<EOF_$COMMENT_CONTENT"
cat "$COMMENT_CONTENT"
echo "EOF_$COMMENT_CONTENT"
} | tee -a "$GITHUB_OUTPUT"

# Post the comment.
if test $COMMENT -gt 0
then
COMMENTS_URL="$(github_pull_request .comments_url)"
Expand Down

0 comments on commit f5d825e

Please sign in to comment.