diff --git a/.github/version.yml b/.github/version.yml index 7e1a3d7..56faa73 100644 --- a/.github/version.yml +++ b/.github/version.yml @@ -6,9 +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/.github/workflows/publish.yml b/.github/workflows/publish.yml index f055c26..7b4e52e 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,33 @@ 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 + + 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 }} 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/README.md b/README.md index 68041cd..a445b73 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,69 @@ 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: + release: + types: [published] + +jobs: + publish: + steps: + - 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 diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..9940438 --- /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 }}