Skip to content

Commit

Permalink
enable canary releases for upload-assets plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Jan 16, 2021
1 parent c8ea512 commit f06c870
Show file tree
Hide file tree
Showing 7 changed files with 663 additions and 83 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@
},
"auto": {
"plugins": [
[
"upload-assets",
[
"./packages/cli/binary/auto-linux.gz",
"./packages/cli/binary/auto-macos.gz",
"./packages/cli/binary/auto-win.exe.gz"
]
],
[
"npm",
{
Expand All @@ -158,14 +166,6 @@
}
}
],
[
"upload-assets",
[
"./packages/cli/binary/auto-linux.gz",
"./packages/cli/binary/auto-macos.gz",
"./packages/cli/binary/auto-win.exe.gz"
]
],
[
"brew",
{
Expand Down
Empty file removed packages/cli/auto
Empty file.
26 changes: 25 additions & 1 deletion plugins/upload-assets/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Upload Assets Plugin

Upload assets to the release. Good for executables and extra downloadable files.
Upload assets to the release.
Good for executables and extra downloadable files.
Also supports canaries!

> NOTE: For canaries to work this plugin must be listed before any other publishing plugin.
## Installation

Expand All @@ -27,3 +31,23 @@ Simply supply the paths to the assets to add to the release.
]
}
```

## Options

### `maxCanaryAssets`

Max number of assets to keep in the canary release.

```json
{
"plugins": [
[
"upload-assets",
{
"assets": ["./path/to/file"],
"maxAssets": 100
}
]
]
}
```
70 changes: 70 additions & 0 deletions plugins/upload-assets/__tests__/upload-assets-ci.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import envCi from "env-ci";

jest.mock("env-ci");

const envSpy = envCi as jest.Mock;
envSpy.mockImplementation(() => ({
isCi: true,
pr: 123,
}));

import Auto, { SEMVER } from "@auto-it/core";
import { makeHooks } from "@auto-it/core/dist/utils/make-hooks";
import path from "path";

import { dummyLog } from "@auto-it/core/dist/utils/logger";
import UploadAssets from "../src";
import endent from "endent";

const options = {
owner: "test",
repo: "repo",
};

jest.spyOn(console, "log").mockImplementation();

describe("Upload Assets Plugin", () => {
test("should add to pr body for pull requests", async () => {
const plugin = new UploadAssets([
path.join(__dirname, "./test-assets/macos"),
]);
const hooks = makeHooks();
const uploadReleaseAsset = jest
.fn()
.mockImplementation(({ name }) =>
Promise.resolve({
data: { id: 2, name, browser_download_url: `http://${name}` },
})
);
const createRelease = jest.fn().mockResolvedValue({ data: { id: 1 } });
const addToPrBody = jest.fn();

plugin.apply(({
hooks,
logger: dummyLog(),
git: {
options,
addToPrBody,
github: {
repos: { uploadReleaseAsset, createRelease },
paginate: jest.fn().mockResolvedValue([]),
},
},
} as unknown) as Auto);

await hooks.canary.promise({
canaryIdentifier: "canary.123",
bump: SEMVER.patch,
});

expect(addToPrBody).toHaveBeenCalledWith(
endent`
:baby_chick: Download canary assets:
[macos-canary.123](http://macos-canary.123)
`,
123,
"canary-assets"
);
});
});
Loading

0 comments on commit f06c870

Please sign in to comment.