Skip to content

Commit 1a1935a

Browse files
authored
Add action to top level of repo (#108)
* Add action to top level of repo * add readme * fmt * fix docs * push tags also
1 parent c854eb8 commit 1a1935a

File tree

6 files changed

+180
-2
lines changed

6 files changed

+180
-2
lines changed

.github/version.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@ on:
66
- kind: regexp
77
file: README.md
88
pattern: '(?<=semver-cli@).*(?=\/main.ts)'
9+
- kind: regexp
10+
file: README.md
11+
pattern: "(?<=semver-cli@).*$"
912
- kind: regexp
1013
file: Dockerfile
1114
pattern: '(?<=VERSION=).*(?=; \\)'
1215
- kind: regexp
1316
file: setup/action.yml
1417
pattern: "(?<=default: ).*"
18+
- kind: regexp
19+
file: action.yml
20+
pattern: "(?<=default: ).*"
21+
- kind: regexp
22+
file: Dockerfile.action
23+
pattern: "(?<=semver-cli:).*"

.github/workflows/publish.yml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ jobs:
1313
runs-on: ubuntu-latest
1414
outputs:
1515
version: ${{ steps.parse_version.outputs.version }}
16+
major: ${{ steps.parse_version.outputs.major }}
17+
minor: ${{ steps.parse_version.outputs.minor }}
1618
steps:
1719
- uses: actions/checkout@v4
1820
- uses: denoland/setup-deno@v2
@@ -22,8 +24,10 @@ jobs:
2224
- id: parse_version
2325
name: Parse the Version
2426
run: deno run -A main.ts parse
27+
2528
assets:
2629
runs-on: ubuntu-latest
30+
needs: version
2731
permissions:
2832
contents: write
2933
strategy:
@@ -37,7 +41,6 @@ jobs:
3741
extension: ""
3842
- name: "aarch64-apple-darwin"
3943
extension: ""
40-
needs: version
4144
steps:
4245
- uses: actions/checkout@v4
4346
- uses: denoland/setup-deno@v2
@@ -115,5 +118,33 @@ jobs:
115118
uses: docker/build-push-action@v4
116119
with:
117120
push: true
118-
tags: optum/semver-cli:${{ needs.version.outputs.version }}
121+
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 }}
119122
platforms: linux/amd64
123+
124+
tags:
125+
runs-on: ubuntu-latest
126+
needs:
127+
- version
128+
- assets
129+
- docker
130+
permissions:
131+
contents: write
132+
id-token: write
133+
env:
134+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
135+
steps:
136+
- name: Configure Git
137+
run: |
138+
git config --global user.name 'github-actions[bot]'
139+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
140+
gh auth setup-git
141+
142+
- uses: actions/checkout@v4
143+
- name: Create Tags
144+
run: |
145+
git tag "v${{ needs.version.outputs.version }}"
146+
git tag "v${{ needs.version.outputs.major }}.${{ needs.version.outputs.minor }}"
147+
git tag "v${{ needs.version.outputs.major }}"
148+
git push origin --tags
149+
env:
150+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ LABEL maintainer="Justin Chase <[email protected]>"
55
LABEL repository="https://github.com/optum/semver-cli"
66
LABEL homepage="https://github.com/optum/semver-cli"
77

8+
# Label as GitHub action
9+
LABEL com.github.actions.name="semver-cli"
10+
11+
# Limit to 160 characters
12+
LABEL com.github.actions.description="Get, set and increment your project version"
13+
14+
# See branding:
15+
# https://docs.github.com/actions/creating-actions/metadata-syntax-for-github-actions#branding
16+
LABEL com.github.actions.icon="activity"
17+
LABEL com.github.actions.color="orange"
18+
819
WORKDIR /app
920
ENV PATH="/app/bin:${PATH}"
1021
RUN mkdir -p /app/bin

Dockerfile.action

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM optum/semver-cli:0.9.20

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,69 @@ on:
174174
pattern: '^(?<=export const version = ").*(?=";)$'
175175
```
176176
177+
## Actions
178+
179+
This repository has two actions available, either a basic setup action or a
180+
single docker based action.
181+
182+
#### example
183+
184+
```yml
185+
name: Publish
186+
on:
187+
workflow_dispatch:
188+
inputs:
189+
pre:
190+
type: boolean
191+
default: true
192+
release:
193+
types: [published]
194+
195+
jobs:
196+
publish:
197+
steps:
198+
- if: inputs.pre
199+
name: Increment Pre-Release Version
200+
uses: optum/[email protected]
201+
with:
202+
action: inc
203+
pre: true
204+
name: pr
205+
value: ${{ github.run_number }}
206+
build: ${{ github.run_id }}
207+
208+
- id: version
209+
name: Get Version
210+
uses: optum/[email protected]
211+
212+
- run: echo "The calculated ${{ steps.version.outputs.version }}"
213+
```
214+
215+
#### example of setup action
216+
217+
```yml
218+
name: Publish
219+
on:
220+
release:
221+
types: [published]
222+
223+
jobs:
224+
publish:
225+
steps:
226+
- name: Increment Pre-Release Version
227+
uses: optum/semver-cli/[email protected]
228+
229+
- id: version
230+
name: Parse Version
231+
run: |
232+
echo "version=$(semver parse | jq -r '.version')" > $GITHUB_OUTPUT
233+
echo "major=$(semver parse | jq -r '.major')" > $GITHUB_OUTPUT
234+
echo "minor=$(semver parse | jq -r '.minor')" > $GITHUB_OUTPUT
235+
echo "patch=$(semver parse | jq -r '.patch')" > $GITHUB_OUTPUT
236+
237+
- run: echo "The calculated ${{ steps.version.outputs.version }}"
238+
```
239+
177240
# Contributing
178241
179242
Contributions are what make the open source community such an amazing place to

action.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: "semver-cli"
2+
description: "Semver utility action"
3+
branding:
4+
icon: activity
5+
color: orange
6+
inputs:
7+
action:
8+
description: "A versioning action to perform (get|set|inc|parse)"
9+
required: false
10+
command:
11+
type: choice
12+
description: "The kind of increment (major|minor|patch|none) for (get|inc) actions"
13+
required: false
14+
options:
15+
- none
16+
- major
17+
- minor
18+
- patch
19+
pre:
20+
type: boolean
21+
description: "Whether or not to create a pre-release version (inc|get)"
22+
name:
23+
description: "If pre is set, you may optionally specify a prerelease name"
24+
required: false
25+
value:
26+
description: "If pre is set, you may optionally specify a prerelease number"
27+
build:
28+
description: "Optional build metadata"
29+
required: false
30+
current:
31+
description: "The version for the set command"
32+
33+
outputs:
34+
version:
35+
description: "The resulting version change"
36+
version_docker:
37+
description: "The resulting version change formatted to be compatible with docker tags"
38+
version_dotnet:
39+
description: "The resulting version change formatted to be compatible with dotnet"
40+
major:
41+
description: "If parsing, the major version"
42+
minor:
43+
description: "If parsing, the minor version"
44+
patch:
45+
description: "If parsing, the patch version"
46+
prerelease:
47+
description: "If parsing, the prerelease version"
48+
build:
49+
description: "If parsing, the build version"
50+
runs:
51+
using: "docker"
52+
image: "Dockerfile.action"
53+
args:
54+
- ${{ inputs.action || 'get' }}
55+
- ${{ inputs.command }}
56+
- ${{ inputs.pre && '--pre' || ''}}
57+
- ${{ inputs.name && '--name' || '' }}
58+
- ${{ inputs.name || '' }}
59+
- ${{ inputs.value && '--value' || '' }}
60+
- ${{ inputs.value || '' }}
61+
- ${{ inputs.build && '--build' || '' }}
62+
- ${{ inputs.build || '' }}
63+
- ${{ inputs.current }}

0 commit comments

Comments
 (0)