Skip to content

Commit 46eb498

Browse files
authored
Merge pull request #2 from riege/BUILD-52
BUILD-52 Add additional outputs
2 parents f025368 + 11ef66e commit 46eb498

File tree

8 files changed

+1125
-31
lines changed

8 files changed

+1125
-31
lines changed

.github/workflows/testAction.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,24 @@ jobs:
1818
- run: npm test
1919
- uses: ./
2020
id: version
21-
- run: |
22-
export VERSION="${{ steps.version.outputs.version }}"
23-
echo "$VERSION must match .+-.+-.+"
24-
bash -c '[[ $VERSION =~ .+-.+-.+ ]]'
21+
- name: Test outputs
22+
run: |
23+
export OUTPUT="${{ steps.version.outputs.version }}"
24+
echo "version: $OUTPUT must match .+-.+-.+"
25+
bash -c '[[ $OUTPUT =~ .+-.+-.+ ]]'
26+
27+
export OUTPUT="${{ steps.version.outputs.version-without-v }}"
28+
echo "version-without-v: $OUTPUT must match .+-.+-.+"
29+
bash -c '[[ $OUTPUT =~ .+-.+-.+ ]]'
30+
31+
export OUTPUT="${{ steps.version.outputs.major }}"
32+
echo "major: $OUTPUT must not be empty"
33+
test -n "$OUTPUT"
34+
35+
export OUTPUT="${{ steps.version.outputs.minor }}"
36+
echo "minor: $OUTPUT must not be empty"
37+
test -n "$OUTPUT"
38+
39+
export OUTPUT="${{ steps.version.outputs.patch }}"
40+
echo "patch: $OUTPUT must not be empty"
41+
test -n "$OUTPUT"

README.md

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,37 @@
11
# action-version
22
A GitHub action to determine the version for build artifacts.
33

4+
## Versioning Scheme
5+
6+
The general idea is to generate a unique version string from the job context that is unique for each run, easy to read and compare, and clearly identifies the revision that was used.
7+
8+
| Ref Type | Version | Example |
9+
| ------------ | ------- | ------- |
10+
| Git tag | \<tagname\> | v1.3.2
11+
| Branch | \<branchname\>-\<runnumber\>-\<sha\> | main-9-f025368a |
12+
| Pull request | pr-\<prnumber\>-\<runnumber\>-\<sha\> | pr-9-1-89d735ed |
13+
14+
Tags are assumed to already satisfy these goals and are taken as-is. For other cases, the first part (branch name or PR number) tells whether two version can be compared, the second part (build number) allows to quickly tell versions apart, and the commit hash uniquely identifies the revision of the source that was build.
15+
416
## Outputs
5-
version: The version string
617

7-
| CI/CD Build | Version |
8-
| ----------- | ----------- |
9-
| Git tag x.y.z on master branch (a prefixed "v" is okay, too) | X.Y.Z, X.Y, X, vX.Y.Z ... |
10-
| Untagged main commit | main-\<runnumber\>-\<sha\> |
11-
| Pull request | pr-\<prnumber\>-\<runnumber\>-\<sha\>
18+
- **version**: The version string
19+
- **version-without-v**: The version string, with a leading "v" removed for tags that resemble a version number
20+
- **major**: The major part of a semantic version
21+
- **minor**: The minor part of a semantic version
22+
- **patch**: The remainder (after major and minor) of a semantic version
23+
24+
## Example Output Values
25+
26+
| Ref | Run | SHA | version | version-without-v | major | minor | patch |
27+
| --- | --- | --- | ------- | ----------------- | ----- | ----- | ----- |
28+
| refs/tags/v1| 9| a52f| v1| 1| 1| | |
29+
| refs/tags/1.2.3| 9| a52f| 1.2.3| 1.2.3| 1| 2| 3|
30+
| refs/tags/v1.2.3| 9| a52f| v1.2.3| 1.2.3| 1| 2| 3|
31+
| refs/tags/1.2.3.4| 9| a52f| 1.2.3.4| 1.2.3.4| 1| 2| 3.4|
32+
| refs/heads/main| 9| a52f| main-9-a52f| main-9-a52f| main| 9| a52f|
33+
| refs/heads/stable| 9| a52f| stable-9-a52f| stable-9-a52f| stable| 9| a52f|
34+
| refs/pull/1/merge| 9| a52f| pr-1-9-a52f| pr-1-9-a52f| pr-1| 9| a52f|
1235

1336
## Example Usage
1437
```
@@ -27,8 +50,8 @@ jobs:
2750
name: Echo action's outputs
2851
steps:
2952
- id: version
30-
uses: riege/action-version@v1.0
53+
uses: riege/action-version@v1
3154
- run: |
3255
echo Version: ${{ steps.version.outputs.version }}
33-
echo Image tag: "${{ secrets.ACR_LOGIN_SERVER }}/my-container:${{ steps.version.outputs.version }}"
56+
echo Image tag: "${{ secrets.ACR_LOGIN_SERVER }}/my-container:${{ steps.version.outputs.version-without-v }}"
3457
```

action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ description: 'Determine the version for the build artifacts'
44
outputs:
55
version:
66
description: "The version string"
7+
version-without-v:
8+
description: "The version string, with a leading \"v\" removed for tags that resemble a version number"
9+
major:
10+
description: "The major part of a semantic version"
11+
minor:
12+
description: "The minor part of a semantic version"
13+
patch:
14+
description: "The remainder (after major and minor) of a semantic version"
715

816
runs:
917
using: "node12"

index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
const core = require('@actions/core');
2-
const getVersion = require('./version');
2+
const version = require('./version');
33

44
try {
5-
const version = getVersion.get(process.env.GITHUB_REF, process.env.GITHUB_RUN_NUMBER, process.env.GITHUB_SHA);
6-
core.setOutput("version", version);
5+
const outputs = version.get(process.env.GITHUB_REF, process.env.GITHUB_RUN_NUMBER, process.env.GITHUB_SHA);
6+
core.setOutput("version", outputs.version);
7+
core.setOutput("version-without-v", outputs.versionWithoutV);
8+
core.setOutput("major", outputs.major);
9+
core.setOutput("minor", outputs.minor);
10+
core.setOutput("patch", outputs.patch);
711
} catch (error) {
812
core.setFailed(error.message);
913
}

0 commit comments

Comments
 (0)