forked from segmentio/analytics-next
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix release tag parsing (segmentio#1007)
- Loading branch information
Showing
5 changed files
with
144 additions
and
15 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { parseReleaseNotes } from '..' | ||
import { parseReleaseNotes, parseRawTags } from '..' | ||
import fs from 'fs' | ||
import path from 'path' | ||
|
||
|
@@ -38,3 +38,129 @@ describe('parseReleaseNotes', () => { | |
`) | ||
}) | ||
}) | ||
|
||
describe('parseRawTags', () => { | ||
test('should work if all are on a single line', () => { | ||
const rawTags = | ||
'@segment/[email protected] @segment/[email protected] @segment/[email protected]' | ||
const tags = parseRawTags(rawTags) | ||
expect(tags).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"name": "@segment/analytics-next", | ||
"raw": "@segment/[email protected]", | ||
"versionNumber": "2.1.1", | ||
}, | ||
Object { | ||
"name": "@segment/analytics-foo", | ||
"raw": "@segment/[email protected]", | ||
"versionNumber": "1.0.1", | ||
}, | ||
Object { | ||
"name": "@segment/analytics-core", | ||
"raw": "@segment/[email protected]", | ||
"versionNumber": "1.0.0", | ||
}, | ||
] | ||
`) | ||
}) | ||
test('should work if there are multiple columns', () => { | ||
const rawTags = ` | ||
@segment/[email protected] @segment/[email protected] | ||
@segment/[email protected] @segment/[email protected] | ||
` | ||
const tags = parseRawTags(rawTags) | ||
expect(tags).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"name": "@segment/analytics-next", | ||
"raw": "@segment/[email protected]", | ||
"versionNumber": "2.1.1", | ||
}, | ||
Object { | ||
"name": "@segment/analytics-foo", | ||
"raw": "@segment/[email protected]", | ||
"versionNumber": "1.0.1", | ||
}, | ||
Object { | ||
"name": "@segment/analytics-core", | ||
"raw": "@segment/[email protected]", | ||
"versionNumber": "1.0.0", | ||
}, | ||
Object { | ||
"name": "@segment/analytics-bar", | ||
"raw": "@segment/[email protected]", | ||
"versionNumber": "1.0.1", | ||
}, | ||
] | ||
`) | ||
}) | ||
test('should work if there are many many columns', () => { | ||
const rawTags = ` | ||
@segment/[email protected] @segment/[email protected] @segment/[email protected] | ||
@segment/[email protected] @segment/[email protected] @segment/[email protected] | ||
@segment/[email protected] | ||
` | ||
const tags = parseRawTags(rawTags) | ||
expect(tags).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"name": "@segment/analytics-next", | ||
"raw": "@segment/[email protected]", | ||
"versionNumber": "2.1.1", | ||
}, | ||
Object { | ||
"name": "@segment/analytics-foo", | ||
"raw": "@segment/[email protected]", | ||
"versionNumber": "1.0.1", | ||
}, | ||
Object { | ||
"name": "@segment/analytics-bar", | ||
"raw": "@segment/[email protected]", | ||
"versionNumber": "1.0.1", | ||
}, | ||
Object { | ||
"name": "@segment/analytics-next", | ||
"raw": "@segment/[email protected]", | ||
"versionNumber": "2.1.1", | ||
}, | ||
Object { | ||
"name": "@segment/analytics-baz", | ||
"raw": "@segment/[email protected]", | ||
"versionNumber": "1.0.1", | ||
}, | ||
Object { | ||
"name": "@segment/analytics-foobar", | ||
"raw": "@segment/[email protected]", | ||
"versionNumber": "1.0.1", | ||
}, | ||
Object { | ||
"name": "@segment/analytics-core", | ||
"raw": "@segment/[email protected]", | ||
"versionNumber": "1.0.0", | ||
}, | ||
] | ||
`) | ||
}) | ||
test('should work if there is newline characters', () => { | ||
const rawTags = ` | ||
@segment/[email protected] | ||
@segment/[email protected] | ||
` | ||
const tags = parseRawTags(rawTags) | ||
expect(tags).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"name": "@segment/analytics-next", | ||
"raw": "@segment/[email protected]", | ||
"versionNumber": "2.1.1", | ||
}, | ||
Object { | ||
"name": "@segment/analytics-core", | ||
"raw": "@segment/[email protected]", | ||
"versionNumber": "1.0.0", | ||
}, | ||
] | ||
`) | ||
}) | ||
}) |
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 |
---|---|---|
|
@@ -25,7 +25,6 @@ export const getCurrentGitTags = async (): Promise<Tag[]> => { | |
'tag', | ||
'--points-at', | ||
'HEAD', | ||
'--column', | ||
]) | ||
if (code !== 0) { | ||
throw new Error(stderr.toString()) | ||
|
@@ -34,10 +33,8 @@ export const getCurrentGitTags = async (): Promise<Tag[]> => { | |
return parseRawTags(stdout.toString()) | ||
} | ||
|
||
export const getConfig = async ({ | ||
DRY_RUN, | ||
TAGS, | ||
}: NodeJS.ProcessEnv): Promise<Config> => { | ||
export const getConfig = async (): Promise<Config> => { | ||
const { DRY_RUN, TAGS } = process.env | ||
const isDryRun = Boolean(DRY_RUN) | ||
const tags = TAGS ? parseRawTags(TAGS) : await getCurrentGitTags() | ||
|
||
|
@@ -116,7 +113,12 @@ const extractPartsFromTag = (rawTag: string): Tag | undefined => { | |
* @param rawTags - string delimited list of tags (e.g. `@segment/[email protected] @segment/[email protected]`) | ||
*/ | ||
export const parseRawTags = (rawTags: string): Tag[] => { | ||
return rawTags.trim().split(' ').map(extractPartsFromTag).filter(exists) | ||
return rawTags | ||
.trim() | ||
.replace(new RegExp('\\n', 'g'), ' ') // remove any newLine characters | ||
.split(' ') | ||
.map(extractPartsFromTag) | ||
.filter(exists) | ||
} | ||
|
||
/** | ||
|
@@ -187,6 +189,7 @@ export const createReleaseFromTags = async (config: Config) => { | |
console.log('Processing tags:', config.tags, '\n') | ||
|
||
for (const tag of config.tags) { | ||
console.log(`\n ---> Creating release for tag: ${tag.raw}`) | ||
await createGithubReleaseFromTag(tag, { dryRun: config.isDryRun }) | ||
} | ||
} |
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