-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import chalk from 'chalk' | |
import path from 'path' | ||
import {readFile, writeFile} from '../util/files' | ||
import {errorToUndefined} from '../util/errorToUndefined' | ||
import {PackageJson} from '../actions/verify/types' | ||
|
||
export const semverWorkflowPreset: Preset = { | ||
name: 'semver-workflow', | ||
|
@@ -79,12 +80,14 @@ async function updateReadme(options: InjectOptions) { | |
async function readmeSnippets(options: InjectOptions) { | ||
const pkg = await getPackage(options) | ||
|
||
const bestEffortUrl = readmeBaseurl(pkg) | ||
|
||
const v3Banner = outdent` | ||
> **NOTE** | ||
> | ||
> This is the **Sanity Studio v3 version** of ${pkg.name}. | ||
> | ||
> For the v2 version, please refer to the [v2-branch](${pkg.repository?.url ?? 'TODO'}). | ||
> For the v2 version, please refer to the [v2-branch](${bestEffortUrl}). | ||
` | ||
|
||
const installUsage = outdent` | ||
|
@@ -120,7 +123,7 @@ async function readmeSnippets(options: InjectOptions) { | |
### Release new version | ||
Run ["CI & Release" workflow](${pkg.repository?.url ?? 'TODO'}/actions/workflows/main.yml). | ||
Run ["CI & Release" workflow](${bestEffortUrl}/actions/workflows/main.yml). | ||
Make sure to select the main branch and check "Release new version". | ||
Semantic release will only release on configured branches, so it is safe to run release on any branch. | ||
|
@@ -156,3 +159,12 @@ async function semverWorkflowDependencies(): Promise<Record<string, string>> { | |
'lint-staged', | ||
]) | ||
} | ||
|
||
export function readmeBaseurl(pkg: PackageJson) { | ||
return ((pkg.repository?.url ?? pkg.homepage ?? 'TODO') as string) | ||
.replaceAll(/.+:\/\//g, 'https://') | ||
.replaceAll(/\.git/g, '') | ||
.replaceAll(/[email protected]\//g, 'github.com/') | ||
.replaceAll(/[email protected]:/g, 'https://github.com/') | ||
.replaceAll(/#.+/g, '') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import tap from 'tap' | ||
import {readmeBaseurl} from '../src/presets/semver-workflow' | ||
import {PackageJson} from '../src/actions/verify/types' | ||
|
||
tap.test('readmeBaseUrl', async (t) => { | ||
const testCases: {pkg: PackageJson; expectedUrl: string}[] = [ | ||
{ | ||
pkg: {repository: {url: 'git+https://github.com/sanity-io/sanity.git'}}, | ||
expectedUrl: 'https://github.com/sanity-io/sanity', | ||
}, | ||
{ | ||
pkg: {repository: {url: 'git+ssh://[email protected]/sanity-io/plugin-kit.git'}}, | ||
expectedUrl: 'https://github.com/sanity-io/plugin-kit', | ||
}, | ||
{ | ||
pkg: {repository: {url: '[email protected]:sanity-io/sanity-plugin-cloudinary.git'}}, | ||
expectedUrl: 'https://github.com/sanity-io/sanity-plugin-cloudinary', | ||
}, | ||
{ | ||
pkg: {repository: {url: 'git+https://github.com/sanity-io/sanity-plugin.git'}}, | ||
expectedUrl: 'https://github.com/sanity-io/sanity-plugin', | ||
}, | ||
{ | ||
pkg: {homepage: 'https://github.com/sanity-io/plugin-with-readme#readme'}, | ||
expectedUrl: 'https://github.com/sanity-io/plugin-with-readme', | ||
}, | ||
] | ||
|
||
testCases.forEach(({pkg, expectedUrl}) => t.equal(readmeBaseurl(pkg), expectedUrl)) | ||
}) |