mirror of
https://github.com/softprops/action-gh-release.git
synced 2025-10-09 08:56:12 +00:00
Fix Issue #616: Handle 422 already_exists race condition in matrix workflows
- Add retry logic for 422 'already_exists' errors in race conditions - Allow action to find and update existing releases instead of failing - Add test to verify race condition handling works correctly - Fixes regression that broke matrix workflows in v2.2.2+ Resolves: #616
This commit is contained in:
parent
97d42c1b50
commit
ef35f35317
3 changed files with 92 additions and 4 deletions
|
@ -1,4 +1,11 @@
|
|||
import { asset, findTagFromReleases, mimeOrDefault, Release, Releaser } from '../src/github';
|
||||
import {
|
||||
asset,
|
||||
findTagFromReleases,
|
||||
mimeOrDefault,
|
||||
release,
|
||||
Release,
|
||||
Releaser,
|
||||
} from '../src/github';
|
||||
|
||||
import { assert, describe, it } from 'vitest';
|
||||
|
||||
|
@ -227,4 +234,75 @@ describe('github', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('error handling', () => {
|
||||
it('handles 422 already_exists error gracefully', async () => {
|
||||
const mockReleaser: Releaser = {
|
||||
getReleaseByTag: () => Promise.reject('Not implemented'),
|
||||
createRelease: () =>
|
||||
Promise.reject({
|
||||
status: 422,
|
||||
response: { data: { errors: [{ code: 'already_exists' }] } },
|
||||
}),
|
||||
updateRelease: () =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
id: 1,
|
||||
upload_url: 'test',
|
||||
html_url: 'test',
|
||||
tag_name: 'v1.0.0',
|
||||
name: 'test',
|
||||
body: 'test',
|
||||
target_commitish: 'main',
|
||||
draft: false,
|
||||
prerelease: false,
|
||||
assets: [],
|
||||
},
|
||||
}),
|
||||
allReleases: async function* () {
|
||||
yield {
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
upload_url: 'test',
|
||||
html_url: 'test',
|
||||
tag_name: 'v1.0.0',
|
||||
name: 'test',
|
||||
body: 'test',
|
||||
target_commitish: 'main',
|
||||
draft: false,
|
||||
prerelease: false,
|
||||
assets: [],
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
} as const;
|
||||
|
||||
const config = {
|
||||
github_token: 'test-token',
|
||||
github_ref: 'refs/tags/v1.0.0',
|
||||
github_repository: 'owner/repo',
|
||||
input_tag_name: undefined,
|
||||
input_name: undefined,
|
||||
input_body: undefined,
|
||||
input_body_path: undefined,
|
||||
input_files: [],
|
||||
input_draft: undefined,
|
||||
input_prerelease: undefined,
|
||||
input_preserve_order: undefined,
|
||||
input_overwrite_files: undefined,
|
||||
input_fail_on_unmatched_files: false,
|
||||
input_target_commitish: undefined,
|
||||
input_discussion_category_name: undefined,
|
||||
input_generate_release_notes: false,
|
||||
input_append_body: false,
|
||||
input_make_latest: undefined,
|
||||
};
|
||||
|
||||
const result = await release(config, mockReleaser, 1);
|
||||
assert.ok(result);
|
||||
assert.equal(result.id, 1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue