2021-05-21 19:59:44 +03:00
|
|
|
import * as core from '@actions/core';
|
|
|
|
|
import * as github from '@actions/github';
|
2021-05-25 21:00:46 +03:00
|
|
|
import { context } from '@actions/github';
|
|
|
|
|
import { updateTag, validateIfReleaseIsPublished, postMessageToSlack } from './api-utils';
|
2021-05-21 19:59:44 +03:00
|
|
|
import { validateSemverVersionFromTag, getMajorTagFromFullTag } from './version-utils';
|
|
|
|
|
|
|
|
|
|
async function run(): Promise<void> {
|
|
|
|
|
try {
|
|
|
|
|
const token = core.getInput('token');
|
|
|
|
|
const octokitClient = github.getOctokit(token);
|
|
|
|
|
const sourceTagName = core.getInput('source-tag');
|
|
|
|
|
|
|
|
|
|
validateSemverVersionFromTag(sourceTagName);
|
|
|
|
|
|
|
|
|
|
await validateIfReleaseIsPublished(sourceTagName, octokitClient);
|
|
|
|
|
|
|
|
|
|
const majorTag = getMajorTagFromFullTag(sourceTagName);
|
|
|
|
|
await updateTag(sourceTagName, majorTag, octokitClient);
|
|
|
|
|
|
|
|
|
|
core.setOutput('major-tag', majorTag);
|
|
|
|
|
core.info(`The '${majorTag}' major tag now points to the '${sourceTagName}' tag`);
|
2021-05-25 21:00:46 +03:00
|
|
|
|
2023-01-09 04:16:12 -05:00
|
|
|
const slackMessage = `The ${majorTag} tag has been successfully updated for the ${context.repo.repo} action to include changes from ${sourceTagName}`;
|
2021-05-25 21:00:46 +03:00
|
|
|
await reportStatusToSlack(slackMessage);
|
2021-05-21 19:59:44 +03:00
|
|
|
} catch (error) {
|
2023-01-09 04:16:12 -05:00
|
|
|
core.setFailed((error as Error).message);
|
2021-05-25 21:00:46 +03:00
|
|
|
|
|
|
|
|
const slackMessage = `Failed to update a major tag for the ${context.repo.repo} action`;
|
|
|
|
|
await reportStatusToSlack(slackMessage);
|
2021-05-21 19:59:44 +03:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-25 21:00:46 +03:00
|
|
|
async function reportStatusToSlack(message: string): Promise<void> {
|
|
|
|
|
const slackWebhook = core.getInput('slack-webhook');
|
|
|
|
|
if (slackWebhook) {
|
|
|
|
|
await postMessageToSlack(slackWebhook, message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-21 19:59:44 +03:00
|
|
|
run();
|