Skip to content

Commit

Permalink
fix(update-tags): update correct commit
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Nov 11, 2022
1 parent b2ec9dd commit bb20c9d
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions update-tags/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const os = require('os');

const remoteRepo = `https://${process.env.GITHUB_ACTOR}:${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}.git`;

const run = (command, args) => {
const run = (command, args): Promise<string> => {
return new Promise((resolve, reject) => {
if (core.isDebug()) {
core.info(`Running "${command}" with args: ${JSON.stringify(args)}`);
Expand Down Expand Up @@ -39,18 +39,31 @@ const run = (command, args) => {
});
};

const findPreviousTag = async (): Promise<string | null> => {
const tagsString = await run('git', ['rev-list', 'HEAD']);
const revisions = tagsString.split('\n');

for (const revision of revisions) {
const tags = await run('git', ['tag', '--points-at', revision]);

for (const tag of tags.split('\n')) {
if (!valid(tag)) {
continue;
}

return tag;
}
}

return null;
};

const updateTags = async() => {
const lastTagRef = await run('git', ['rev-list', '--tags', '--max-count=1']);
const version = await run('git', ['describe', '--tags', lastTagRef]);
const version = await findPreviousTag();

const updateMajor = core.getBooleanInput('major');
const updateMinor = core.getBooleanInput('minor');

if (!valid(version)) {
core.error('Passed version "' + version + '" is not valid.');
return;
}

if (prerelease(version)) {
core.info('Prerelease version detected; will not add a major version tag.');
return;
Expand All @@ -77,7 +90,7 @@ const updateTags = async() => {

if (exists) {
core.info(`Deleting tag "${tagName}"`);
await run('git', ['push', remoteRepo, `:refs/tags/v${tagName}`]);
// await run('git', ['push', remoteRepo, `:refs/tags/v${tagName}`]);
}

if (exists) {
Expand All @@ -86,11 +99,11 @@ const updateTags = async() => {
core.info(`Creating new tag "${tagName}" on ${ref}`);
}

await run('git', ['tag', '--force', `v${tagName}`, ref]);
// await run('git', ['tag', '--force', `v${tagName}`, ref]);
}));

core.info('Pushing tags');
await run('git', ['push', remoteRepo, '--tags']);
// await run('git', ['push', remoteRepo, '--tags']);
};

try {
Expand Down

0 comments on commit bb20c9d

Please sign in to comment.