diff --git a/packages/cli/package.json b/packages/cli/package.json index 88dfef566..551012c60 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -49,10 +49,10 @@ "gzip": "ls binary/auto* | xargs gzip" }, "dependencies": { - "@auto-it/core": "link:../core", - "@auto-it/npm": "link:../../plugins/npm", - "@auto-it/released": "link:../../plugins/released", - "@auto-it/version-file": "link:../../plugins/version-file", + "@auto-it/core": "file:../core", + "@auto-it/npm": "file:../../plugins/npm", + "@auto-it/released": "file:../../plugins/released", + "@auto-it/version-file": "file:../../plugins/version-file", "await-to-js": "^3.0.0", "chalk": "^4.0.0", "command-line-application": "^0.10.1", diff --git a/packages/core/package.json b/packages/core/package.json index 1ef7c2803..35e004e53 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -37,7 +37,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/bot-list": "link:../../packages/bot-list", + "@auto-it/bot-list": "file:../../packages/bot-list", "@endemolshinegroup/cosmiconfig-typescript-loader": "^3.0.2", "@octokit/core": "^3.5.1", "@octokit/plugin-enterprise-compatibility": "1.3.0", diff --git a/plugins/all-contributors/package.json b/plugins/all-contributors/package.json index e9d948bc5..5e94c2239 100644 --- a/plugins/all-contributors/package.json +++ b/plugins/all-contributors/package.json @@ -37,8 +37,8 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/bot-list": "link:../../packages/bot-list", - "@auto-it/core": "link:../../packages/core", + "@auto-it/bot-list": "file:../../packages/bot-list", + "@auto-it/core": "file:../../packages/core", "@octokit/rest": "^18.12.0", "all-contributors-cli": "6.19.0", "anymatch": "^3.1.1", diff --git a/plugins/brew/package.json b/plugins/brew/package.json index 7813dbf29..950014e3d 100644 --- a/plugins/brew/package.json +++ b/plugins/brew/package.json @@ -36,7 +36,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "fp-ts": "^2.5.3", "io-ts": "^2.1.2", "tslib": "2.1.0" diff --git a/plugins/chrome/package.json b/plugins/chrome/package.json index 48b199b3e..b7d164874 100644 --- a/plugins/chrome/package.json +++ b/plugins/chrome/package.json @@ -38,7 +38,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "chrome-webstore-upload-cli": "^1.2.0", "fp-ts": "^2.5.3", "io-ts": "^2.1.2", diff --git a/plugins/cocoapods/package.json b/plugins/cocoapods/package.json index 448b5748d..8316ba293 100644 --- a/plugins/cocoapods/package.json +++ b/plugins/cocoapods/package.json @@ -36,7 +36,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "fp-ts": "^2.5.3", "io-ts": "^2.1.2", "semver": "^7.1.3", diff --git a/plugins/conventional-commits/package.json b/plugins/conventional-commits/package.json index d5be6cb8f..5f589791d 100644 --- a/plugins/conventional-commits/package.json +++ b/plugins/conventional-commits/package.json @@ -37,7 +37,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "array.prototype.flatmap": "^1.2.2", "conventional-changelog-core": "^4.2.0", "conventional-changelog-preset-loader": "^2.3.4", diff --git a/plugins/crates/package.json b/plugins/crates/package.json index 437360a00..7b71e87f5 100644 --- a/plugins/crates/package.json +++ b/plugins/crates/package.json @@ -38,7 +38,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "env-ci": "^5.0.1", "semver": "^7.0.0", "toml": "^3.0.0", diff --git a/plugins/docker/package.json b/plugins/docker/package.json index 2c9a735cb..369eb0336 100644 --- a/plugins/docker/package.json +++ b/plugins/docker/package.json @@ -37,7 +37,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "fp-ts": "^2.5.3", "io-ts": "^2.1.2", "semver": "^7.0.0", diff --git a/plugins/exec/package.json b/plugins/exec/package.json index 70a6d6816..5c45241bc 100644 --- a/plugins/exec/package.json +++ b/plugins/exec/package.json @@ -36,7 +36,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "endent": "^2.1.0", "fp-ts": "^2.5.3", "fromentries": "^1.2.0", diff --git a/plugins/first-time-contributor/package.json b/plugins/first-time-contributor/package.json index 5a6aa2f02..e4edc4447 100644 --- a/plugins/first-time-contributor/package.json +++ b/plugins/first-time-contributor/package.json @@ -36,8 +36,8 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/bot-list": "link:../../packages/bot-list", - "@auto-it/core": "link:../../packages/core", + "@auto-it/bot-list": "file:../../packages/bot-list", + "@auto-it/core": "file:../../packages/core", "array.prototype.flatmap": "^1.2.2", "endent": "^2.1.0", "tslib": "2.1.0", diff --git a/plugins/gem/package.json b/plugins/gem/package.json index febfe45a9..12a875b91 100644 --- a/plugins/gem/package.json +++ b/plugins/gem/package.json @@ -36,7 +36,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "endent": "^2.1.0", "env-ci": "^5.0.1", "fast-glob": "^3.1.1", diff --git a/plugins/gh-pages/package.json b/plugins/gh-pages/package.json index 06125c432..a9a42c70c 100644 --- a/plugins/gh-pages/package.json +++ b/plugins/gh-pages/package.json @@ -36,7 +36,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "endent": "^2.1.0", "fp-ts": "^2.5.3", "io-ts": "^2.1.2", diff --git a/plugins/git-tag/package.json b/plugins/git-tag/package.json index 72ef198aa..5d1716e24 100644 --- a/plugins/git-tag/package.json +++ b/plugins/git-tag/package.json @@ -36,7 +36,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "semver": "^7.0.0", "tslib": "2.1.0" }, diff --git a/plugins/gradle/package.json b/plugins/gradle/package.json index 56bf8231d..a4715f166 100644 --- a/plugins/gradle/package.json +++ b/plugins/gradle/package.json @@ -36,7 +36,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "fp-ts": "^2.5.3", "io-ts": "^2.1.2", "semver": "^7.0.0", diff --git a/plugins/jira/package.json b/plugins/jira/package.json index 040158845..a1e6d572c 100644 --- a/plugins/jira/package.json +++ b/plugins/jira/package.json @@ -37,7 +37,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "enquirer": "^2.3.4", "fp-ts": "^2.5.3", "io-ts": "^2.1.2", diff --git a/plugins/magic-zero/package.json b/plugins/magic-zero/package.json index e612ba1af..60eed61de 100644 --- a/plugins/magic-zero/package.json +++ b/plugins/magic-zero/package.json @@ -36,7 +36,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "fp-ts": "^2.5.3", "io-ts": "^2.1.2", "semver": "^7.0.0", diff --git a/plugins/maven/package.json b/plugins/maven/package.json index fe47e4929..f6251d49a 100644 --- a/plugins/maven/package.json +++ b/plugins/maven/package.json @@ -38,7 +38,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "fast-glob": "^3.1.1", "fp-ts": "^2.5.3", "io-ts": "^2.1.2", diff --git a/plugins/microsoft-teams/package.json b/plugins/microsoft-teams/package.json index ca2e0bc61..fce0c3b8e 100644 --- a/plugins/microsoft-teams/package.json +++ b/plugins/microsoft-teams/package.json @@ -37,7 +37,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "fp-ts": "^2.5.3", "https-proxy-agent": "^5.0.0", "io-ts": "^2.1.2", diff --git a/plugins/npm/package.json b/plugins/npm/package.json index bd12489b3..9636c9e24 100644 --- a/plugins/npm/package.json +++ b/plugins/npm/package.json @@ -38,8 +38,8 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", - "@auto-it/package-json-utils": "link:../../packages/package-json-utils", + "@auto-it/core": "file:../../packages/core", + "@auto-it/package-json-utils": "file:../../packages/package-json-utils", "await-to-js": "^3.0.0", "endent": "^2.1.0", "env-ci": "^5.0.1", diff --git a/plugins/omit-commits/package.json b/plugins/omit-commits/package.json index 70db89fe2..42ff5038a 100644 --- a/plugins/omit-commits/package.json +++ b/plugins/omit-commits/package.json @@ -38,7 +38,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "fp-ts": "^2.5.3", "io-ts": "^2.1.2", "tslib": "2.1.0" diff --git a/plugins/omit-release-notes/package.json b/plugins/omit-release-notes/package.json index d40eeda54..6f4d22e63 100644 --- a/plugins/omit-release-notes/package.json +++ b/plugins/omit-release-notes/package.json @@ -38,7 +38,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "fp-ts": "^2.5.3", "io-ts": "^2.1.2", "tslib": "2.1.0" diff --git a/plugins/pr-body-labels/package.json b/plugins/pr-body-labels/package.json index b98f3dd6d..e991d693e 100644 --- a/plugins/pr-body-labels/package.json +++ b/plugins/pr-body-labels/package.json @@ -36,7 +36,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "fp-ts": "^2.5.3", "io-ts": "^2.1.2", "tslib": "2.1.0" diff --git a/plugins/protected-branch/package.json b/plugins/protected-branch/package.json index a3524eb44..76da90568 100644 --- a/plugins/protected-branch/package.json +++ b/plugins/protected-branch/package.json @@ -36,7 +36,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "@octokit/rest": "^18.12.0", "fp-ts": "^2.5.3", "io-ts": "^2.1.2", diff --git a/plugins/released/package.json b/plugins/released/package.json index 19a9a5319..21400c4af 100644 --- a/plugins/released/package.json +++ b/plugins/released/package.json @@ -38,8 +38,8 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/bot-list": "link:../../packages/bot-list", - "@auto-it/core": "link:../../packages/core", + "@auto-it/bot-list": "file:../../packages/bot-list", + "@auto-it/core": "file:../../packages/core", "deepmerge": "^4.0.0", "fp-ts": "^2.5.3", "io-ts": "^2.1.2", diff --git a/plugins/s3/package.json b/plugins/s3/package.json index 00d156ccb..134053b7b 100644 --- a/plugins/s3/package.json +++ b/plugins/s3/package.json @@ -36,7 +36,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "aws-cli-js": "^2.0.6", "fp-ts": "^2.5.3", "io-ts": "^2.1.2", diff --git a/plugins/sbt/package.json b/plugins/sbt/package.json index 1683860d7..89551a050 100644 --- a/plugins/sbt/package.json +++ b/plugins/sbt/package.json @@ -38,7 +38,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "fp-ts": "^2.5.3", "io-ts": "^2.1.2", "semver": "^7.0.0", diff --git a/plugins/slack/package.json b/plugins/slack/package.json index 392857368..90c0a03a4 100644 --- a/plugins/slack/package.json +++ b/plugins/slack/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@atomist/slack-messages": "^1.2.2", - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "@octokit/rest": "^18.12.0", "fp-ts": "^2.5.3", "https-proxy-agent": "^5.0.0", diff --git a/plugins/twitter/package.json b/plugins/twitter/package.json index 2e904e1e2..eec7a5c13 100644 --- a/plugins/twitter/package.json +++ b/plugins/twitter/package.json @@ -38,7 +38,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "@types/twitter-text": "^3.1.0", "endent": "^2.1.0", "fp-ts": "^2.5.3", diff --git a/plugins/upload-assets/README.md b/plugins/upload-assets/README.md index 662dac7e1..ad898fb62 100644 --- a/plugins/upload-assets/README.md +++ b/plugins/upload-assets/README.md @@ -45,9 +45,147 @@ Max number of assets to keep in the canary release. "upload-assets", { "assets": ["./path/to/file"], - "maxAssets": 100 + "maxCanaryAssets": 100 } ] ] } ``` + +### `headerMessage` + +Custom message for header in Pull Requests. + +```json +{ + "plugins": [ + [ + "upload-assets", + { + "assets": ["./path/to/file"], + "headerMessage": "🚀 Download links canary assets with custom message:" + } + ] + ] +} +``` + +### `filter` + +Filter assets by regular expression. This check are using `test` method from RegEx object. + +```json +{ + "plugins": [ + [ + "upload-assets", + { + "assets": [ + "./test-assets/color_test.xml", + "./test-assets/typo_test.xml", + "./test-assets/shadow_test", + "./test-assets/macos" + ], + "filter": "(color).*\\.xml" + } + ] + ] +} +``` + +Get result: + +🐤 Download canary assets: + +[color_test-canary.123.xml](http://color_test-canary.123.xml) + +### `includeBotPrs` + +Whether to comment on Pull Requests made by bots. Default `true`. + +```json +{ + "plugins": [ + [ + "upload-assets", + { + "assets": ["./path/to/file"], + "includeBotPrs": false + } + ] + ] +} +``` + +### `group` + +Group assets by regular expression. This check are using `exec` method from RegEx object and get second output. + +```json +{ + "plugins": [ + [ + "upload-assets", + { + "assets": [ + "./test-assets/color_test.xml", + "./test-assets/shadow_test.xml", + "./test-assets/typo_test.xml" + ], + "group": "(color|shadow|typo).*\\.xml" + } + ] + ] +} +``` + +Get result: + +🐤 Download canary assets: + +### color + +[color_test-canary.123.xml](http://color_test-canary.123.xml) + +### shadow + +[shadow_test-canary.123.xml](http://shadow_test-canary.123.xml) + +### typo + +[typo_test-3-canary.123.xml](http://typo_test-3-canary.123.xml) + +### `compact` + +Compact view for Pull Requests comment. Default `false`. + +```json +{ + "plugins": [ + [ + "upload-assets", + { + "assets": [ + "./test-assets/color_test.xml", + "./test-assets/shadow_test.xml", + "./test-assets/typo_test.xml" + ], + "compact": "true" + } + ] + ] +} +``` + +Get result: + +```HTML +
+ :baby_chick: Download canary assets: +
+ color_test-canary.123.xml
+ shadow_test-canary.123.xml
+ typo_test-canary.123.xml
+
+
+``` diff --git a/plugins/upload-assets/__tests__/test-assets/color_test-2.xml b/plugins/upload-assets/__tests__/test-assets/color_test-2.xml new file mode 100755 index 000000000..381d92807 Binary files /dev/null and b/plugins/upload-assets/__tests__/test-assets/color_test-2.xml differ diff --git a/plugins/upload-assets/__tests__/test-assets/color_test-3.xml b/plugins/upload-assets/__tests__/test-assets/color_test-3.xml new file mode 100755 index 000000000..381d92807 Binary files /dev/null and b/plugins/upload-assets/__tests__/test-assets/color_test-3.xml differ diff --git a/plugins/upload-assets/__tests__/test-assets/color_test.xml b/plugins/upload-assets/__tests__/test-assets/color_test.xml new file mode 100755 index 000000000..381d92807 Binary files /dev/null and b/plugins/upload-assets/__tests__/test-assets/color_test.xml differ diff --git a/plugins/upload-assets/__tests__/test-assets/macos.xml b/plugins/upload-assets/__tests__/test-assets/macos.xml new file mode 100755 index 000000000..381d92807 Binary files /dev/null and b/plugins/upload-assets/__tests__/test-assets/macos.xml differ diff --git a/plugins/upload-assets/__tests__/test-assets/shadow_test-2.xml b/plugins/upload-assets/__tests__/test-assets/shadow_test-2.xml new file mode 100755 index 000000000..381d92807 Binary files /dev/null and b/plugins/upload-assets/__tests__/test-assets/shadow_test-2.xml differ diff --git a/plugins/upload-assets/__tests__/test-assets/shadow_test.xml b/plugins/upload-assets/__tests__/test-assets/shadow_test.xml new file mode 100755 index 000000000..381d92807 Binary files /dev/null and b/plugins/upload-assets/__tests__/test-assets/shadow_test.xml differ diff --git a/plugins/upload-assets/__tests__/test-assets/typo_test-2.xml b/plugins/upload-assets/__tests__/test-assets/typo_test-2.xml new file mode 100755 index 000000000..381d92807 Binary files /dev/null and b/plugins/upload-assets/__tests__/test-assets/typo_test-2.xml differ diff --git a/plugins/upload-assets/__tests__/test-assets/typo_test-3.xml b/plugins/upload-assets/__tests__/test-assets/typo_test-3.xml new file mode 100755 index 000000000..381d92807 Binary files /dev/null and b/plugins/upload-assets/__tests__/test-assets/typo_test-3.xml differ diff --git a/plugins/upload-assets/__tests__/test-assets/typo_test.xml b/plugins/upload-assets/__tests__/test-assets/typo_test.xml new file mode 100755 index 000000000..381d92807 Binary files /dev/null and b/plugins/upload-assets/__tests__/test-assets/typo_test.xml differ diff --git a/plugins/upload-assets/__tests__/upload-assets-ci.test.ts b/plugins/upload-assets/__tests__/upload-assets-ci.test.ts index aa689f682..2ce51983e 100644 --- a/plugins/upload-assets/__tests__/upload-assets-ci.test.ts +++ b/plugins/upload-assets/__tests__/upload-assets-ci.test.ts @@ -67,4 +67,347 @@ describe("Upload Assets Plugin", () => { "canary-assets" ); }); + + test("should add to pr body for pull requests with custom message", async () => { + const plugin = new UploadAssets({ + assets: [path.join(__dirname, "./test-assets/macos.xml")], + headerMessage: "🚀 Download links canary assets with custom message:", + }); + 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(), + prefixRelease: (v) => v, + git: { + options, + getFirstCommit: () => "abc", + 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` + 🚀 Download links canary assets with custom message: + + [macos-canary.123.xml](http://macos-canary.123.xml) + `, + 123, + "canary-assets" + ); + }); + + test("should add to pr body for pull requests with filter", async () => { + const plugin = new UploadAssets({ + assets: [ + path.join(__dirname, "./test-assets/color_test.xml"), + path.join(__dirname, "./test-assets/typo_test.xml"), + path.join(__dirname, "./test-assets/shadow_test.xml"), + path.join(__dirname, "./test-assets/macos.xml"), + path.join(__dirname, "./test-assets/macos"), + ], + filter: "(color|shadow|typo).*\\.xml", + }); + 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(), + prefixRelease: (v) => v, + git: { + options, + getFirstCommit: () => "abc", + 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: + + [color_test-canary.123.xml](http://color_test-canary.123.xml) + [typo_test-canary.123.xml](http://typo_test-canary.123.xml) + [shadow_test-canary.123.xml](http://shadow_test-canary.123.xml) + `, + 123, + "canary-assets" + ); + }); + + test("should not add to pr body for pull request", async () => { + const plugin = new UploadAssets({ + assets: [path.join(__dirname, "./test-assets/color_test.xml")], + includeBotPrs: false, + }); + 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(), + prefixRelease: (v) => v, + git: { + options, + getFirstCommit: () => "abc", + 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).not.toHaveBeenCalled(); + }); + + test("should add to pr body for pull requests with group", async () => { + const plugin = new UploadAssets({ + assets: [ + path.join(__dirname, "./test-assets/color_test.xml"), + path.join(__dirname, "./test-assets/shadow_test.xml"), + path.join(__dirname, "./test-assets/color_test-3.xml"), + path.join(__dirname, "./test-assets/typo_test-3.xml"), + path.join(__dirname, "./test-assets/shadow_test-2.xml"), + path.join(__dirname, "./test-assets/typo_test.xml"), + path.join(__dirname, "./test-assets/color_test-2.xml"), + path.join(__dirname, "./test-assets/typo_test-2.xml"), + ], + group: "(color|shadow|typo).*\\.xml", + }); + 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(), + prefixRelease: (v) => v, + git: { + options, + getFirstCommit: () => "abc", + 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: + + ### color + [color_test-canary.123.xml](http://color_test-canary.123.xml) + [color_test-3-canary.123.xml](http://color_test-3-canary.123.xml) + [color_test-2-canary.123.xml](http://color_test-2-canary.123.xml) + ### shadow + [shadow_test-canary.123.xml](http://shadow_test-canary.123.xml) + [shadow_test-2-canary.123.xml](http://shadow_test-2-canary.123.xml) + ### typo + [typo_test-3-canary.123.xml](http://typo_test-3-canary.123.xml) + [typo_test-canary.123.xml](http://typo_test-canary.123.xml) + [typo_test-2-canary.123.xml](http://typo_test-2-canary.123.xml) + `, + 123, + "canary-assets" + ); + }); + + test("should add to pr body for pull requests with compact message", async () => { + const plugin = new UploadAssets({ + assets: [ + path.join(__dirname, "./test-assets/color_test.xml"), + path.join(__dirname, "./test-assets/shadow_test.xml"), + path.join(__dirname, "./test-assets/color_test-3.xml"), + path.join(__dirname, "./test-assets/typo_test-3.xml"), + path.join(__dirname, "./test-assets/shadow_test-2.xml"), + path.join(__dirname, "./test-assets/typo_test.xml"), + path.join(__dirname, "./test-assets/color_test-2.xml"), + path.join(__dirname, "./test-assets/typo_test-2.xml"), + ], + compact: true, + }); + 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(), + prefixRelease: (v) => v, + git: { + options, + getFirstCommit: () => "abc", + 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: +
+ color_test-canary.123.xml
+ shadow_test-canary.123.xml
+ color_test-3-canary.123.xml
+ typo_test-3-canary.123.xml
+ shadow_test-2-canary.123.xml
+ typo_test-canary.123.xml
+ color_test-2-canary.123.xml
+ typo_test-2-canary.123.xml
+
+
+ `, + 123, + "canary-assets" + ); + }); + + test("should add to pr body for pull requests with group and compact message", async () => { + const plugin = new UploadAssets({ + assets: [ + path.join(__dirname, "./test-assets/color_test.xml"), + path.join(__dirname, "./test-assets/shadow_test.xml"), + path.join(__dirname, "./test-assets/color_test-3.xml"), + path.join(__dirname, "./test-assets/typo_test-3.xml"), + path.join(__dirname, "./test-assets/shadow_test-2.xml"), + path.join(__dirname, "./test-assets/typo_test.xml"), + path.join(__dirname, "./test-assets/color_test-2.xml"), + path.join(__dirname, "./test-assets/typo_test-2.xml"), + ], + group: "(color|shadow|typo).*\\.xml", + compact: true, + }); + 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(), + prefixRelease: (v) => v, + git: { + options, + getFirstCommit: () => "abc", + 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: +
+
+ color +
+ color_test-canary.123.xml
+ color_test-3-canary.123.xml
+ color_test-2-canary.123.xml
+
+
+
+ shadow +
+ shadow_test-canary.123.xml
+ shadow_test-2-canary.123.xml
+
+
+
+ typo +
+ typo_test-3-canary.123.xml
+ typo_test-canary.123.xml
+ typo_test-2-canary.123.xml
+
+
+
+
+ `, + 123, + "canary-assets" + ); + }); }); diff --git a/plugins/upload-assets/package.json b/plugins/upload-assets/package.json index 56899b1cf..e6fb49470 100644 --- a/plugins/upload-assets/package.json +++ b/plugins/upload-assets/package.json @@ -38,7 +38,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "endent": "^2.1.0", "fast-glob": "^3.1.1", "file-type": "^16.0.0", diff --git a/plugins/upload-assets/src/index.ts b/plugins/upload-assets/src/index.ts index 4bc0b3d21..2d3727f80 100644 --- a/plugins/upload-assets/src/index.ts +++ b/plugins/upload-assets/src/index.ts @@ -21,7 +21,7 @@ const stat = promisify(fs.stat); const readFile = promisify(fs.readFile); const canaryTag = "0.0.0-canary"; -const requiredPluginOptions = t.interface({ +const requiredPluginOptions = t.type({ /** Paths to assets to upload */ assets: t.array(t.string), }); @@ -29,6 +29,16 @@ const requiredPluginOptions = t.interface({ const optionalPluginOptions = t.partial({ /** Max number of assets to keep in the canary release */ maxCanaryAssets: t.number, + /** Custom message for header in PR */ + headerMessage: t.string, + /** Filter assets by regular expression */ + filter: t.string, + /** Whether to comment on PRs made by bots */ + includeBotPrs: t.boolean, + /** Group assets by regular expression */ + group: t.string, + /** Compact view for PRs comment */ + compact: t.boolean, }); const pluginOptions = t.intersection([ @@ -64,11 +74,26 @@ export default class UploadAssetsPlugin implements IPlugin { this.options = { ...normalizedOptions, maxCanaryAssets: normalizedOptions.maxCanaryAssets || 300, + headerMessage: + normalizedOptions.headerMessage || ":baby_chick: Download canary assets:", + filter: normalizedOptions.filter || "", + includeBotPrs: + normalizedOptions.includeBotPrs === undefined + ? true + : normalizedOptions.includeBotPrs, + group: normalizedOptions.group || "", + compact: normalizedOptions.compact || false, }; } /** Tap into auto plugin points. */ apply(auto: Auto) { + const headerMessage = this.options.headerMessage; + const filter = this.options.filter; + const includeBotPrs = this.options.includeBotPrs; + const group = this.options.group; + const compact = this.options.compact; + auto.hooks.validateConfig.tapPromise(this.name, async (name, options) => { if (name === this.name || name === `@auto-it/${this.name}`) { return validatePluginConfiguration( @@ -112,23 +137,18 @@ export default class UploadAssetsPlugin implements IPlugin { const prNumber = getPrNumberFromEnv(); - if (!prNumber) { + if (!prNumber || !includeBotPrs) { return; } - const assetList = assets - .map((asset) => `[${asset.name}](${asset.browser_download_url}) `) - .join("\n"); + const assetList = this.getFilteredList(assets, filter); + const groupList = this.getGroupedList(assets, group); - await auto.git?.addToPrBody( - endent` - :baby_chick: Download canary assets: + const message = compact + ? this.getCompactPullRequestMessage(headerMessage, assetList, groupList) + : this.getPullRequestMessage(headerMessage, assetList, groupList); - ${assetList} - `, - prNumber, - "canary-assets" - ); + await auto.git?.addToPrBody(message, prNumber, "canary-assets"); } ); @@ -142,6 +162,120 @@ export default class UploadAssetsPlugin implements IPlugin { }); } + // prettier-ignore + /** Get link list by type */ + private getLinkList(assets: AssetResponse[], type: "html" | "markdown"): string { + /** Get Markdown link */ + const getMarkdownLink = (asset: AssetResponse) => + `[${asset.name}](${asset.browser_download_url})`; + + /** Get HTML link */ + const getHTMLLink = (asset: AssetResponse) => + `${asset.name}
`; + + return assets + .map(type === "html" ? getHTMLLink : getMarkdownLink) + .join("\n"); + } + + // prettier-ignore + /** Get asset list by filter */ + private getFilteredList(assets: AssetResponse[], filter: string): AssetResponse[] { + if (!filter) { + return assets; + } + + const regexp = new RegExp(filter, "mi"); + return assets.filter(({ name }) => regexp.test(name)); + } + + // prettier-ignore + /** Get asset list by group */ + private getGroupedList(assets: AssetResponse[], group: string): Record | undefined { + if (!group) { + return; + } + + const regexp = new RegExp(group, "mi"); + + return assets.reduce( + (groupList: Record, asset) => { + const name = (regexp.exec(asset.name) || [])[1]; + + if (groupList[name]) { + groupList[name].push(asset); + } else { + groupList[name] = [asset]; + } + + return groupList; + }, + {} + ); + } + + /** Get pull request message */ + private getPullRequestMessage( + message: string, + assetList: AssetResponse[], + groupList?: Record + ): string { + /** Get grouped link list */ + const getGroupedLinkList = (groupList: Record) => + Object.entries(groupList) + .map( + ([group, assets]) => + endent` + ### ${group} + ${this.getLinkList(assets, "markdown")}` + ) + .join("\n"); + + return endent` + ${message} + + ${ + groupList + ? getGroupedLinkList(groupList) + : this.getLinkList(assetList, "markdown") + } + `; + } + + /** Get compact pull request message */ + private getCompactPullRequestMessage( + message: string, + assetList: AssetResponse[], + groupList?: Record + ): string { + /** Get grouped link list */ + const getGroupedLinkList = (groupList: Record) => + Object.entries(groupList) + .map( + ([group, assets]) => endent` +
+ ${group} +
+ ${this.getLinkList(assets, "html")} +
+
` + ) + .join("\n"); + + return endent` +
+ ${message} +
+ ${ + groupList + ? getGroupedLinkList(groupList) + : this.getLinkList(assetList, "html") + } +
+
+ `; + } + /** Upload the configured asset to a release */ private async uploadAssets( auto: Auto, diff --git a/plugins/version-file/package.json b/plugins/version-file/package.json index e8492116e..657c0b415 100644 --- a/plugins/version-file/package.json +++ b/plugins/version-file/package.json @@ -36,7 +36,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "fp-ts": "^2.5.3", "io-ts": "^2.1.2", "semver": "^7.0.0", diff --git a/plugins/vscode/package.json b/plugins/vscode/package.json index d1e74ef12..fd35325f6 100644 --- a/plugins/vscode/package.json +++ b/plugins/vscode/package.json @@ -36,8 +36,8 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", - "@auto-it/package-json-utils": "link:../../packages/package-json-utils", + "@auto-it/core": "file:../../packages/core", + "@auto-it/package-json-utils": "file:../../packages/package-json-utils", "fp-ts": "^2.5.3", "io-ts": "^2.1.2", "semver": "^7.0.0", diff --git a/scripts/template-plugin/package.json b/scripts/template-plugin/package.json index a7ab05491..ef1146765 100644 --- a/scripts/template-plugin/package.json +++ b/scripts/template-plugin/package.json @@ -36,7 +36,7 @@ "test": "jest --maxWorkers=2 --config ../../package.json" }, "dependencies": { - "@auto-it/core": "link:../../packages/core", + "@auto-it/core": "file:../../packages/core", "fp-ts": "^2.5.3", "io-ts": "^2.1.2", "tslib": "1.10.0"