Skip to content

Commit c4a9d94

Browse files
committed
Add support for working with tag pushes
Change-type: minor
1 parent d9918a0 commit c4a9d94

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/action.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,21 @@ export async function run(
9090
let buildOptions = null;
9191

9292
// If we are pushing directly to the target branch then just build a release without draft flag
93-
if (context.eventName === 'push' && context.ref === `refs/heads/${target}`) {
93+
if (
94+
context.eventName === 'push' &&
95+
(context.ref === `refs/heads/${target}` ||
96+
context.ref.startsWith('/refs/tags/'))
97+
) {
98+
// TODO: Update this to use ref_type & ref_name once that becomes available
99+
// See: https://github.com/actions/toolkit/pull/935/files
100+
const tagName = context.ref.match(/^\/refs\/tags\/(\w+)/)?.[1];
94101
// Make a final release because context is master workflow
95102
buildOptions = {
96103
draft: false,
97-
tags: { sha: context.sha },
104+
tags: {
105+
sha: context.sha,
106+
...(!!tagName && { tag: tagName }),
107+
},
98108
};
99109
} else if (context.eventName !== 'pull_request') {
100110
// Make sure the only events now are Pull Requests

src/balena-utils.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ import * as balena from 'balena-sdk';
55

66
import { Release } from './types';
77

8+
const TagKeyMap = {
9+
sha: 'balena-ci-commit-sha',
10+
pullRequestId: 'balena-ci-id',
11+
tag: 'balena-ci-git-tag',
12+
};
13+
814
type Tags = {
915
sha: string;
1016
pullRequestId?: number;
17+
tag?: string;
1118
};
1219

1320
type BuildOptions = {
@@ -76,15 +83,12 @@ export async function push(
7683
'--source',
7784
source,
7885
'--release-tag',
79-
'balena-ci-commit-sha',
80-
buildOpt.tags.sha,
86+
...Object.entries(buildOpt.tags).flatMap(([key, value]) => [
87+
TagKeyMap[key as keyof typeof TagKeyMap],
88+
String(value),
89+
]),
8190
];
8291

83-
if (buildOpt.tags.pullRequestId) {
84-
pushOpt.push('balena-ci-id');
85-
pushOpt.push(buildOpt.tags.pullRequestId.toString());
86-
}
87-
8892
if (buildOpt.draft) {
8993
pushOpt.push('--draft');
9094
}

0 commit comments

Comments
 (0)