From 9a440b155669d8ec2e8818d79ae9cca89ab7b8c3 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Fri, 24 May 2024 22:44:51 +0800 Subject: [PATCH 1/3] feat: use the action itself in build/release workflows --- .github/workflows/build.yaml | 18 ++++++++++++++++++ .github/workflows/release.yaml | 24 +++--------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 085056c..8e99d48 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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}} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 444a5a0..d5fb754 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -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 "$GITHUB_ACTOR@users.noreply.github.com" - - 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 From d3a1b11453dd003b3b2fc111ddf1a6ca35d5c310 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Fri, 24 May 2024 22:45:25 +0800 Subject: [PATCH 2/3] chore: update docs in README with action usage --- README.md | 102 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 89 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 9a65db9..324125c 100644 --- a/README.md +++ b/README.md @@ -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 From ff1e5ea2b6d45de8c34e8a081f59b968771ea55f Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Fri, 24 May 2024 22:45:39 +0800 Subject: [PATCH 3/3] chore: minor formatting update in action.yaml --- action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yaml b/action.yaml index 72a484d..75bf5fe 100644 --- a/action.yaml +++ b/action.yaml @@ -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: