diff --git a/.github/workflows/ci-rel.yaml b/.github/workflows/ci-rel.yaml new file mode 100644 index 0000000..2a83a98 --- /dev/null +++ b/.github/workflows/ci-rel.yaml @@ -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 'mona.lisa@example.com' + 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 'mona.lisa@example.com' + 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 'mona.lisa@example.com' + 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 diff --git a/README.md b/README.md index 774c989..b6c06ed 100644 --- a/README.md +++ b/README.md @@ -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: 'mycoolproject@org.org' - # 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. @@ -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 | `cog@demo.org`| +| `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 eda8275..7479c08 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/cog.sh b/cog.sh index add915f..f5650f7 100755 --- a/cog.sh +++ b/cog.sh @@ -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 @@ -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