Skip to content

Commit

Permalink
Merge pull request #16 from mikepenz/other/use_github_request_api
Browse files Browse the repository at this point in the history
Offer setting to `make_latest`
  • Loading branch information
mikepenz committed Mar 14, 2024
2 parents 51db930 + 1168a0d commit 9a604af
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ The following are optional as `step.with` keys
| `fail_on_asset_upload_issue` | Boolean | Indicator of whether to fail if any of the `assets` fails to upload |
| `repository` | String | Name of a target repository in `<owner>/<repo>` format. Defaults to GITHUB_REPOSITORY env variable |
| `target_commitish` | String | Commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Defaults to repository default branch. |
| `make_latest` | String | Configuration to make the new release the latest. Defaults to 'true'. Can be one of: 'true', 'false', 'legacy' branch. |
| `token` | String | Secret GitHub Personal Access Token. Defaults to `${{ github.token }}` |
| `discussion_category_name` | String | If specified, a discussion of the specified category is created and linked to the release. The value must be a category that already exists in the repository. For more information, see ["Managing categories for discussions in your repository."](https://docs.github.com/en/discussions/managing-discussions-for-your-community/managing-categories-for-discussions-in-your-repository) |
| `generate_release_notes` | Boolean | Whether to automatically generate the name and body for this release. If name is specified, the specified name will be used; otherwise, a name will be automatically generated. If body is specified, the body will be pre-pended to the automatically generated notes. See the [GitHub docs for this feature](https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes) for more information |
Expand Down
33 changes: 22 additions & 11 deletions __tests__/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ describe('util', () => {
input_tag_name: undefined,
input_target_commitish: undefined,
input_discussion_category_name: undefined,
input_generate_release_notes: false
input_generate_release_notes: false,
input_make_latest: 'true'
})
)
})
Expand All @@ -65,7 +66,8 @@ describe('util', () => {
input_tag_name: undefined,
input_target_commitish: undefined,
input_discussion_category_name: undefined,
input_generate_release_notes: false
input_generate_release_notes: false,
input_make_latest: 'true'
})
)
})
Expand All @@ -85,7 +87,8 @@ describe('util', () => {
input_tag_name: undefined,
input_target_commitish: undefined,
input_discussion_category_name: undefined,
input_generate_release_notes: false
input_generate_release_notes: false,
input_make_latest: 'true'
})
)
})
Expand Down Expand Up @@ -119,7 +122,8 @@ describe('util', () => {
input_fail_on_asset_upload_issue: false,
input_target_commitish: undefined,
input_discussion_category_name: undefined,
input_generate_release_notes: false
input_generate_release_notes: false,
input_make_latest: 'true'
}
)
})
Expand All @@ -145,7 +149,8 @@ describe('util', () => {
input_fail_on_asset_upload_issue: false,
input_target_commitish: 'affa18ef97bc9db20076945705aba8c516139abd',
input_discussion_category_name: undefined,
input_generate_release_notes: false
input_generate_release_notes: false,
input_make_latest: 'true'
}
)
})
Expand All @@ -170,7 +175,8 @@ describe('util', () => {
input_fail_on_asset_upload_issue: false,
input_target_commitish: undefined,
input_discussion_category_name: 'releases',
input_generate_release_notes: false
input_generate_release_notes: false,
input_make_latest: 'true'
}
)
})
Expand All @@ -196,7 +202,8 @@ describe('util', () => {
input_fail_on_asset_upload_issue: false,
input_target_commitish: undefined,
input_discussion_category_name: undefined,
input_generate_release_notes: true
input_generate_release_notes: true,
input_make_latest: 'true'
}
)
})
Expand Down Expand Up @@ -225,7 +232,8 @@ describe('util', () => {
input_fail_on_asset_upload_issue: false,
input_target_commitish: undefined,
input_discussion_category_name: undefined,
input_generate_release_notes: false
input_generate_release_notes: false,
input_make_latest: 'true'
}
)
})
Expand All @@ -252,7 +260,8 @@ describe('util', () => {
input_fail_on_asset_upload_issue: false,
input_target_commitish: undefined,
input_discussion_category_name: undefined,
input_generate_release_notes: false
input_generate_release_notes: false,
input_make_latest: 'true'
}
)
})
Expand All @@ -278,7 +287,8 @@ describe('util', () => {
input_fail_on_asset_upload_issue: false,
input_target_commitish: undefined,
input_discussion_category_name: undefined,
input_generate_release_notes: false
input_generate_release_notes: false,
input_make_latest: 'true'
}
)
})
Expand All @@ -303,7 +313,8 @@ describe('util', () => {
input_fail_on_asset_upload_issue: false,
input_target_commitish: undefined,
input_discussion_category_name: undefined,
input_generate_release_notes: false
input_generate_release_notes: false,
input_make_latest: 'true'
}
)
})
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ inputs:
append_body:
description: "Append to existing body instead of overwriting it. Default is false."
required: false
make_latest:
description: "Wheter to make the new release the latest. Default is 'true'. Can be one of: 'true', 'false', 'legacy'"
required: false
env:
"GITHUB_TOKEN": "As provided by Github Actions"
outputs:
Expand Down
12 changes: 9 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ const release = async (config, releaser, maxRetries = 3) => {
}
const draft = config.input_draft !== undefined ? config.input_draft : existingRelease.draft;
const prerelease = config.input_prerelease !== undefined ? config.input_prerelease : existingRelease.prerelease;
const make_latest = config.input_make_latest;
const rel = await releaser.updateRelease({
owner,
repo,
Expand All @@ -191,7 +192,8 @@ const release = async (config, releaser, maxRetries = 3) => {
draft,
prerelease,
discussion_category_name,
generate_release_notes
generate_release_notes,
make_latest
});
return rel.data;
}
Expand All @@ -203,6 +205,7 @@ const release = async (config, releaser, maxRetries = 3) => {
const draft = config.input_draft;
const prerelease = config.input_prerelease;
const target_commitish = config.input_target_commitish;
const make_latest = config.input_make_latest;
let commitMessage = '';
if (target_commitish) {
commitMessage = ` using commit "${target_commitish}"`;
Expand All @@ -219,7 +222,8 @@ const release = async (config, releaser, maxRetries = 3) => {
prerelease,
target_commitish,
discussion_category_name,
generate_release_notes
generate_release_notes,
make_latest
});
return newRelease.data;
}
Expand Down Expand Up @@ -398,6 +402,7 @@ const parseInputFiles = (files) => {
};
exports.parseInputFiles = parseInputFiles;
const parseConfig = (env) => {
const ml = env.INPUT_MAKE_LATEST;
return {
github_token: env.GITHUB_TOKEN || env.INPUT_TOKEN || '',
github_ref: env.GITHUB_REF || '',
Expand All @@ -414,7 +419,8 @@ const parseConfig = (env) => {
input_target_commitish: env.INPUT_TARGET_COMMITISH || undefined,
input_discussion_category_name: env.INPUT_DISCUSSION_CATEGORY_NAME || undefined,
input_generate_release_notes: env.INPUT_GENERATE_RELEASE_NOTES === 'true',
input_append_body: env.INPUT_APPEND_BODY === 'true'
input_append_body: env.INPUT_APPEND_BODY === 'true',
input_make_latest: ml === 'false' ? 'false' : ml === 'legacy' ? 'legacy' : 'true'
};
};
exports.parseConfig = parseConfig;
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface Releaser {
target_commitish: string | undefined
discussion_category_name: string | undefined
generate_release_notes: boolean | undefined
make_latest: 'true' | 'false' | 'legacy'
}): Promise<{data: Release}>

updateRelease(params: {
Expand All @@ -55,6 +56,7 @@ export interface Releaser {
prerelease: boolean | undefined
discussion_category_name: string | undefined
generate_release_notes: boolean | undefined
make_latest: 'true' | 'false' | 'legacy'
}): Promise<{data: Release}>

allReleases(params: {owner: string; repo: string}): AsyncIterableIterator<{data: Release[]}>
Expand Down Expand Up @@ -244,6 +246,7 @@ export const release = async (config: Config, releaser: Releaser, maxRetries = 3

const draft = config.input_draft !== undefined ? config.input_draft : existingRelease.draft
const prerelease = config.input_prerelease !== undefined ? config.input_prerelease : existingRelease.prerelease
const make_latest = config.input_make_latest

const rel = await releaser.updateRelease({
owner,
Expand All @@ -256,7 +259,8 @@ export const release = async (config: Config, releaser: Releaser, maxRetries = 3
draft,
prerelease,
discussion_category_name,
generate_release_notes
generate_release_notes,
make_latest
})
return rel.data
} catch (error: any) {
Expand All @@ -267,6 +271,7 @@ export const release = async (config: Config, releaser: Releaser, maxRetries = 3
const draft = config.input_draft
const prerelease = config.input_prerelease
const target_commitish = config.input_target_commitish
const make_latest = config.input_make_latest
let commitMessage = ''
if (target_commitish) {
commitMessage = ` using commit "${target_commitish}"`
Expand All @@ -283,7 +288,8 @@ export const release = async (config: Config, releaser: Releaser, maxRetries = 3
prerelease,
target_commitish,
discussion_category_name,
generate_release_notes
generate_release_notes,
make_latest
})
return newRelease.data
} catch (newError) {
Expand Down
5 changes: 4 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Config {
input_discussion_category_name?: string
input_generate_release_notes?: boolean
input_append_body?: boolean
input_make_latest: 'true' | 'false' | 'legacy'
}

export const uploadUrl = (url: string): string => {
Expand Down Expand Up @@ -48,6 +49,7 @@ export const parseInputFiles = (files: string): string[] => {
}

export const parseConfig = (env: Env): Config => {
const ml = env.INPUT_MAKE_LATEST
return {
github_token: env.GITHUB_TOKEN || env.INPUT_TOKEN || '',
github_ref: env.GITHUB_REF || '',
Expand All @@ -64,7 +66,8 @@ export const parseConfig = (env: Env): Config => {
input_target_commitish: env.INPUT_TARGET_COMMITISH || undefined,
input_discussion_category_name: env.INPUT_DISCUSSION_CATEGORY_NAME || undefined,
input_generate_release_notes: env.INPUT_GENERATE_RELEASE_NOTES === 'true',
input_append_body: env.INPUT_APPEND_BODY === 'true'
input_append_body: env.INPUT_APPEND_BODY === 'true',
input_make_latest: ml === 'false' ? 'false' : ml === 'legacy' ? 'legacy' : 'true'
}
}

Expand Down

0 comments on commit 9a604af

Please sign in to comment.