-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
fix: do not mark github release as latest if higher version exists #69
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { rest } from 'msw' | ||
import { DeferredPromise } from '@open-draft/deferred-promise' | ||
import { testEnvironment } from '../../../../test/env' | ||
import { mockRepo } from '../../../../test/fixtures' | ||
import type { GitHubRelease } from '../getGitHubRelease' | ||
import { createGitHubRelease } from '../createGitHubRelease' | ||
|
||
const { setup, reset, cleanup, api } = testEnvironment({ | ||
fileSystemPath: 'create-github-release', | ||
}) | ||
|
||
beforeAll(async () => { | ||
await setup() | ||
}) | ||
|
||
afterEach(async () => { | ||
await reset() | ||
}) | ||
|
||
afterAll(async () => { | ||
await cleanup() | ||
}) | ||
|
||
it('marks the release as non-latest if there is a higher version released on GitHub', async () => { | ||
const repo = mockRepo() | ||
const requestBodyPromise = new DeferredPromise() | ||
api.use( | ||
rest.get<never, never, GitHubRelease>( | ||
`https://api.github.com/repos/:owner/:name/releases/latest`, | ||
(req, res, ctx) => { | ||
return res( | ||
// Set the latest GitHub release as v2.0.0. | ||
ctx.json({ | ||
tag_name: 'v2.0.0', | ||
html_url: '/v2.0.0', | ||
}), | ||
) | ||
}, | ||
), | ||
rest.post<never, never, GitHubRelease>( | ||
`https://api.github.com/repos/:owner/:name/releases`, | ||
(req, res, ctx) => { | ||
requestBodyPromise.resolve(req.json()) | ||
return res( | ||
ctx.status(201), | ||
ctx.json({ | ||
tag_name: 'v1.1.1', | ||
html_url: '/v1.1.1', | ||
}), | ||
) | ||
}, | ||
), | ||
) | ||
|
||
// Try to release a backport version for v1.0.0. | ||
const notes = '# Release notes' | ||
const githubRelease = await createGitHubRelease( | ||
{ | ||
repo, | ||
nextRelease: { | ||
version: '1.1.1', | ||
tag: 'v1.1.1', | ||
publishedAt: new Date(), | ||
}, | ||
}, | ||
notes, | ||
) | ||
expect(githubRelease).toHaveProperty('html_url', '/v1.1.1') | ||
|
||
const requestBody = await requestBodyPromise | ||
expect(requestBody).toEqual({ | ||
tag_name: 'v1.1.1', | ||
name: 'v1.1.1', | ||
body: notes, | ||
// Must set "false" as the value of the "make_latest" property. | ||
make_latest: 'false', | ||
}) | ||
}) |
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,11 +1,14 @@ | ||
import fetch from 'node-fetch' | ||
import { format } from 'outvariant' | ||
import { lt } from 'semver' | ||
import type { ReleaseContext } from '../createContext' | ||
import type { GitHubRelease } from './getGitHubRelease' | ||
import { getGitHubRelease, type GitHubRelease } from './getGitHubRelease' | ||
import { log } from '../../logger' | ||
|
||
/** | ||
* Create a new GitHub release with the given release notes. | ||
* This is only called if there's no existing GitHub release | ||
* for the next release tag. | ||
* @return {string} The URL of the newly created release. | ||
*/ | ||
export async function createGitHubRelease( | ||
|
@@ -22,6 +25,20 @@ export async function createGitHubRelease( | |
), | ||
) | ||
|
||
// Determine if the next release should be marked as the | ||
// latest release on GitHub. For that, fetch whichever latest | ||
// release exists on GitHub and see if its version is larger | ||
// than the version we are releasing right now. | ||
const latestGitHubRelease = await getGitHubRelease('latest') | ||
const shouldMarkAsLatest = latestGitHubRelease | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The actual fix. |
||
? lt(latestGitHubRelease.tag_name || '0.0.0', context.nextRelease.tag) | ||
: // Undefined is fine, it means GitHub will use its default | ||
// value for the "make_latest" property in the API. | ||
undefined | ||
|
||
/** | ||
* @see https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#create-a-release | ||
*/ | ||
const response = await fetch( | ||
`https://api.github.com/repos/${repo.owner}/${repo.name}/releases`, | ||
{ | ||
|
@@ -35,6 +52,7 @@ export async function createGitHubRelease( | |
tag_name: context.nextRelease.tag, | ||
name: context.nextRelease.tag, | ||
body: notes, | ||
make_latest: shouldMarkAsLatest?.toString(), | ||
}), | ||
}, | ||
) | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The confirming test suite.