-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from r7kamura/increment
Increment version by `release_type` input option
- Loading branch information
Showing
8 changed files
with
145 additions
and
13 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
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
File renamed without changes.
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,2 +1,5 @@ | ||
export * as core from "https://esm.sh/@actions/[email protected]?dts"; | ||
export * as exec from "https://esm.sh/@actions/[email protected]?dts"; | ||
export * as github from "https://esm.sh/@actions/[email protected]?dts"; | ||
export * as semver from "https://esm.sh/[email protected]?dts"; | ||
export * as asserts from "https://deno.land/[email protected]/testing/asserts.ts"; |
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,54 @@ | ||
import { core } from "./deps.ts"; | ||
import { github } from "./deps.ts"; | ||
import { fetchLatestRelease } from "./github.ts"; | ||
import { incrementVersion } from "./versioning.ts"; | ||
|
||
const forcedVersion = Deno.env.get("BUMP_REQUEST_INPUTS_VERSION"); | ||
const releaseType = Deno.env.get("BUMP_REQUEST_INPUTS_RELEASE_TYPE"); | ||
const githubToken = Deno.env.get("GITHUB_TOKEN")!; | ||
|
||
if (!forcedVersion && !releaseType) { | ||
throw new Error( | ||
"Specify either `release_type` or `version`.", | ||
); | ||
} | ||
|
||
if (releaseType) { | ||
if (!["major", "minor", "patch"].includes(releaseType)) { | ||
throw new Error( | ||
"`release_type` must be one of `major`, `minor`, or `patch`.", | ||
); | ||
} | ||
} | ||
|
||
core.setOutput( | ||
"version", | ||
await detectNextVersion({ | ||
githubToken, | ||
githubOwner: github.context.repo.owner, | ||
githubRepo: github.context.repo.repo, | ||
releaseType: releaseType!, | ||
}), | ||
); | ||
|
||
async function detectNextVersion({ | ||
githubToken, | ||
githubOwner, | ||
githubRepo, | ||
releaseType, | ||
}: { | ||
githubToken: string; | ||
githubOwner: string; | ||
githubRepo: string; | ||
releaseType: string; | ||
}) { | ||
const response = await fetchLatestRelease({ | ||
githubToken, | ||
owner: githubOwner, | ||
repo: githubRepo, | ||
}); | ||
return incrementVersion({ | ||
version: response.data.tag_name, | ||
releaseType, | ||
}); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { semver } from "./deps.ts"; | ||
import { asserts } from "./deps.ts"; | ||
|
||
export function incrementVersion({ | ||
version, | ||
releaseType, | ||
}: { | ||
version: string; | ||
releaseType: string; | ||
}) { | ||
return semver.inc( | ||
version, | ||
releaseType as semver.ReleaseType, | ||
); | ||
} | ||
|
||
Deno.test("incrementVersion", () => { | ||
asserts.assertEquals( | ||
incrementVersion({ | ||
version: "1.0.0", | ||
releaseType: "major", | ||
}), | ||
"2.0.0", | ||
); | ||
asserts.assertEquals( | ||
incrementVersion({ | ||
version: "v1.0.0", | ||
releaseType: "minor", | ||
}), | ||
"1.1.0", | ||
); | ||
}); |