Skip to content

Commit

Permalink
Merge pull request #148 from smlx/dogfood
Browse files Browse the repository at this point in the history
dogfood
  • Loading branch information
smlx authored May 24, 2024
2 parents c5f6769 + ff1e5ea commit bbf6b0f
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 35 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,21 @@ jobs:
with:
version: latest
args: build --clean --debug --single-target --snapshot
check-tag:
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
fetch-depth: 0
- id: ccv
uses: smlx/ccv@c5f6769c943c082c4e8d8ccf2ec4b6f5f517e1f2 # v0.7.3
with:
write-tag: false
- run: |
echo "new-tag=$NEW_TAG"
echo "new-tag-version=$NEW_TAG_VERSION"
env:
NEW_TAG: ${{steps.ccv.outputs.new-tag}}
NEW_TAG_VERSION: ${{steps.ccv.outputs.new-tag-version}}
24 changes: 3 additions & 21 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,14 @@ jobs:
contents: write
runs-on: ubuntu-latest
outputs:
new-tag: ${{ steps.bump-tag.outputs.new }}
new-tag-version: ${{ steps.bump-tag.outputs.new_tag_version }}
new-tag: ${{ steps.ccv.outputs.new-tag }}
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
with:
fetch-depth: 0
- name: Configure git
run: |
git config --global user.name "$GITHUB_ACTOR"
git config --global user.email "[email protected]"
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: stable
- name: Install ccv
run: >
curl -sSL https://github.com/smlx/ccv/releases/download/v0.3.2/ccv_0.3.2_linux_amd64.tar.gz
| sudo tar -xz -C /usr/local/bin ccv
- name: Bump tag if necessary
id: bump-tag
run: |
if [ -z "$(git tag -l "$(ccv)")" ]; then
git tag "$(ccv)"
git push --tags
echo "new=true" >> "$GITHUB_OUTPUT"
echo "new_tag_version=$(git tag --points-at HEAD)" >> "$GITHUB_OUTPUT"
fi
id: ccv
uses: smlx/ccv@c5f6769c943c082c4e8d8ccf2ec4b6f5f517e1f2 # v0.7.3
release-build:
permissions:
# create release
Expand Down
102 changes: 89 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,106 @@ When it reaches the most recent tag, it uses the commit messages it saw to figur

The ideas behind `ccv` are described by [Conventional Commits](https://www.conventionalcommits.org/) and [Semantic Versioning](https://semver.org/). Currently parts 1 to 3 of the Conventional Commits specification summary are recognized when incrementing versions.

## Get it
## Use as a Github Action

Download the latest [release](https://github.com/smlx/ccv/releases) on github, or:
This repository is also a [Github Action](https://docs.github.com/en/actions).

```
go install github.com/smlx/ccv/cmd/ccv@latest
Inputs:

* `write-tag`: If true, and ccv determines that a new version is required, the action will automatically write the new version tag to the repository. Default `true`.

Outputs:

* `new-tag`: Either "true" or "false" depending on whether a new tag was pushed. Example: `true`.
* `new-tag-version`: The new version that was tagged. This will only be set if new_tag=true. Example: `v0.1.2`.

### Example: automatic tagging

The main use-case of this action is to automatically tag and build new releases in a fully automated release workflow.

```yaml
name: release
on:
push:
branches:
- main
permissions: {}
jobs:
release-tag:
permissions:
# create tag
contents: write
runs-on: ubuntu-latest
outputs:
new-tag: ${{ steps.ccv.outputs.new-tag }}
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
fetch-depth: 0
- name: Bump tag if necessary
id: ccv
uses: smlx/ccv@c5f6769c943c082c4e8d8ccf2ec4b6f5f517e1f2 # v0.7.3
release-build:
permissions:
# create release
contents: write
# push docker images to registry
packages: write
needs: release-tag
if: needs.release-tag.outputs.new-tag == 'true'
runs-on: ubuntu-latest
steps:
# ... build and release steps here
```

## Use it
### Example: read-only

For a full example, see the [`tag-release` workflow](https://github.com/smlx/ccv/blob/main/.github/workflows/tag-release.yaml) in this repository.
You can also check the tag your PR will generate by running with `write-tag: false`. Note that the permissions on this job are read-only.

Simple example:
```yaml
name: build
on:
pull_request:
branches:
- main
permissions: {}
jobs:
check-tag:
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
fetch-depth: 0
- id: ccv
uses: smlx/ccv@c5f6769c943c082c4e8d8ccf2ec4b6f5f517e1f2 # v0.7.3
with:
write-tag: false
- run: |
echo "new-tag=$NEW_TAG"
echo "new-tag-version=$NEW_TAG_VERSION"
env:
NEW_TAG: ${{steps.ccv.outputs.new-tag}}
NEW_TAG_VERSION: ${{steps.ccv.outputs.new-tag-version}}
```
Gives this output:
```
# add an incremented tag if necessary
if [ -z $(git tag -l $(ccv)) ]; then
git tag $(ccv)
fi
new-tag=true
new-tag-version=v0.16.0
```

`ccv` takes no arguments or options\*.
## Use locally

Download the latest [release](https://github.com/smlx/ccv/releases) on github, or:

```
go install github.com/smlx/ccv/cmd/ccv@latest
```

\* Yet!
Run `ccv` in the directory containing your git repository.

## Prior art

Expand Down
2 changes: 1 addition & 1 deletion action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Conventional Commits Versioner Action
description: Automatically tag a new version based on the commit messages of commits since the last tag.
inputs:
write-tag:
description: 'If true, and ccv determines that a new version is required, the action will automatically write the new version tag to the repository.'
description: If true, and ccv determines that a new version is required, the action will automatically write the new version tag to the repository.
required: false
default: 'true'
outputs:
Expand Down

0 comments on commit bbf6b0f

Please sign in to comment.