Skip to content
Snippets Groups Projects
Unverified Commit 791223d8 authored by Diego Sampaio's avatar Diego Sampaio
Browse files

ci(release): fix version replace

parent 68317c85
No related branches found
No related tags found
No related merge requests found
...@@ -55,6 +55,7 @@ export async function bumpNextVersion({ ...@@ -55,6 +55,7 @@ export async function bumpNextVersion({
const newBranch = `release-${finalVersion}`; const newBranch = `release-${finalVersion}`;
// update root package.json // update root package.json
core.info('bump main package.json version');
updateVersionPackageJson(cwd, newVersion); updateVersionPackageJson(cwd, newVersion);
// TODO check if branch exists // TODO check if branch exists
...@@ -63,6 +64,7 @@ export async function bumpNextVersion({ ...@@ -63,6 +64,7 @@ export async function bumpNextVersion({
await exec('git', ['add', '.']); await exec('git', ['add', '.']);
await exec('git', ['commit', '-m', newVersion]); await exec('git', ['commit', '-m', newVersion]);
core.info('fix dependencies in workspace packages');
await fixWorkspaceVersionsBeforePublish(); await fixWorkspaceVersionsBeforePublish();
await exec('yarn', ['changeset', 'publish']); await exec('yarn', ['changeset', 'publish']);
...@@ -80,8 +82,11 @@ export async function bumpNextVersion({ ...@@ -80,8 +82,11 @@ export async function bumpNextVersion({
body: prBody, body: prBody,
...github.context.repo, ...github.context.repo,
}); });
} else {
core.info('no pull request created: release is not the first candidate');
} }
core.info('create release');
await octokit.rest.repos.createRelease({ await octokit.rest.repos.createRelease({
name: newVersion, name: newVersion,
tag_name: newVersion, tag_name: newVersion,
......
...@@ -3,6 +3,7 @@ import path from 'path'; ...@@ -3,6 +3,7 @@ import path from 'path';
import { exec } from '@actions/exec'; import { exec } from '@actions/exec';
import * as github from '@actions/github'; import * as github from '@actions/github';
import * as core from '@actions/core';
import { createNpmFile } from './createNpmFile'; import { createNpmFile } from './createNpmFile';
import { setupOctokit } from './setupOctokit'; import { setupOctokit } from './setupOctokit';
...@@ -71,17 +72,20 @@ export async function publishRelease({ ...@@ -71,17 +72,20 @@ export async function publishRelease({
const releaseBody = changelogEntry.content; const releaseBody = changelogEntry.content;
// update root package.json // update root package.json
core.info('bump main package.json version');
updateVersionPackageJson(cwd, newVersion); updateVersionPackageJson(cwd, newVersion);
await exec('git', ['add', '.']); await exec('git', ['add', '.']);
await exec('git', ['commit', '-m', newVersion]); await exec('git', ['commit', '-m', newVersion]);
core.info('fix dependencies in workspace packages');
await fixWorkspaceVersionsBeforePublish(); await fixWorkspaceVersionsBeforePublish();
await exec('yarn', ['changeset', 'publish']); await exec('yarn', ['changeset', 'publish']);
await exec('git', ['push', '--follow-tags']); await exec('git', ['push', '--follow-tags']);
core.info('create release');
await octokit.rest.repos.createRelease({ await octokit.rest.repos.createRelease({
name: newVersion, name: newVersion,
tag_name: newVersion, tag_name: newVersion,
......
...@@ -38,6 +38,7 @@ export async function startPatchRelease({ ...@@ -38,6 +38,7 @@ export async function startPatchRelease({
// TODO check if branch exists // TODO check if branch exists
await exec('git', ['checkout', '-b', newBranch]); await exec('git', ['checkout', '-b', newBranch]);
core.info('bump main package.json version');
updateVersionPackageJson(cwd, newVersion); updateVersionPackageJson(cwd, newVersion);
await exec('git', ['add', '.']); await exec('git', ['add', '.']);
...@@ -57,5 +58,7 @@ export async function startPatchRelease({ ...@@ -57,5 +58,7 @@ export async function startPatchRelease({
body: '', body: '',
...github.context.repo, ...github.context.repo,
}); });
} else {
core.info('no pull request created: patch is not for current version');
} }
} }
...@@ -61,6 +61,6 @@ export function getChangelogEntry(changelog: string, version: string) { ...@@ -61,6 +61,6 @@ export function getChangelogEntry(changelog: string, version: string) {
export function updateVersionPackageJson(cwd = process.cwd(), newVersion: string) { export function updateVersionPackageJson(cwd = process.cwd(), newVersion: string) {
const rootPackageJsonPath = path.resolve(cwd, 'package.json'); const rootPackageJsonPath = path.resolve(cwd, 'package.json');
const content = fs.readFileSync(rootPackageJsonPath, 'utf8'); const content = fs.readFileSync(rootPackageJsonPath, 'utf8');
const updatedContent = content.replace(/'version': '.*',$/m, `'version': '${newVersion}',`); const updatedContent = content.replace(/"version": ".*",$/m, `"version": "${newVersion}",`);
fs.writeFileSync(rootPackageJsonPath, updatedContent); fs.writeFileSync(rootPackageJsonPath, updatedContent);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment