Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added preRelease flag to release task #19

Merged
merged 2 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:

- `task` (required): Must be `release`.
- `token` (required): GitHub token.
- `preRelease` (optional): Mark or not the release as pre-release. If not defined, detect the right value automatically from the version, [by following Marp project guideline.](https://github.com/marp-team/.github/blob/master/CONTRIBUTING.md#pre-release)

<!--
- `convertGitHubMention` (optional: `true` by default): Set whether to convert Markdown links to GitHub profile like `[@marp-team](https://github.com/marp-team/)` into a plain GitHub mention.
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ inputs:
required: true

# "release" task
convertGitHubMention:
description: Set whether to convert Markdown links to GitHub profile into a plain GitHub mention
preRelease:
description: Mark the release as pre-release

# "upload" task
files:
Expand Down
13 changes: 12 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@ import release from './tasks/release'
import upload from './tasks/upload'

const get = (name: string, required = true) => core.getInput(name, { required })
const getBoolean = (name: string, required = true) => {
const val = get(name, required).toLowerCase()

if (val === 'true') return true
if (val === 'false') return false

return undefined
}

async function run() {
try {
switch (get('task')) {
case 'release':
await release({ token: get('token') })
await release({
token: get('token'),
preRelease: getBoolean('preRelease', false),
})
break
case 'upload':
await upload({ token: get('token'), files: get('files').split(',') })
Expand Down
8 changes: 7 additions & 1 deletion src/tasks/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export type ReleaseOptions = {
/** Target version tag. We will use the name tagged in the current action if empty. */
version?: string

/** Mark the release as pre-release. If not defined, detect the right value automatically from the version, by following Marp project guideline. */
preRelease?: boolean

/** Convert Markdown link to GitHub profile into the mention link of GitHub. */
convertGitHubMention?: boolean
}
Expand All @@ -19,6 +22,7 @@ export type ReleaseOptions = {
export default async function release({
token,
version: _version,
preRelease = undefined,
convertGitHubMention = true,
}: ReleaseOptions) {
const octokit = getOctokit(token)
Expand All @@ -28,6 +32,8 @@ export default async function release({
if (context.ref.startsWith('refs/tags/')) return context.ref.slice(10)
throw new Error('Release task failed to detect the target version.')
})()
const isPreRelease =
preRelease !== undefined ? preRelease : version.startsWith('v0.0.')

// Parse CHANGELOG.md
const changelog = path.resolve(process.cwd(), 'CHANGELOG.md')
Expand Down Expand Up @@ -64,7 +70,7 @@ export default async function release({
body,
name: version,
owner: context.repo.owner,
prerelease: version.startsWith('v0.0.'),
prerelease: isPreRelease,
repo: context.repo.repo,
tag_name: version,
})
Expand Down