Skip to content

Commit

Permalink
feat: implement v1 with cocogitto 2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Jul 17, 2021
1 parent 0e98881 commit 8e591de
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
coco
cog
LICENSE
cocogitto-*
cocogitto-*
.idea
92 changes: 92 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Cocogitto github action

This action uses [cocogitto](https://github.com/oknozor/cocogitto) to check
your repository is [conventional commit](https://conventionalcommits.org/) and perform auto-release.

## Requirement

1. Before running this action you need to call checkout action with `fetch-depth: 0`. This is mandatory, otherwise not all commit
will be fetched and cocogitto will fail to execute (see [actions/checkout](https://github.com/actions/checkout#checkout-v2) for more info).

2. Cocogitto assumes you are running on a x86 linux runner.

## Example

```yaml
on: [push]

jobs:
cog_check_job:
runs-on: ubuntu-latest
name: check conventional commit compliance
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Conventional commit check
uses: oknozor/cocogitto-action@v1
```
If you are familiar with cocogitto this will run `cog check` and nothing else.

## Check commits since latest tag

In some case you might want to perform check only since the latest tagged version.
If your repository has not alway been conventional commit compliant, then you probably want to
use this option.

```yaml
- name: Conventional commit check
uses: oknozor/cocogitto-action@v1
with:
check-latest-tag-only: true
```

Let us assume the following git history :

```
* 9b609bc - (HEAD -> main) WIP: feat unfinished work
* d832ca4 - feat: working on feature A
* d5ce110 - (tag: 0.1.0) chore: release 0.1.0
* 8f25a4b - chore: a commit before tag 0.1.0
```

Using `check-latest-tag-only: true` here would make cocogitto check for the two commits made since
tag `0.1.0`, the action would fail on *HEAD* which contains the non conventional commit
type 'WIP'.

## Performing release

You can also use this action to perform releases (calling `cog bump --auto` under the hood)
(see: [cocogitto's auto bump](https://github.com/oknozor/cocogitto#auto-bump)).

```yaml
- name: Semver release
uses: oknozor/cocogitto-action@v1
with:
release: true
git-user: 'Cog Bot'
git-user-email: '[email protected]'
```

Note that you probably want to set the `git-user` and `git-user-email` options to override the default the git signature for the release commit.
If you are not familiar with how cocogitto perform release, you might want to read the [auto bump](https://github.com/oknozor/cocogitto#auto-bump)
and [hook](https://github.com/oknozor/cocogitto#auto-bump) sections on cocogitto's documentation.

## Reference

Here are all the inputs available through `with`:

| Input | Description | Default |
| ------------------- | -------------------------------------------------------------------------- | ------- |
| `check` | Check conventional commit compliance with `cog check` | `true` |
| `check-latest-tag-only` | Check conventional commit compliance with `cog check --from-latest-tag` | `false` |
| `release` | Perform a release using `cog bump --auto` | `false` |
| `git-user` | Set the git `user.name` to use for the release commit | `cog-bot`|
| `git-user-email` | Set the git `user.email` to use for the release commit | `[email protected]`|





40 changes: 37 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
name: 'Cog check'
description: 'Check that your git log is conventional commit compliant'
name: 'Conventional commit cocogitto action'
description: 'Check conventional commits compliance and/or automatically release new version'
branding:
icon: 'git-commit'
color: 'red'
author: 'Paul Delafosse'

inputs:
release:
description: 'Perform a release with cog bump --auto'
required: false
default: 'false'
check:
description: 'Perform a conventional commit check with cog --check'
required: false
default: 'true'
check-latest-tag-only:
description: 'Check commit history from latest tag to HEAD'
required: false
default: 'false'
git-user:
description: 'Git user.name configuration'
required: false
default: 'cog-bot'
git-user-email:
description: 'Git user.email configuration'
required: false
default: '[email protected]'
runs:
using: "composite"
steps:
- run: echo Running cog check
- run: ${{ github.action_path }}/cog.sh
shell: sh

- run: |
${{ github.action_path }}/cog.sh \
${{ inputs.check }} \
${{ inputs.check-latest-tag-only }} \
${{ inputs.release }} \
${{ inputs.git-user }} \
${{ inputs.git-user-email }}
shell: sh
44 changes: 41 additions & 3 deletions cog.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,46 @@
#!/bin/sh

VERSION=2.0.0
set -a

VERSION=2.1.1
TAR="cocogitto-$VERSION-x86_64-unknown-linux-musl.tar.gz"
CHECK=$1
LATEST_TAG_ONLY=$2
RELEASE=$3
GIT_USER=$4
GIT_USER_EMAIL=$5
CUR_DIR=$(pwd)
BIN_DIR=/home/runner/work/bin


echo "Setting git user : $GIT_USER"
git config --global user.name "$GIT_USER"

echo "Settings git user email $GIT_USER_EMAIL"
git config --global user.email "$GIT_USER_EMAIL"

mkdir -p "$BIN_DIR"
cd "$BIN_DIR" || exit
curl -OL https://github.com/oknozor/cocogitto/releases/download/"$VERSION"/"$TAR"
tar xfvz $TAR
./cog check
tar xfz $TAR

cd "$CUR_DIR" || exit

if [ "$CHECK" = "true" ]; then
if [ "$LATEST_TAG_ONLY" = "true" ]; then
if [ "$(git describe --abbrev=0)" ]; then
message="Checking commits from $(git describe --abbrev=0)"
else
message="No tag found checking history from first commit"
fi
echo "$message"
"$BIN_DIR"/./cog check --from-latest-tag
else
echo "Checking all commits"
"$BIN_DIR"/./cog check
fi
fi

if [ "$RELEASE" = "true" ]; then
"$BIN_DIR"/./cog bump --auto
fi

0 comments on commit 8e591de

Please sign in to comment.