mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9cc34b540 |
@@ -10,12 +10,12 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Use Node.js 20
|
||||
uses: actions/setup-node@v4
|
||||
- name: Use Node.js 16
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 20.x
|
||||
node-version: 16.x
|
||||
|
||||
- name: Install Dependencies
|
||||
run: yarn --frozen-lockfile
|
||||
|
||||
@@ -12,12 +12,12 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Use Node.js 20
|
||||
uses: actions/setup-node@v4
|
||||
- name: Use Node.js 16
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 20.x
|
||||
node-version: 16.x
|
||||
|
||||
- name: Install Dependencies
|
||||
run: yarn --frozen-lockfile
|
||||
|
||||
@@ -1,60 +1,5 @@
|
||||
# @changesets/action
|
||||
|
||||
## 1.4.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#415](https://github.com/changesets/action/pull/415) [`57ab80c`](https://github.com/changesets/action/commit/57ab80c61104c270bebc125910ae32da3a5aca46) Thanks [@benmccann](https://github.com/benmccann)! - Improve error message when attempting to publish without publish script defined
|
||||
|
||||
## 1.4.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#393](https://github.com/changesets/action/pull/393) [`48ab0d2`](https://github.com/changesets/action/commit/48ab0d2f2e77ae169182d022591ef5c18c931ff2) Thanks [@s0](https://github.com/s0)! - Ensure the PR remains open when updated
|
||||
|
||||
- [#393](https://github.com/changesets/action/pull/393) [`48ab0d2`](https://github.com/changesets/action/commit/48ab0d2f2e77ae169182d022591ef5c18c931ff2) Thanks [@s0](https://github.com/s0)! - Switch to cheaper API for querying existing PRs
|
||||
|
||||
## 1.4.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#255](https://github.com/changesets/action/pull/255) [`f2660aa`](https://github.com/changesets/action/commit/f2660aa7e78365f53dbeb4cfa774c1499ec6483a) Thanks [@ernestognw](https://github.com/ernestognw)! - Allow customize PR `branch` field
|
||||
|
||||
## 1.4.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#350](https://github.com/changesets/action/pull/350) [`9385be9`](https://github.com/changesets/action/commit/9385be9e757839189ea5ee63ec4e3caa8a6ca71b) Thanks [@m-shaka](https://github.com/m-shaka)! - Bump the used node.js from 16 to 20
|
||||
|
||||
## 1.4.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#282](https://github.com/changesets/action/pull/282) [`eb19e25`](https://github.com/changesets/action/commit/eb19e25e7797cf33dc2de4caa071e85a8057a0f0) Thanks [@mark-omarov](https://github.com/mark-omarov)! - Updated a few dependencies to patch the security vulnerabilities that were reported for their older versions.
|
||||
|
||||
## 1.4.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#291](https://github.com/changesets/action/pull/291) [`db8a109`](https://github.com/changesets/action/commit/db8a1099bc0ba1dd6f46a5b9df4212e4f69e78c9) Thanks [@varl](https://github.com/varl)! - Wire up [`@octokit/plugin-throttling`](https://github.com/octokit/plugin-throttling.js) with all GitHub Octokit instances
|
||||
|
||||
## 1.4.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#289](https://github.com/changesets/action/pull/289) [`8b28186`](https://github.com/changesets/action/commit/8b2818674de86a7fc69aebb9ed6b486ee32eb96e) Thanks [@varl](https://github.com/varl)! - Use logging provided by `@actions/core`
|
||||
|
||||
## 1.4.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#286](https://github.com/changesets/action/pull/286) [`225a1e8`](https://github.com/changesets/action/commit/225a1e8cbcabb7b585174ba0ad806549db40d4cd) Thanks [@varl](https://github.com/varl)! - This patch implements the [`@octokit/plugin-throttling`](https://github.com/octokit/plugin-throttling.js) plugin and [wires
|
||||
it up with the internal GitHub Octokit instance](https://github.com/actions/toolkit/tree/457303960f03375db6f033e214b9f90d79c3fe5c/packages/github#extending-the-octokit-instance).
|
||||
|
||||
This plugin is recommended by [the Octokit docs](://octokit.github.io/rest.js/v19#throttling) as it implements all the GitHub [best practices for integrators](https://docs.github.com/en/rest/guides/best-practices-for-integrators?apiVersion=2022-11-28).
|
||||
|
||||
This should help with `changesets/action` gitting spurious secondary rate limits and failing CI jobs, for which the only known workaround is to simply re-run the job.
|
||||
|
||||
## 1.4.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -16,7 +16,7 @@ This action for [Changesets](https://github.com/atlassian/changesets) creates a
|
||||
|
||||
### Outputs
|
||||
|
||||
- published - A boolean value to indicate whether a publishing has happened or not
|
||||
- published - A boolean value to indicate whether a publishing is happened or not
|
||||
- publishedPackages - A JSON array to present the published packages. The format is `[{"name": "@xx/xx", "version": "1.2.0"}, {"name": "@xx/xy", "version": "0.8.9"}]`
|
||||
|
||||
### Example workflow:
|
||||
@@ -41,12 +41,12 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Node.js 20
|
||||
uses: actions/setup-node@v3
|
||||
- name: Setup Node.js 12.x
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 20
|
||||
node-version: 12.x
|
||||
|
||||
- name: Install Dependencies
|
||||
run: yarn
|
||||
@@ -77,12 +77,12 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Node.js 20.x
|
||||
uses: actions/setup-node@v3
|
||||
- name: Setup Node.js 12.x
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 20.x
|
||||
node-version: 12.x
|
||||
|
||||
- name: Install Dependencies
|
||||
run: yarn
|
||||
@@ -124,7 +124,7 @@ For example, you can add a step before running the Changesets GitHub Action:
|
||||
|
||||
#### Custom Publishing
|
||||
|
||||
If you want to hook into when publishing should occur but have your own publishing functionality, you can utilize the `hasChangesets` output.
|
||||
If you want to hook into when publishing should occur but have your own publishing functionality you can utilize the `hasChangesets` output.
|
||||
|
||||
Note that you might need to account for things already being published in your script because a commit without any new changesets can always land on your base branch after a successful publish. In such a case you need to figure out on your own how to skip over the actual publishing logic or handle errors gracefully as most package registries won't allow you to publish over already published version.
|
||||
|
||||
@@ -142,12 +142,12 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Node.js 20.x
|
||||
uses: actions/setup-node@v3
|
||||
- name: Setup Node.js 12.x
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 20.x
|
||||
node-version: 12.x
|
||||
|
||||
- name: Install Dependencies
|
||||
run: yarn
|
||||
@@ -186,12 +186,12 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Node.js 20.x
|
||||
uses: actions/setup-node@v3
|
||||
- name: Setup Node.js 12.x
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 20.x
|
||||
node-version: 12.x
|
||||
|
||||
- name: Install Dependencies
|
||||
run: yarn
|
||||
|
||||
+1
-4
@@ -1,7 +1,7 @@
|
||||
name: Changesets
|
||||
description: A GitHub action to automate releases with Changesets
|
||||
runs:
|
||||
using: "node20"
|
||||
using: "node16"
|
||||
main: "dist/index.js"
|
||||
inputs:
|
||||
publish:
|
||||
@@ -28,9 +28,6 @@ inputs:
|
||||
description: "A boolean value to indicate whether to create Github releases after `publish` or not"
|
||||
required: false
|
||||
default: true
|
||||
branch:
|
||||
description: Sets the branch in which the action will run. Default to `github.ref_name` if not provided
|
||||
required: false
|
||||
outputs:
|
||||
published:
|
||||
description: A boolean value to indicate whether a publishing is happened or not
|
||||
|
||||
Vendored
+973
-63
File diff suppressed because one or more lines are too long
+17
-23
@@ -1,29 +1,19 @@
|
||||
{
|
||||
"name": "@changesets/action",
|
||||
"version": "1.4.9",
|
||||
"version": "1.4.1",
|
||||
"main": "dist/index.js",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@changesets/changelog-github": "^0.4.2",
|
||||
"@changesets/cli": "^2.20.0",
|
||||
"@changesets/write": "^0.1.6",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"fixturez": "^1.1.0",
|
||||
"parcel": "^1.12.3",
|
||||
"prettier": "^2.0.5",
|
||||
"typescript": "^5.0.4",
|
||||
"@babel/core": "^7.13.10",
|
||||
"@babel/preset-env": "^7.13.10",
|
||||
"@babel/preset-typescript": "^7.13.0",
|
||||
"@types/fs-extra": "^8.0.0",
|
||||
"@types/jest": "^29.5.1",
|
||||
"@types/node": "^20.11.17",
|
||||
"@types/semver": "^7.5.0",
|
||||
"babel-jest": "^29.5.0",
|
||||
"husky": "^3.0.3",
|
||||
"jest": "^29.5.0"
|
||||
"typescript": "^3.5.3"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "ncc build src/index.ts -o dist --transpile-only --minify",
|
||||
"build": "parcel build ./src/index.ts --no-source-maps --target=node --bundle-node-modules",
|
||||
"test": "jest",
|
||||
"test:watch": "yarn test --watch",
|
||||
"changeset": "changeset",
|
||||
@@ -31,31 +21,35 @@
|
||||
"release": "node ./scripts/release.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 20"
|
||||
"node": ">= 16"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/github": "^5.1.1",
|
||||
"@babel/core": "^7.13.10",
|
||||
"@babel/preset-env": "^7.13.10",
|
||||
"@babel/preset-typescript": "^7.13.0",
|
||||
"@changesets/pre": "^1.0.9",
|
||||
"@changesets/read": "^0.5.3",
|
||||
"@manypkg/get-packages": "^1.1.3",
|
||||
"@octokit/plugin-throttling": "^5.2.1",
|
||||
"@types/fs-extra": "^8.0.0",
|
||||
"@types/jest": "^24.0.18",
|
||||
"@types/node": "^12.7.1",
|
||||
"@types/semver": "^6.0.2",
|
||||
"babel-jest": "^24.9.0",
|
||||
"fs-extra": "^8.1.0",
|
||||
"husky": "^3.0.3",
|
||||
"jest": "^24.9.0",
|
||||
"mdast-util-to-string": "^1.0.6",
|
||||
"remark-parse": "^7.0.1",
|
||||
"remark-stringify": "^7.0.3",
|
||||
"resolve-from": "^5.0.0",
|
||||
"semver": "^7.5.3",
|
||||
"semver": "^6.3.0",
|
||||
"unified": "^8.3.2"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {}
|
||||
},
|
||||
"prettier": {},
|
||||
"resolutions": {
|
||||
"**/@octokit/core": "4.2.0",
|
||||
"trim": "^0.0.3",
|
||||
"y18n": "^4.0.1"
|
||||
}
|
||||
"prettier": {}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`version creates simple PR 1`] = `
|
||||
[
|
||||
{
|
||||
Array [
|
||||
Object {
|
||||
"base": "some-branch",
|
||||
"body": "This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to some-branch, this PR will be updated.
|
||||
|
||||
@@ -34,8 +34,8 @@ exports[`version creates simple PR 1`] = `
|
||||
`;
|
||||
|
||||
exports[`version does not include any release information if a message with simplified release info exceeds size limit 1`] = `
|
||||
[
|
||||
{
|
||||
Array [
|
||||
Object {
|
||||
"base": "some-branch",
|
||||
"body": "This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to some-branch, this PR will be updated.
|
||||
|
||||
@@ -52,8 +52,8 @@ exports[`version does not include any release information if a message with simp
|
||||
`;
|
||||
|
||||
exports[`version does not include changelog entries if full message exceeds size limit 1`] = `
|
||||
[
|
||||
{
|
||||
Array [
|
||||
Object {
|
||||
"base": "some-branch",
|
||||
"body": "This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to some-branch, this PR will be updated.
|
||||
|
||||
@@ -74,8 +74,8 @@ exports[`version does not include changelog entries if full message exceeds size
|
||||
`;
|
||||
|
||||
exports[`version doesn't include ignored package that got a dependency update in the PR body 1`] = `
|
||||
[
|
||||
{
|
||||
Array [
|
||||
Object {
|
||||
"base": "some-branch",
|
||||
"body": "This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to some-branch, this PR will be updated.
|
||||
|
||||
@@ -96,8 +96,8 @@ exports[`version doesn't include ignored package that got a dependency update in
|
||||
`;
|
||||
|
||||
exports[`version only includes bumped packages in the PR body 1`] = `
|
||||
[
|
||||
{
|
||||
Array [
|
||||
Object {
|
||||
"base": "some-branch",
|
||||
"body": "This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to some-branch, this PR will be updated.
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`it sorts the things right 1`] = `
|
||||
[
|
||||
{
|
||||
Array [
|
||||
Object {
|
||||
"highestLevel": 3,
|
||||
"name": "c",
|
||||
"private": false,
|
||||
},
|
||||
{
|
||||
Object {
|
||||
"highestLevel": 1,
|
||||
"name": "b",
|
||||
"private": false,
|
||||
},
|
||||
{
|
||||
Object {
|
||||
"highestLevel": 3,
|
||||
"name": "a",
|
||||
"private": true,
|
||||
|
||||
+12
-13
@@ -16,18 +16,18 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
|
||||
const inputCwd = core.getInput("cwd");
|
||||
if (inputCwd) {
|
||||
core.info("changing directory to the one given as the input");
|
||||
console.log("changing directory to the one given as the input");
|
||||
process.chdir(inputCwd);
|
||||
}
|
||||
|
||||
let setupGitUser = core.getBooleanInput("setupGitUser");
|
||||
|
||||
if (setupGitUser) {
|
||||
core.info("setting git user");
|
||||
console.log("setting git user");
|
||||
await gitUtils.setupUser();
|
||||
}
|
||||
|
||||
core.info("setting GitHub credentials");
|
||||
console.log("setting GitHub credentials");
|
||||
await fs.writeFile(
|
||||
`${process.env.HOME}/.netrc`,
|
||||
`machine github.com\nlogin github-actions[bot]\npassword ${githubToken}`
|
||||
@@ -48,27 +48,27 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
|
||||
switch (true) {
|
||||
case !hasChangesets && !hasPublishScript:
|
||||
core.info("No changesets present or were removed by merging release PR. Not publishing because no publish script found.");
|
||||
console.log("No changesets found");
|
||||
return;
|
||||
case !hasChangesets && hasPublishScript: {
|
||||
core.info(
|
||||
"No changesets found. Attempting to publish any unpublished packages to npm"
|
||||
console.log(
|
||||
"No changesets found, attempting to publish any unpublished packages to npm"
|
||||
);
|
||||
|
||||
let userNpmrcPath = `${process.env.HOME}/.npmrc`;
|
||||
if (fs.existsSync(userNpmrcPath)) {
|
||||
core.info("Found existing user .npmrc file");
|
||||
console.log("Found existing user .npmrc file");
|
||||
const userNpmrcContent = await fs.readFile(userNpmrcPath, "utf8");
|
||||
const authLine = userNpmrcContent.split("\n").find((line) => {
|
||||
// check based on https://github.com/npm/cli/blob/8f8f71e4dd5ee66b3b17888faad5a7bf6c657eed/test/lib/adduser.js#L103-L105
|
||||
return /^\s*\/\/registry\.npmjs\.org\/:[_-]authToken=/i.test(line);
|
||||
});
|
||||
if (authLine) {
|
||||
core.info(
|
||||
console.log(
|
||||
"Found existing auth token for the npm registry in the user .npmrc file"
|
||||
);
|
||||
} else {
|
||||
core.info(
|
||||
console.log(
|
||||
"Didn't find existing auth token for the npm registry in the user .npmrc file, creating one"
|
||||
);
|
||||
fs.appendFileSync(
|
||||
@@ -77,7 +77,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
);
|
||||
}
|
||||
} else {
|
||||
core.info("No user .npmrc file found, creating one");
|
||||
console.log("No user .npmrc file found, creating one");
|
||||
fs.writeFileSync(
|
||||
userNpmrcPath,
|
||||
`//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`
|
||||
@@ -100,7 +100,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
return;
|
||||
}
|
||||
case hasChangesets && !hasNonEmptyChangesets:
|
||||
core.info("All changesets are empty; not creating PR");
|
||||
console.log("All changesets are empty; not creating PR");
|
||||
return;
|
||||
case hasChangesets:
|
||||
const { pullRequestNumber } = await runVersion({
|
||||
@@ -109,7 +109,6 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
prTitle: getOptionalInput("title"),
|
||||
commitMessage: getOptionalInput("commit"),
|
||||
hasPublishScript,
|
||||
branch: getOptionalInput("branch"),
|
||||
});
|
||||
|
||||
core.setOutput("pullRequestNumber", String(pullRequestNumber));
|
||||
@@ -117,6 +116,6 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
return;
|
||||
}
|
||||
})().catch((err) => {
|
||||
core.error(err);
|
||||
console.error(err);
|
||||
core.setFailed(err.message);
|
||||
});
|
||||
|
||||
@@ -11,19 +11,17 @@ export default async function readChangesetState(
|
||||
cwd: string = process.cwd()
|
||||
): Promise<ChangesetState> {
|
||||
let preState = await readPreState(cwd);
|
||||
let isInPreMode = preState !== undefined && preState.mode === "pre";
|
||||
|
||||
let changesets = await readChangesets(cwd);
|
||||
|
||||
if (preState !== undefined && preState.mode === "pre") {
|
||||
if (isInPreMode) {
|
||||
let changesetsToFilter = new Set(preState.changesets);
|
||||
|
||||
return {
|
||||
preState,
|
||||
changesets: changesets.filter((x) => !changesetsToFilter.has(x.id)),
|
||||
};
|
||||
changesets = changesets.filter((x) => !changesetsToFilter.has(x.id));
|
||||
}
|
||||
|
||||
return {
|
||||
preState: undefined,
|
||||
preState: isInPreMode ? preState : undefined,
|
||||
changesets,
|
||||
};
|
||||
}
|
||||
|
||||
+22
-20
@@ -1,6 +1,5 @@
|
||||
import fixturez from "fixturez";
|
||||
import * as github from "@actions/github";
|
||||
import * as githubUtils from "@actions/github/lib/utils";
|
||||
import fs from "fs-extra";
|
||||
import path from "path";
|
||||
import writeChangeset from "@changesets/write";
|
||||
@@ -16,31 +15,24 @@ jest.mock("@actions/github", () => ({
|
||||
ref: "refs/heads/some-branch",
|
||||
sha: "xeac7",
|
||||
},
|
||||
}));
|
||||
jest.mock("@actions/github/lib/utils", () => ({
|
||||
GitHub: {
|
||||
plugin: () => {
|
||||
// function necessary to be used as constructor
|
||||
return function() {
|
||||
return {
|
||||
rest: mockedGithubMethods,
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
getOctokitOptions: jest.fn(),
|
||||
getOctokit: jest.fn(),
|
||||
}));
|
||||
jest.mock("./gitUtils");
|
||||
|
||||
let mockedGithubMethods = {
|
||||
search: {
|
||||
issuesAndPullRequests: jest.fn(),
|
||||
},
|
||||
pulls: {
|
||||
create: jest.fn(),
|
||||
list: jest.fn(),
|
||||
},
|
||||
repos: {
|
||||
createRelease: jest.fn(),
|
||||
},
|
||||
};
|
||||
(github.getOctokit as any).mockImplementation(() => ({
|
||||
rest: mockedGithubMethods,
|
||||
}));
|
||||
|
||||
let f = fixturez(__dirname);
|
||||
|
||||
@@ -63,7 +55,9 @@ describe("version", () => {
|
||||
let cwd = f.copy("simple-project");
|
||||
linkNodeModules(cwd);
|
||||
|
||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
||||
mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce(
|
||||
() => ({ data: { items: [] } })
|
||||
);
|
||||
|
||||
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
||||
data: { number: 123 },
|
||||
@@ -100,7 +94,9 @@ describe("version", () => {
|
||||
let cwd = f.copy("simple-project");
|
||||
linkNodeModules(cwd);
|
||||
|
||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
||||
mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce(
|
||||
() => ({ data: { items: [] } })
|
||||
);
|
||||
|
||||
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
||||
data: { number: 123 },
|
||||
@@ -133,7 +129,9 @@ describe("version", () => {
|
||||
let cwd = f.copy("ignored-package");
|
||||
linkNodeModules(cwd);
|
||||
|
||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
||||
mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce(
|
||||
() => ({ data: { items: [] } })
|
||||
);
|
||||
|
||||
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
||||
data: { number: 123 },
|
||||
@@ -166,7 +164,9 @@ describe("version", () => {
|
||||
let cwd = f.copy("simple-project");
|
||||
linkNodeModules(cwd);
|
||||
|
||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
||||
mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce(
|
||||
() => ({ data: { items: [] } })
|
||||
);
|
||||
|
||||
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
||||
data: { number: 123 },
|
||||
@@ -223,7 +223,9 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
||||
let cwd = f.copy("simple-project");
|
||||
linkNodeModules(cwd);
|
||||
|
||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
||||
mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce(
|
||||
() => ({ data: { items: [] } })
|
||||
);
|
||||
|
||||
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
||||
data: { number: 123 },
|
||||
|
||||
+15
-70
@@ -1,7 +1,5 @@
|
||||
import { exec, getExecOutput } from "@actions/exec";
|
||||
import { GitHub, getOctokitOptions } from "@actions/github/lib/utils";
|
||||
import * as github from "@actions/github";
|
||||
import * as core from "@actions/core";
|
||||
import fs from "fs-extra";
|
||||
import { getPackages, Package } from "@manypkg/get-packages";
|
||||
import path from "path";
|
||||
@@ -16,7 +14,6 @@ import {
|
||||
import * as gitUtils from "./gitUtils";
|
||||
import readChangesetState from "./readChangesetState";
|
||||
import resolveFrom from "resolve-from";
|
||||
import { throttling } from "@octokit/plugin-throttling";
|
||||
|
||||
// GitHub Issues/PRs messages have a max size limit on the
|
||||
// message body payload.
|
||||
@@ -24,42 +21,8 @@ import { throttling } from "@octokit/plugin-throttling";
|
||||
// To avoid that, we ensure to cap the message to 60k chars.
|
||||
const MAX_CHARACTERS_PER_MESSAGE = 60000;
|
||||
|
||||
const setupOctokit = (githubToken: string) => {
|
||||
return new (GitHub.plugin(throttling))(
|
||||
getOctokitOptions(githubToken, {
|
||||
throttle: {
|
||||
onRateLimit: (retryAfter, options: any, octokit, retryCount) => {
|
||||
core.warning(
|
||||
`Request quota exhausted for request ${options.method} ${options.url}`
|
||||
);
|
||||
|
||||
if (retryCount <= 2) {
|
||||
core.info(`Retrying after ${retryAfter} seconds!`);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
onSecondaryRateLimit: (
|
||||
retryAfter,
|
||||
options: any,
|
||||
octokit,
|
||||
retryCount
|
||||
) => {
|
||||
core.warning(
|
||||
`SecondaryRateLimit detected for request ${options.method} ${options.url}`
|
||||
);
|
||||
|
||||
if (retryCount <= 2) {
|
||||
core.info(`Retrying after ${retryAfter} seconds!`);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
const createRelease = async (
|
||||
octokit: ReturnType<typeof setupOctokit>,
|
||||
octokit: ReturnType<typeof github.getOctokit>,
|
||||
{ pkg, tagName }: { pkg: Package; tagName: string }
|
||||
) => {
|
||||
try {
|
||||
@@ -85,12 +48,7 @@ const createRelease = async (
|
||||
});
|
||||
} catch (err) {
|
||||
// if we can't find a changelog, the user has probably disabled changelogs
|
||||
if (
|
||||
err &&
|
||||
typeof err === "object" &&
|
||||
"code" in err &&
|
||||
err.code !== "ENOENT"
|
||||
) {
|
||||
if (err.code !== "ENOENT") {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -120,8 +78,7 @@ export async function runPublish({
|
||||
createGithubReleases,
|
||||
cwd = process.cwd(),
|
||||
}: PublishOptions): Promise<PublishResult> {
|
||||
const octokit = setupOctokit(githubToken);
|
||||
|
||||
let octokit = github.getOctokit(githubToken);
|
||||
let [publishCommand, ...publishArgs] = script.split(/\s+/);
|
||||
|
||||
let changesetPublishOutput = await getExecOutput(
|
||||
@@ -208,12 +165,7 @@ const requireChangesetsCliPkgJson = (cwd: string) => {
|
||||
try {
|
||||
return require(resolveFrom(cwd, "@changesets/cli/package.json"));
|
||||
} catch (err) {
|
||||
if (
|
||||
err &&
|
||||
typeof err === "object" &&
|
||||
"code" in err &&
|
||||
err.code === "MODULE_NOT_FOUND"
|
||||
) {
|
||||
if (err && err.code === "MODULE_NOT_FOUND") {
|
||||
throw new Error(
|
||||
`Have you forgotten to install \`@changesets/cli\` in "${cwd}"?`
|
||||
);
|
||||
@@ -299,7 +251,6 @@ type VersionOptions = {
|
||||
commitMessage?: string;
|
||||
hasPublishScript?: boolean;
|
||||
prBodyMaxCharacters?: number;
|
||||
branch?: string;
|
||||
};
|
||||
|
||||
type RunVersionResult = {
|
||||
@@ -314,14 +265,11 @@ export async function runVersion({
|
||||
commitMessage = "Version Packages",
|
||||
hasPublishScript = false,
|
||||
prBodyMaxCharacters = MAX_CHARACTERS_PER_MESSAGE,
|
||||
branch,
|
||||
}: VersionOptions): Promise<RunVersionResult> {
|
||||
const octokit = setupOctokit(githubToken);
|
||||
|
||||
let repo = `${github.context.repo.owner}/${github.context.repo.repo}`;
|
||||
branch = branch ?? github.context.ref.replace("refs/heads/", "");
|
||||
let branch = github.context.ref.replace("refs/heads/", "");
|
||||
let versionBranch = `changeset-release/${branch}`;
|
||||
|
||||
let octokit = github.getOctokit(githubToken);
|
||||
let { preState } = await readChangesetState(cwd);
|
||||
|
||||
await gitUtils.switchToMaybeExistingBranch(versionBranch);
|
||||
@@ -342,11 +290,9 @@ export async function runVersion({
|
||||
});
|
||||
}
|
||||
|
||||
const existingPullRequestsPromise = octokit.rest.pulls.list({
|
||||
...github.context.repo,
|
||||
state: "open",
|
||||
head: `${github.context.repo.owner}:${versionBranch}`,
|
||||
base: branch,
|
||||
let searchQuery = `repo:${repo}+state:open+head:${versionBranch}+base:${branch}+is:pull-request`;
|
||||
let searchResultPromise = octokit.rest.search.issuesAndPullRequests({
|
||||
q: searchQuery,
|
||||
});
|
||||
let changedPackages = await getChangedPackages(cwd, versionsByDirectory);
|
||||
let changedPackagesInfoPromises = Promise.all(
|
||||
@@ -378,8 +324,8 @@ export async function runVersion({
|
||||
|
||||
await gitUtils.push(versionBranch, { force: true });
|
||||
|
||||
let existingPullRequests = await existingPullRequestsPromise;
|
||||
core.info(JSON.stringify(existingPullRequests.data, null, 2));
|
||||
let searchResult = await searchResultPromise;
|
||||
console.log(JSON.stringify(searchResult.data, null, 2));
|
||||
|
||||
const changedPackagesInfo = (await changedPackagesInfoPromises)
|
||||
.filter((x) => x)
|
||||
@@ -393,8 +339,8 @@ export async function runVersion({
|
||||
prBodyMaxCharacters,
|
||||
});
|
||||
|
||||
if (existingPullRequests.data.length === 0) {
|
||||
core.info("creating pull request");
|
||||
if (searchResult.data.items.length === 0) {
|
||||
console.log("creating pull request");
|
||||
const { data: newPullRequest } = await octokit.rest.pulls.create({
|
||||
base: branch,
|
||||
head: versionBranch,
|
||||
@@ -407,15 +353,14 @@ export async function runVersion({
|
||||
pullRequestNumber: newPullRequest.number,
|
||||
};
|
||||
} else {
|
||||
const [pullRequest] = existingPullRequests.data;
|
||||
const [pullRequest] = searchResult.data.items;
|
||||
|
||||
core.info(`updating found pull request #${pullRequest.number}`);
|
||||
console.log(`updating found pull request #${pullRequest.number}`);
|
||||
await octokit.rest.pulls.update({
|
||||
pull_number: pullRequest.number,
|
||||
title: finalPrTitle,
|
||||
body: prBody,
|
||||
...github.context.repo,
|
||||
state: "open",
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@@ -3,6 +3,7 @@ import remarkParse from "remark-parse";
|
||||
import remarkStringify from "remark-stringify";
|
||||
// @ts-ignore
|
||||
import mdastToString from "mdast-util-to-string";
|
||||
import { exec } from "@actions/exec";
|
||||
import { getPackages, Package } from "@manypkg/get-packages";
|
||||
|
||||
export const BumpLevels = {
|
||||
|
||||
Reference in New Issue
Block a user