From d4251d8891d17d54274d99f7bda839efa1d67232 Mon Sep 17 00:00:00 2001 From: "Chase, Justin M" Date: Thu, 19 Jun 2025 09:45:14 -0500 Subject: [PATCH 1/5] Add action to top level of repo --- .github/version.yml | 3 ++ .github/workflows/publish.yml | 7 ++-- Dockerfile | 11 ++++++ Dockerfile.action | 1 + action.yml | 63 +++++++++++++++++++++++++++++++++++ 5 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 Dockerfile.action create mode 100644 action.yml diff --git a/.github/version.yml b/.github/version.yml index 7e1a3d7..082312b 100644 --- a/.github/version.yml +++ b/.github/version.yml @@ -12,3 +12,6 @@ on: - kind: regexp file: setup/action.yml pattern: "(?<=default: ).*" + - kind: regexp + file: Dockerfile.action + pattern: "(?<=semver-cli:).*" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f055c26..dfcbdec 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,6 +13,8 @@ jobs: runs-on: ubuntu-latest outputs: version: ${{ steps.parse_version.outputs.version }} + major: ${{ steps.parse_version.outputs.major }} + minor: ${{ steps.parse_version.outputs.minor }} steps: - uses: actions/checkout@v4 - uses: denoland/setup-deno@v2 @@ -22,8 +24,10 @@ jobs: - id: parse_version name: Parse the Version run: deno run -A main.ts parse + assets: runs-on: ubuntu-latest + needs: version permissions: contents: write strategy: @@ -37,7 +41,6 @@ jobs: extension: "" - name: "aarch64-apple-darwin" extension: "" - needs: version steps: - uses: actions/checkout@v4 - uses: denoland/setup-deno@v2 @@ -115,5 +118,5 @@ jobs: uses: docker/build-push-action@v4 with: push: true - tags: optum/semver-cli:${{ needs.version.outputs.version }} + tags: latest,optum/semver-cli:${{ needs.version.outputs.version }},optum/semver-cli:v${{ needs.version.outputs.major }}.${{ needs.version.outputs.minor }},optum/semver-cli:v${{ needs.version.outputs.major }} platforms: linux/amd64 diff --git a/Dockerfile b/Dockerfile index 117f407..268d509 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,17 @@ LABEL maintainer="Justin Chase " LABEL repository="https://github.com/optum/semver-cli" LABEL homepage="https://github.com/optum/semver-cli" +# Label as GitHub action +LABEL com.github.actions.name="semver-cli" + +# Limit to 160 characters +LABEL com.github.actions.description="Get, set and increment your project version" + +# See branding: +# https://docs.github.com/actions/creating-actions/metadata-syntax-for-github-actions#branding +LABEL com.github.actions.icon="activity" +LABEL com.github.actions.color="orange" + WORKDIR /app ENV PATH="/app/bin:${PATH}" RUN mkdir -p /app/bin diff --git a/Dockerfile.action b/Dockerfile.action new file mode 100644 index 0000000..a0fe2ca --- /dev/null +++ b/Dockerfile.action @@ -0,0 +1 @@ +FROM optum/semver-cli:0.9.20 diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..fc55af3 --- /dev/null +++ b/action.yml @@ -0,0 +1,63 @@ +name: 'semver-cli' +description: 'Semver utility action' +branding: + icon: activity + color: orange +inputs: + action: + description: 'A versioning action to perform (get|set|inc|parse)' + required: false + command: + type: choice + description: 'The kind of increment (major|minor|patch|none) for (get|inc) actions' + required: false + options: + - none + - major + - minor + - patch + pre: + type: boolean + description: 'Whether or not to create a pre-release version (inc|get)' + name: + description: 'If pre is set, you may optionally specify a prerelease name' + required: false + value: + description: 'If pre is set, you may optionally specify a prerelease number' + build: + description: 'Optional build metadata' + required: false + current: + description: 'The version for the set command' + +outputs: + version: + description: 'The resulting version change' + version_docker: + description: 'The resulting version change formatted to be compatible with docker tags' + version_dotnet: + description: 'The resulting version change formatted to be compatible with dotnet' + major: + description: 'If parsing, the major version' + minor: + description: 'If parsing, the minor version' + patch: + description: 'If parsing, the patch version' + prerelease: + description: 'If parsing, the prerelease version' + build: + description: 'If parsing, the build version' +runs: + using: 'docker' + image: 'Dockerfile.action' + args: + - ${{ inputs.action || 'get' }} + - ${{ inputs.command }} + - ${{ inputs.pre && '--pre' || ''}} + - ${{ inputs.name && '--name' || '' }} + - ${{ inputs.name || '' }} + - ${{ inputs.value && '--value' || '' }} + - ${{ inputs.value || '' }} + - ${{ inputs.build && '--build' || '' }} + - ${{ inputs.build || '' }} + - ${{ inputs.current }} From aa369f23550734f5ed5f360ddb3238e25dc49040 Mon Sep 17 00:00:00 2001 From: "Chase, Justin M" Date: Thu, 19 Jun 2025 09:53:56 -0500 Subject: [PATCH 2/5] add readme --- .github/version.yml | 6 ++++ README.md | 68 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/.github/version.yml b/.github/version.yml index 082312b..e3c4cac 100644 --- a/.github/version.yml +++ b/.github/version.yml @@ -6,12 +6,18 @@ on: - kind: regexp file: README.md pattern: '(?<=semver-cli@).*(?=\/main.ts)' + - kind: regexp + file: README.md + pattern: '(?<=semver-cli@).*$' - kind: regexp file: Dockerfile pattern: '(?<=VERSION=).*(?=; \\)' - kind: regexp file: setup/action.yml pattern: "(?<=default: ).*" + - kind: regexp + file: action.yml + pattern: "(?<=default: ).*" - kind: regexp file: Dockerfile.action pattern: "(?<=semver-cli:).*" diff --git a/README.md b/README.md index 68041cd..9659cd1 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,74 @@ on: pattern: '^(?<=export const version = ").*(?=";)$' ``` +## Actions + +This repository has two actions available, either a basic setup action or a single docker based action. + +#### example + +```yml +name: Publish +on: + workflow_dispatch: + inputs: + pre: + type: boolean + default: true + release: + types: [published] + +jobs: + publish: + steps: + - if: inputs.pre + name: Increment Pre-Release Version + uses: optum/semver-cli@0.9.20 + with: + action: inc + pre: true + name: pr + value: ${{ github.run_number }} + build: ${{ github.run_id }} + + - id: version + name: Get Version + uses: optum/semver-cli@0.9.20 + + - run: echo "The calculated ${{ steps.version.outputs.version }}" +``` + +#### example of setup action + +```yml +name: Publish +on: + workflow_dispatch: + inputs: + pre: + type: boolean + default: true + release: + types: [published] + +jobs: + publish: + steps: + - if: inputs.pre + name: Increment Pre-Release Version + uses: optum/semver-cli/setup@0.9.20 + + - id: version + name: Parse Version + run: | + echo "version=$(semver parse | jq -r '.version')" > $GITHUB_OUTPUT + echo "major=$(semver parse | jq -r '.major')" > $GITHUB_OUTPUT + echo "minor=$(semver parse | jq -r '.minor')" > $GITHUB_OUTPUT + echo "patch=$(semver parse | jq -r '.patch')" > $GITHUB_OUTPUT + + - run: echo "The calculated ${{ steps.version.outputs.version }}" +``` + # Contributing Contributions are what make the open source community such an amazing place to From 301f5ac30b969740a6760705692f10464bdf5f0d Mon Sep 17 00:00:00 2001 From: "Chase, Justin M" Date: Thu, 19 Jun 2025 10:01:40 -0500 Subject: [PATCH 3/5] fmt --- .github/version.yml | 2 +- README.md | 59 ++++++++++++++++++++-------------------- action.yml | 66 ++++++++++++++++++++++----------------------- 3 files changed, 64 insertions(+), 63 deletions(-) diff --git a/.github/version.yml b/.github/version.yml index e3c4cac..56faa73 100644 --- a/.github/version.yml +++ b/.github/version.yml @@ -8,7 +8,7 @@ on: pattern: '(?<=semver-cli@).*(?=\/main.ts)' - kind: regexp file: README.md - pattern: '(?<=semver-cli@).*$' + pattern: "(?<=semver-cli@).*$" - kind: regexp file: Dockerfile pattern: '(?<=VERSION=).*(?=; \\)' diff --git a/README.md b/README.md index 9659cd1..bbe8cbf 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,8 @@ on: ## Actions -This repository has two actions available, either a basic setup action or a single docker based action. +This repository has two actions available, either a basic setup action or a +single docker based action. #### example @@ -194,21 +195,21 @@ on: jobs: publish: steps: - - if: inputs.pre - name: Increment Pre-Release Version - uses: optum/semver-cli@0.9.20 - with: - action: inc - pre: true - name: pr - value: ${{ github.run_number }} - build: ${{ github.run_id }} - - - id: version - name: Get Version - uses: optum/semver-cli@0.9.20 - - - run: echo "The calculated ${{ steps.version.outputs.version }}" + - if: inputs.pre + name: Increment Pre-Release Version + uses: optum/semver-cli@0.9.20 + with: + action: inc + pre: true + name: pr + value: ${{ github.run_number }} + build: ${{ github.run_id }} + + - id: version + name: Get Version + uses: optum/semver-cli@0.9.20 + + - run: echo "The calculated ${{ steps.version.outputs.version }}" ``` #### example of setup action @@ -227,19 +228,19 @@ on: jobs: publish: steps: - - if: inputs.pre - name: Increment Pre-Release Version - uses: optum/semver-cli/setup@0.9.20 - - - id: version - name: Parse Version - run: | - echo "version=$(semver parse | jq -r '.version')" > $GITHUB_OUTPUT - echo "major=$(semver parse | jq -r '.major')" > $GITHUB_OUTPUT - echo "minor=$(semver parse | jq -r '.minor')" > $GITHUB_OUTPUT - echo "patch=$(semver parse | jq -r '.patch')" > $GITHUB_OUTPUT - - - run: echo "The calculated ${{ steps.version.outputs.version }}" + - if: inputs.pre + name: Increment Pre-Release Version + uses: optum/semver-cli/setup@0.9.20 + + - id: version + name: Parse Version + run: | + echo "version=$(semver parse | jq -r '.version')" > $GITHUB_OUTPUT + echo "major=$(semver parse | jq -r '.major')" > $GITHUB_OUTPUT + echo "minor=$(semver parse | jq -r '.minor')" > $GITHUB_OUTPUT + echo "patch=$(semver parse | jq -r '.patch')" > $GITHUB_OUTPUT + + - run: echo "The calculated ${{ steps.version.outputs.version }}" ``` # Contributing diff --git a/action.yml b/action.yml index fc55af3..9940438 100644 --- a/action.yml +++ b/action.yml @@ -1,63 +1,63 @@ -name: 'semver-cli' -description: 'Semver utility action' +name: "semver-cli" +description: "Semver utility action" branding: icon: activity color: orange inputs: action: - description: 'A versioning action to perform (get|set|inc|parse)' + description: "A versioning action to perform (get|set|inc|parse)" required: false command: type: choice - description: 'The kind of increment (major|minor|patch|none) for (get|inc) actions' + description: "The kind of increment (major|minor|patch|none) for (get|inc) actions" required: false options: - - none - - major - - minor - - patch + - none + - major + - minor + - patch pre: type: boolean - description: 'Whether or not to create a pre-release version (inc|get)' + description: "Whether or not to create a pre-release version (inc|get)" name: - description: 'If pre is set, you may optionally specify a prerelease name' + description: "If pre is set, you may optionally specify a prerelease name" required: false value: - description: 'If pre is set, you may optionally specify a prerelease number' + description: "If pre is set, you may optionally specify a prerelease number" build: - description: 'Optional build metadata' + description: "Optional build metadata" required: false current: - description: 'The version for the set command' + description: "The version for the set command" outputs: version: - description: 'The resulting version change' + description: "The resulting version change" version_docker: - description: 'The resulting version change formatted to be compatible with docker tags' + description: "The resulting version change formatted to be compatible with docker tags" version_dotnet: - description: 'The resulting version change formatted to be compatible with dotnet' + description: "The resulting version change formatted to be compatible with dotnet" major: - description: 'If parsing, the major version' + description: "If parsing, the major version" minor: - description: 'If parsing, the minor version' + description: "If parsing, the minor version" patch: - description: 'If parsing, the patch version' + description: "If parsing, the patch version" prerelease: - description: 'If parsing, the prerelease version' + description: "If parsing, the prerelease version" build: - description: 'If parsing, the build version' + description: "If parsing, the build version" runs: - using: 'docker' - image: 'Dockerfile.action' + using: "docker" + image: "Dockerfile.action" args: - - ${{ inputs.action || 'get' }} - - ${{ inputs.command }} - - ${{ inputs.pre && '--pre' || ''}} - - ${{ inputs.name && '--name' || '' }} - - ${{ inputs.name || '' }} - - ${{ inputs.value && '--value' || '' }} - - ${{ inputs.value || '' }} - - ${{ inputs.build && '--build' || '' }} - - ${{ inputs.build || '' }} - - ${{ inputs.current }} + - ${{ inputs.action || 'get' }} + - ${{ inputs.command }} + - ${{ inputs.pre && '--pre' || ''}} + - ${{ inputs.name && '--name' || '' }} + - ${{ inputs.name || '' }} + - ${{ inputs.value && '--value' || '' }} + - ${{ inputs.value || '' }} + - ${{ inputs.build && '--build' || '' }} + - ${{ inputs.build || '' }} + - ${{ inputs.current }} From c6b870cab2e6be5f5bd4d4b4a05f572f125d55e5 Mon Sep 17 00:00:00 2001 From: "Chase, Justin M" Date: Thu, 19 Jun 2025 14:25:04 -0500 Subject: [PATCH 4/5] fix docs --- README.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/README.md b/README.md index bbe8cbf..a445b73 100644 --- a/README.md +++ b/README.md @@ -217,19 +217,13 @@ jobs: ```yml name: Publish on: - workflow_dispatch: - inputs: - pre: - type: boolean - default: true release: types: [published] jobs: publish: steps: - - if: inputs.pre - name: Increment Pre-Release Version + - name: Increment Pre-Release Version uses: optum/semver-cli/setup@0.9.20 - id: version From 8348e543a0dd85736522d5512dd80b5f9707636d Mon Sep 17 00:00:00 2001 From: "Chase, Justin M" Date: Thu, 19 Jun 2025 16:21:11 -0500 Subject: [PATCH 5/5] push tags also --- .github/workflows/publish.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index dfcbdec..7b4e52e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -120,3 +120,31 @@ jobs: push: true tags: latest,optum/semver-cli:${{ needs.version.outputs.version }},optum/semver-cli:v${{ needs.version.outputs.major }}.${{ needs.version.outputs.minor }},optum/semver-cli:v${{ needs.version.outputs.major }} platforms: linux/amd64 + + tags: + runs-on: ubuntu-latest + needs: + - version + - assets + - docker + permissions: + contents: write + id-token: write + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + steps: + - name: Configure Git + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + gh auth setup-git + + - uses: actions/checkout@v4 + - name: Create Tags + run: | + git tag "v${{ needs.version.outputs.version }}" + git tag "v${{ needs.version.outputs.major }}.${{ needs.version.outputs.minor }}" + git tag "v${{ needs.version.outputs.major }}" + git push origin --tags + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}