Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce changes output variable #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ You do this by checking if `changed` is equal to `1`.

The value will be 0 if no code has been changed by any previous steps.

You can print list of all changes by printing `changes` variable in the step.

## Example

```yaml
Expand All @@ -38,6 +40,8 @@ jobs:
- name: Process changes
if: steps.changes.outputs.changed == 1
run: echo "Changes exist"
# You can print list of changes if needed
# run: echo "Changes exist: " && echo "${{ steps.changes.outputs.changes }}"
```

The example shows that adding a step to check the status will expose the
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ inputs:
outputs:
changed:
description: "Whether or not there are uncommitted changes in the pathspec"
changes:
description: "Describes list of uncommitted changes in the pathspec"
runs:
using: "docker"
image: "Dockerfile"
Expand Down
23 changes: 18 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
#!/bin/bash
set -e

STATUS_ARGS=$1
PATHSPEC=$2

function check() {
if [[ -z "$(git status --porcelain $STATUS_ARGS $PATHSPEC)" ]];
set -e
output=$(git status --porcelain $STATUS_ARGS $PATHSPEC)
set +e

echo "$output"
if [[ -z "$output" ]];
then
echo "0"
return 0
else
echo "1"
return 1
fi
}

echo ::set-output name=changed::$(check)
changes=$(check)
changed=$?

# Escape result
changes="${changes//'%'/'%25'}"
changes="${changes//$'\n'/'%0A'}"
changes="${changes//$'\r'/'%0D'}"

echo ::set-output name=changed::$changed
echo ::set-output name=changes::$changes