|
1 | 1 | # action-version |
2 | 2 | A GitHub action to determine the version for build artifacts. |
3 | 3 |
|
| 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 | + |
4 | 16 | ## Outputs |
5 | | -version: The version string |
6 | 17 |
|
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| |
12 | 35 |
|
13 | 36 | ## Example Usage |
14 | 37 | ``` |
|
27 | 50 | name: Echo action's outputs |
28 | 51 | steps: |
29 | 52 | - id: version |
30 | | - uses: riege/action-version@v1.0 |
| 53 | + uses: riege/action-version@v1 |
31 | 54 | - run: | |
32 | 55 | 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 }}" |
34 | 57 | ``` |
0 commit comments