diff --git a/.gitignore b/.gitignore index d3214e3..8a010cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ coco cog LICENSE -cocogitto-* \ No newline at end of file +cocogitto-* +.idea \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f6d8285 --- /dev/null +++ b/README.md @@ -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: 'mycoolproject@org.org' +``` + +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 | `cog@demo.org`| + + + + + diff --git a/action.yml b/action.yml index 57ff58a..b23e501 100644 --- a/action.yml +++ b/action.yml @@ -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: 'cog@demo.org' 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 diff --git a/cog.sh b/cog.sh index dd93cb0..89bb5d4 100755 --- a/cog.sh +++ b/cog.sh @@ -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 \ No newline at end of file