mirror of
https://github.com/softprops/action-gh-release.git
synced 2026-03-15 09:20:54 -04:00
fix: handle upload already_exists races across workflows (#745)
* Handle upload already_exists races across workflows * fix: rebase duplicate asset race handling Signed-off-by: Rui Chen <rui@chenrui.dev> --------- Signed-off-by: Rui Chen <rui@chenrui.dev> Co-authored-by: Aditya Inamdar <api2062@Adityas-MacBook-Air.local> Co-authored-by: Rui Chen <rui@chenrui.dev>
This commit is contained in:
@@ -279,6 +279,56 @@ describe('github', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('retries upload after deleting conflicting asset on 422 already_exists race', async () => {
|
||||
const uploadReleaseAsset = vi
|
||||
.fn()
|
||||
.mockRejectedValueOnce({
|
||||
status: 422,
|
||||
response: { data: { errors: [{ code: 'already_exists' }] } },
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
status: 201,
|
||||
data: { id: 123, name: 'release.txt' },
|
||||
});
|
||||
|
||||
const listReleaseAssets = vi.fn().mockResolvedValue([{ id: 99, name: 'release.txt' }]);
|
||||
const deleteReleaseAsset = vi.fn().mockResolvedValue(undefined);
|
||||
|
||||
const mockReleaser: Releaser = {
|
||||
getReleaseByTag: () => Promise.reject('Not implemented'),
|
||||
createRelease: () => Promise.reject('Not implemented'),
|
||||
updateRelease: () => Promise.reject('Not implemented'),
|
||||
finalizeRelease: () => Promise.reject('Not implemented'),
|
||||
allReleases: async function* () {
|
||||
throw new Error('Not implemented');
|
||||
},
|
||||
listReleaseAssets,
|
||||
deleteReleaseAsset,
|
||||
uploadReleaseAsset,
|
||||
};
|
||||
|
||||
const result = await upload(
|
||||
config,
|
||||
mockReleaser,
|
||||
'https://uploads.github.com/repos/owner/repo/releases/1/assets',
|
||||
'__tests__/release.txt',
|
||||
[],
|
||||
);
|
||||
|
||||
expect(result).toStrictEqual({ id: 123, name: 'release.txt' });
|
||||
expect(listReleaseAssets).toHaveBeenCalledWith({
|
||||
owner: 'owner',
|
||||
repo: 'repo',
|
||||
release_id: 1,
|
||||
});
|
||||
expect(deleteReleaseAsset).toHaveBeenCalledWith({
|
||||
owner: 'owner',
|
||||
repo: 'repo',
|
||||
asset_id: 99,
|
||||
});
|
||||
expect(uploadReleaseAsset).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('handles 422 already_exists error gracefully', async () => {
|
||||
const existingRelease = {
|
||||
id: 1,
|
||||
|
||||
Reference in New Issue
Block a user