Skip to content

Commit

Permalink
✨ Add short SHA output
Browse files Browse the repository at this point in the history
  • Loading branch information
proudust committed Dec 16, 2023
1 parent 3b7aab6 commit 369a07a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ All inputs are optional, and sensible defaults will be used if they are not set.

The following outputs can be used by subsequent workflow steps.

| Name | Description | Example |
| -------- | ---------------------------------------------------------- | ------------------------------------------ |
| describe | `git describe --tags`-like description. | `v1.5.4-2-g4fdf9d0` |
| tag | The most recent tag. | `v1.5.4` |
| distance | The number of additional commits from the most recent tag. | `2` |
| sha | The object name for the commit itself. | `4fdf9d0b88fe5f55e465ae947bca6b6b55c39415` |
| Name | Description | Example |
| --------- | ---------------------------------------------------------- | ------------------------------------------ |
| describe | `git describe --tags`-like description. | `v1.5.4-2-g4fdf9d0` |
| tag | The most recent tag. | `v1.5.4` |
| distance | The number of additional commits from the most recent tag. | `2` |
| sha | The object name for the commit itself. | `4fdf9d0b88fe5f55e465ae947bca6b6b55c39415` |
| short-sha | The object name for the commit itself. | `4fdf9d0` |

Step outputs can be accessed using the following example.\
Note that in order to read the step outputs, the action step must have an ID.
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ outputs:
description: >
The object name for the commit itself.
ex) 2414721
short-sha:
description: >
The object name for the commit itself.
ex) 2414721
runs:
using: node16
Expand Down
3 changes: 2 additions & 1 deletion actions/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function run() {

try {
Deno.env.set("GITHUB_TOKEN", token);
const { describe, tag, distance, sha } = await ghDescribe({
const { describe, tag, distance, sha, shortSha } = await ghDescribe({
repo,
commitish,
defaultTag,
Expand All @@ -29,6 +29,7 @@ async function run() {
setOutput("tag", tag);
setOutput("distance", distance);
setOutput("sha", sha);
setOutput("short-sha", shortSha);
} catch (e: unknown) {
if (e instanceof GhDescribeError) {
setFailed(`fatal: ${e.message}`);
Expand Down
13 changes: 12 additions & 1 deletion core/gh_describe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export interface GhDescribeOutput {
* Object name for the commit itself.
*/
sha: string;

/**
* Abbreviated object name for the commit itself.
*/
shortSha: string;
}

export function createDescribe(tag: string, distance: number, sha: string) {
Expand Down Expand Up @@ -106,5 +111,11 @@ export async function ghDescribe(options?: GhDescribeOptions): Promise<GhDescrib
}

const describe = createDescribe(tag, distance, sha);
return { describe, tag, distance, sha };
return {
describe,
tag,
distance,
sha,
shortSha: sha.substring(0, 7),
};
}
8 changes: 7 additions & 1 deletion dist/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25254,7 +25254,13 @@ async function ghDescribe(options) {
throw new GhDescribeError("No names found, cannot describe anything.");
}
const describe = createDescribe(tag, distance, sha);
return { describe, tag, distance, sha };
return {
describe,
tag,
distance,
sha,
shortSha: sha.substring(0, 7)
};
}

// dist/dnt/esm/actions/main.js
Expand Down
8 changes: 7 additions & 1 deletion dist/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -10549,7 +10549,13 @@ async function ghDescribe(options) {
throw new GhDescribeError("No names found, cannot describe anything.");
}
const describe2 = createDescribe(tag, distance2, sha);
return { describe: describe2, tag, distance: distance2, sha };
return {
describe: describe2,
tag,
distance: distance2,
sha,
shortSha: sha.substring(0, 7)
};
}

// dist/dnt/esm/cli/cli.js
Expand Down

0 comments on commit 369a07a

Please sign in to comment.