Skip to content

Commit

Permalink
Initial version of the orb
Browse files Browse the repository at this point in the history
- Added the orb file.
  • Loading branch information
Surya Teja authored Oct 17, 2019
1 parent 35c8056 commit b4d81d3
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 2 deletions.
37 changes: 37 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: 2.1

executors:
cli:
docker:
- image: circleci/circleci-cli:0.1.2709

jobs:
validate:
executor: cli
steps:
- checkout
- run:
name: Validate orb
command:
make validate

dev-release:
executor: cli
steps:
- checkout
- run:
name: Publish dev version of the orb
command: |
make dev-release
workflows:
main:
jobs:
- validate

# CircleCI personal tokens are visible in the logs. Hence not publishing automatically until it is resolved (https://ideas.circleci.com/ideas/CCI-I-397).

# - dev-release:
# requires:
# - validate

13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.PHONY: validate
validate:
circleci orb validate src/orb.yml

.PHONY: dev-release
dev-release:
@$(MAKE) validate
circleci orb publish src/orb.yml niteo/check-untracked-changes@dev:${tag}

.PHONY: prod-release
prod-release:
@$(MAKE) validate
circleci orb publish src/orb.yml niteo/check-untracked-changes@${tag}
69 changes: 67 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,67 @@
# check-untracked-changes
TODO
# Check Un-tracked Changes Orb
[![CircleCI](https://circleci.com/gh/niteoweb/check-untracked-changes/tree/master.svg?style=svg&circle-token=2a9cb57945337d7999f3f325ffdd0569795157bf)](https://circleci.com/gh/niteoweb/check-untracked-changes/tree/master)

An orb to test if any un-tracked changes(to git commit) are present in the given path.
This is useful to test if any auto-formatters(like black, codegen) have produced changes during CI validation.


## Example Usage
```yml
version: 2.1

orbs:
untracked_changes: niteo/[email protected]
jobs:
test:
docker:
- image: circleci/python:3.7 # Can be any executor
steps:
- checkout

# Run auto-formatter commands
- run: pip install black
- run: black src/

# Fail if changes are produced
- untracked_changes/check:
path: "src/"

workflows:
test-format:
jobs:
- test
```
## Development
* To see all the existing orbs in the organization, run:
```bash
$ circleci orb list niteo
```

* To validate the orb, run:
```bash
$ make validate
```

* You can publish a **dev** version of the orb for testing before publishing a production immutable version. To publish a dev version of 1.0.1, run:
```bash
$ make dev-release tag=1.0.1
```

> Note: It is always a good practice to test a dev version of the orb first before publishing new public version.

## Publishing Orb

* Make sure you have privileges to publish the orb to production.
* Once the dev version is tested, You can publish a new orb version manually, by specifying new version:
```bash
$ make prod-release tag=1.0.1
```
> Note: Once the new version of orb is published, the same can be tagged in the Github releases.

## Additional Information
Authoring orb: https://circleci.com/docs/2.0/orb-author/
58 changes: 58 additions & 0 deletions src/orb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: 2.1
description: >-
An orb command to test if any un-tracked changes(to git commit) are present in the given path.
This is useful to check if any auto-formatters(like black, codegen) have produced changes during CI validation.
############################################
# ---- Commands ---- #
# Command to check the un-tracked changes. #
############################################
commands:
check:
description: Check un-tracked changes in the given path
parameters:
path:
description: Path to check
type: string
default: "."
steps:
- run:
name: Check un-tracked changes using git porcelain command
command: |
if [[ `git status <<parameters.path>> --porcelain` ]]
then
echo "ERROR: running the previous command has introduced changes. Hence, Failing the build."
git status --porcelain
exit 1
fi
######################################
# ---- Examples & Usage ---- #
######################################

examples:
format_test:
description: Test if the files are formatted
usage:
version: 2.1
orbs:
untracked_changes: niteo/[email protected]
jobs:
test:
docker:
- image: circleci/python:3.7 # Can be any executor
steps:
- checkout

# Run auto formatter commands

# Fail if changes are produced
- untracked_changes/check:
path: "src/"

workflows:
test-format:
jobs:
- test

0 comments on commit b4d81d3

Please sign in to comment.