Skip to content

Commit 5503e1c

Browse files
committed
Add package version check
1 parent 7a7f522 commit 5503e1c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/package.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {dirname, join, normalize, relative} from 'path'
22
import {exec} from '@actions/exec'
33

44
import {GitHubHandle, lastCommitDate} from './github'
5-
import {semver} from './utils'
5+
import {isver, semver} from './utils'
66
import {getCrateVersions} from './crates'
77

88
type RawDependencyKind = 'dev' | 'build' | null
@@ -154,6 +154,7 @@ export interface CheckPackageError {
154154
| 'unable-to-get-commit-date'
155155
| 'has-unpublished-changes'
156156
| 'not-a-workspace-member'
157+
| 'invalid-package-version'
157158
| 'mismatch-intern-dep-path'
158159
| 'mismatch-intern-dep-version'
159160
| 'unable-to-find-extern-dep'
@@ -171,6 +172,14 @@ export async function checkPackages(
171172
for (const package_name in packages) {
172173
const package_info = packages[package_name]
173174

175+
if (!isver(package_info.version)) {
176+
errors.push({
177+
name: package_name,
178+
kind: 'invalid-package-version',
179+
message: `Invalid package '${package_name}' version: '${package_info.version}'`
180+
})
181+
}
182+
174183
tasks.push(
175184
(async () => {
176185
const published_versions = await getCrateVersions(package_name)

src/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as fs from 'fs'
22
import {promisify} from 'util'
3-
import {satisfies} from 'semver'
3+
import {parse, satisfies} from 'semver'
44

55
export const stat = promisify(fs.stat)
66
export const readFile = promisify(fs.readFile)
@@ -14,3 +14,7 @@ export async function delay(msecs: number): Promise<void> {
1414
export function semver(available: string, required: string): boolean {
1515
return satisfies(available, required.replace(/,/g, ' '))
1616
}
17+
18+
export function isver(version: string): boolean {
19+
return typeof parse(version) === 'object'
20+
}

0 commit comments

Comments
 (0)