Skip to content

Commit

Permalink
GitHub Action to display Git changes and fail a build
Browse files Browse the repository at this point in the history
  • Loading branch information
multani committed Jan 4, 2022
1 parent 4df272d commit 0021777
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Jonathan Ballet

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Git changes action

This GitHub Action:

* Show pending changes in a Git repository: uncommited files and pending
modifications.

![untracked files](/doc/status.png)

* Fail the step if there are any pending changes.

![modified files](/doc/diff.png)

This can be used to verify that the content of a Git repository didn't change
after a set of steps.

To use this GitHub Action:

```yaml
- name: Check Git changes
uses: camunda-cloud/git-changes-action@v1
```
14 changes: 14 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Git changes verifier
description: |
Display changes from Git and fail the build if there are any changes pending.
branding:
icon: alert-triangle
color: red

runs:
using: composite
steps:
- shell: bash
name: Find changes
run: ${{ github.action_path }}/git-changes.sh
Binary file added doc/diff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/status.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions git-changes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -euo pipefail

output="$(git -c color.status=always status --short)"

if [ -n "$output" ]; then
echo "== git status =="
echo -e "$output"
echo "================"
fi

git diff --color=always --exit-code

if [ -n "$output" ]; then
echo
echo -e "\e[31;1mThere are pending changes!\e[0m"
exit 1
fi

0 comments on commit 0021777

Please sign in to comment.