Skip to content

Commit

Permalink
feat(release): bumped indicator
Browse files Browse the repository at this point in the history
* action outputs expose boolean flag indicating if bump happenend
* added tests and improved assertions

Signed-off-by: Ievgenii Shepeliuk <[email protected]>
  • Loading branch information
eshepelyuk committed Jun 26, 2024
1 parent 5ae1660 commit ab04659
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 15 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/ci-rel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: CI cog release

on:
workflow_dispatch: {}
push: {}

jobs:
no-bump-has-prev:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
path: cocogitto-action
- name: Initialise repository
run: |
git init
git config --global user.name 'Mona Lisa'
git config --global user.email '[email protected]'
git commit --allow-empty -m 'feat: initial'
git tag '0.1.0'
echo 'cocogitto-action/' > .gitignore
echo '# Mona Lisa' > README.md
git add README.md .gitignore
git commit -m 'chore: add Mona Lisa docs'
- name: Run cocogitto-action
id: release
uses: ./cocogitto-action
with:
check: true
release: true
- name: Check outputs
run: |
[ "${{ steps.release.outputs.version }}" == '0.1.0' ] || exit 1
[ -z "${{ steps.release.outputs.bumped }}" ] || exit 1
no-bump-no-prev:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
path: cocogitto-action
- name: Initialise repository
run: |
git init
git config --global user.name 'Mona Lisa'
git config --global user.email '[email protected]'
echo 'cocogitto-action/' > .gitignore
echo '# Mona Lisa' > README.md
git add README.md .gitignore
git commit -m 'chore: add Mona Lisa docs'
- name: Run cocogitto-action
id: release
uses: ./cocogitto-action
with:
check: true
release: true
- name: Check outputs
run: |
[ -z "${{ steps.release.outputs.version }}" ] || exit 1
[ -z "${{ steps.release.outputs.bumped }}" ] || exit 1
bump-no-prev:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
path: cocogitto-action
- name: Initialise repository
run: |
git init
git config --global user.name 'Mona Lisa'
git config --global user.email '[email protected]'
echo 'cocogitto-action/' > .gitignore
echo '# Mona Lisa' > README.md
git add README.md .gitignore
git commit -m 'feat: add Mona Lisa docs'
- name: Run cocogitto-action
id: release
uses: ./cocogitto-action
with:
check: true
release: true
- name: Check outputs
run: |
[ "${{ steps.release.outputs.version }}" == '0.1.0' ] || exit 1
[ "${{ steps.release.outputs.bumped }}" == 'true' ] || exit 1
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,13 @@ You can also use this action to perform releases (calling `cog bump --auto` unde
git-user: 'Cog Bot'
git-user-email: '[email protected]'
# The version number is accessible as a github action output
- name: Print version
run: "echo '${{ steps.release.outputs.version }}'"
# The version number is accessible as the action output.
# Also the action output contains flag,
# indicating if version was bumped or not.
- name: Print version if changed
if: ${{ steps.release.outputs.bumped }}
run: |
echo "new version: ${{ steps.release.outputs.version }}"
```

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.
Expand All @@ -110,8 +114,8 @@ 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]`|
| `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]`|
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ inputs:

outputs:
version:
description: Version released
description: Released version or previous version if not bumped.
value: ${{ steps.cog.outputs.version }}
bumped:
description: Indicates if the version was bumped.
value: ${{ steps.cog.outputs.bumped }}

runs:
using: composite
Expand Down
19 changes: 13 additions & 6 deletions cog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ git config --global user.email "${GIT_USER_EMAIL}"

cog --version

if [ "${CHECK}" = "true" ]; then
CURRENT_VERSION=$(cog get-version 2>/dev/null || echo '')

if [ "${CHECK}" = 'true' ]; then
if [ "${LATEST_TAG_ONLY}" = "true" ]; then
if [ "$(git describe --tags --abbrev=0)" ]; then
message="Checking commits from $(git describe --tags --abbrev=0)"
if [ -n "${CURRENT_VERSION}" ]; then
message="Checking commits from ${CURRENT_VERSION}"
else
message="No tag found checking history from first commit"
fi
Expand All @@ -32,10 +34,15 @@ if [ "${CHECK}" = "true" ]; then
fi
fi

if [ "${RELEASE}" = "true" ]; then
if [ "${RELEASE}" = 'true' ]; then
cog bump --auto || exit 1
VERSION="$(git describe --tags "$(git rev-list --tags --max-count=1)")"
echo "version=$VERSION" >> $GITHUB_OUTPUT
NEXT_VERSION=$(cog get-version 2>/dev/null || echo '')
# shellcheck disable=2086
echo "version=${NEXT_VERSION}" >> $GITHUB_OUTPUT
if [ -n "${NEXT_VERSION}" ] && [ "${CURRENT_VERSION}" != "${NEXT_VERSION}" ]; then
# shellcheck disable=2086
echo 'bumped=true' >> $GITHUB_OUTPUT
fi
fi

if ( echo "${VERIFY}" | grep -Eiv '^([01]|(true)|(false))$' > /dev/null ) ; then
Expand Down

0 comments on commit ab04659

Please sign in to comment.