Skip to content
This repository has been archived by the owner on Sep 24, 2022. It is now read-only.

Commit

Permalink
Change to checking failure in example and print changes as output
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakari Mursu committed Sep 30, 2020
1 parent bf0dbf2 commit 5858f1c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ jobs:
id: check-changes
uses: ./
- name: Evaluate if there are changes
if: steps.check-changes.outputs.changes == 1
if: steps.check-changes.outputs.outcome == failure()
run: echo "There are uncommitted changes"
18 changes: 18 additions & 0 deletions .github/workflows/print-changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on: [push]

name: Check uncommitted changes and print them out
jobs:
check-uncommitted-changes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Make uncommitted changes by creating empty file
run: touch uncommitted.tmp
- name: Check for uncommitted changes
id: check-changes
uses: ./
- name: Print uncommitted changes
if: steps.check-changes.outputs.changes != ''
run: echo ${{ steps.check-changes.outputs.changes }}
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ A GitHub action for checking if repository has uncommitted changes.

### `changes`

Value indicating if there are uncommitted changes in the repository. If `changed` is equal to `1`
there are uncommitted changes. No changes will return `0`.
Changes outputted by `git status --porcelain`.

### Example usage

Expand All @@ -26,7 +25,26 @@ jobs:
id: check-changes
uses: mskri/[email protected]
- name: Evaluate if there are changes
if: steps.check-changes.outputs.changes == 1
if: steps.check-changes.outputs.outcome == failure()
run: echo "There are uncommitted changes"
```
```yaml
name: Check uncommitted changes and print them out
jobs:
check-uncommitted-changes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Make uncommitted changes by creating empty file
run: touch uncommitted.tmp
- name: Check for uncommitted changes
id: check-changes
uses: mskri/[email protected]
- name: Print uncommitted changes
if: steps.check-changes.outputs.changes != ''
run: echo "There are uncommitted changes"
```
Expand Down
8 changes: 4 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: "Check uncommitted changes"
description: "Checks if a git repository has uncommitted changes"
branding:
icon: "alert-circle"
color: "yellow"
outputs:
changes:
description: "Value indicating if there are uncommitted changes in the repository"
description: "Uncommitted changes if any"
runs:
using: "docker"
image: "Dockerfile"
branding:
icon: "alert-circle"
color: "yellow"
12 changes: 9 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
set -e

function check_uncommitted_changes() {
if [ -n "$(git status --porcelain)" ]; then
echo "1"
status=$(git status --porcelain)
if [ -n "$status" ]; then
status="${status//'%'/'%25'}"
status="${status//$'\n'/'%0A'}"
status="${status//$'\r'/'%0D'}"
echo "$status"
exit 1
else
echo "0"
echo ""
exit 0
fi
}

Expand Down

0 comments on commit 5858f1c

Please sign in to comment.