Skip to content

Commit

Permalink
Add support for working with tag pushes
Browse files Browse the repository at this point in the history
Change-type: minor
  • Loading branch information
thgreasi committed Jun 23, 2022
1 parent d9918a0 commit 83db95a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
14 changes: 12 additions & 2 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,21 @@ export async function run(
let buildOptions = null;

// If we are pushing directly to the target branch then just build a release without draft flag
if (context.eventName === 'push' && context.ref === `refs/heads/${target}`) {
if (
context.eventName === 'push' &&
(context.ref === `refs/heads/${target}` ||
context.ref.startsWith('refs/tags/'))
) {
// TODO: Update this to use ref_type & ref_name once that becomes available
// See: https://github.com/actions/toolkit/pull/935/files
const tagName = context.ref.match(/^refs\/tags\/(\w+)/)?.[1];
// Make a final release because context is master workflow
buildOptions = {
draft: false,
tags: { sha: context.sha },
tags: {
sha: context.sha,
...(!!tagName && { tag: tagName }),
},
};
} else if (context.eventName !== 'pull_request') {
// Make sure the only events now are Pull Requests
Expand Down
18 changes: 11 additions & 7 deletions src/balena-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ import * as balena from 'balena-sdk';

import { Release } from './types';

const TagKeyMap = {
sha: 'balena-ci-commit-sha',
pullRequestId: 'balena-ci-id',
tag: 'balena-ci-git-tag',
};

type Tags = {
sha: string;
pullRequestId?: number;
tag?: string;
};

type BuildOptions = {
Expand Down Expand Up @@ -76,15 +83,12 @@ export async function push(
'--source',
source,
'--release-tag',
'balena-ci-commit-sha',
buildOpt.tags.sha,
...Object.entries(buildOpt.tags).flatMap(([key, value]) => [
TagKeyMap[key as keyof typeof TagKeyMap],
String(value),
]),
];

if (buildOpt.tags.pullRequestId) {
pushOpt.push('balena-ci-id');
pushOpt.push(buildOpt.tags.pullRequestId.toString());
}

if (buildOpt.draft) {
pushOpt.push('--draft');
}
Expand Down

0 comments on commit 83db95a

Please sign in to comment.