mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
983cabb332 |
@@ -1,6 +1,6 @@
|
|||||||
name: Node CI
|
name: Node CI
|
||||||
|
|
||||||
on: [pull_request]
|
on: [push]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -12,10 +12,10 @@ jobs:
|
|||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Use Node.js 16
|
- name: Use Node.js 14
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 16.x
|
node-version: 14.x
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: yarn --frozen-lockfile
|
run: yarn --frozen-lockfile
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
changesets:
|
changesets:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -14,10 +12,10 @@ jobs:
|
|||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Use Node.js 16
|
- name: Use Node.js 14
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 16.x
|
node-version: 14.x
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: yarn --frozen-lockfile
|
run: yarn --frozen-lockfile
|
||||||
|
|||||||
@@ -1,62 +1,5 @@
|
|||||||
# @changesets/action
|
# @changesets/action
|
||||||
|
|
||||||
## 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
|
|
||||||
|
|
||||||
- [#123](https://github.com/changesets/action/pull/123) [`b78f480`](https://github.com/changesets/action/commit/b78f48099899f0a853c5d9cd3feb21a5440babbd) Thanks [@Andarist](https://github.com/Andarist)! - Updated `@actions/*` dependencies to avoid using deprecated features of the runner.
|
|
||||||
|
|
||||||
## 1.4.0
|
|
||||||
|
|
||||||
### Minor Changes
|
|
||||||
|
|
||||||
- [#216](https://github.com/changesets/action/pull/216) [`398d7ed`](https://github.com/changesets/action/commit/398d7ed) Thanks [@quinnjn](https://github.com/quinnjn)! - Execute action with node16 instead of node12.
|
|
||||||
|
|
||||||
### Patch Changes
|
|
||||||
|
|
||||||
- [#228](https://github.com/changesets/action/pull/228) [`bff53cc`](https://github.com/changesets/action/commit/bff53cc50c1ebb33f8f558f9de2e0eb9a99230c6) Thanks [@iansan5653](https://github.com/iansan5653)! - Add `is:pull-request` to search query when looking for existing PR. This fixes an issue with user-owned PATs.
|
|
||||||
|
|
||||||
* [#206](https://github.com/changesets/action/pull/206) [`8c3f5f5`](https://github.com/changesets/action/commit/8c3f5f5637a95a2327e78d5dabcf357978aedcbb) Thanks [@glasser](https://github.com/glasser)! - Skip creating a PR when all existing changesets are empty.
|
|
||||||
|
|
||||||
## 1.3.0
|
|
||||||
|
|
||||||
### Minor Changes
|
|
||||||
|
|
||||||
- [#167](https://github.com/changesets/action/pull/167) [`993a0a0`](https://github.com/changesets/action/commit/993a0a090df78cee07481d3886dcd8b29deb9567) Thanks [@dmregister](https://github.com/dmregister)! - Added `pullRequestNumber` to the action's outputs
|
|
||||||
|
|
||||||
### Patch Changes
|
|
||||||
|
|
||||||
- [#157](https://github.com/changesets/action/pull/157) [`521c27b`](https://github.com/changesets/action/commit/521c27bf86ec53547d6a350d208fbbbc9d576fbc) Thanks [@emmenko](https://github.com/emmenko)! - Automatically adjust GitHub PR message if it exceeds a size limit of 60k characters by omitting some of the changelog information.
|
|
||||||
|
|
||||||
## 1.2.2
|
|
||||||
|
|
||||||
### Patch Changes
|
|
||||||
|
|
||||||
- [#161](https://github.com/changesets/action/pull/161) [`52c9ce7`](https://github.com/changesets/action/commit/52c9ce75d9d8a14ea2d75e4157b0c15b7a4ac313) Thanks [@bicknellr](https://github.com/bicknellr)! - Change directory to `cwd` before running git user setup. This fixes an issue when the action starts its execution not in a git repository.
|
|
||||||
|
|
||||||
## 1.2.1
|
## 1.2.1
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Changesets Release Action
|
# Changesets Release Action
|
||||||
|
|
||||||
This action for [Changesets](https://github.com/atlassian/changesets) creates a pull request with all of the package versions updated and changelogs updated and when there are new changesets on [your configured `baseBranch`](https://github.com/changesets/changesets/blob/main/docs/config-file-options.md#basebranch-git-branch-name), the PR will be updated. When you're ready, you can merge the pull request and you can either publish the packages to npm manually or setup the action to do it for you.
|
This action for [Changesets](https://github.com/atlassian/changesets) creates a pull request with all of the package versions updated and changelogs updated and when there are new changesets on master, the PR will be updated. When you're ready, you can merge the pull request and you can either publish the packages to npm manually or setup the action to do it for you.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@@ -11,7 +11,6 @@ This action for [Changesets](https://github.com/atlassian/changesets) creates a
|
|||||||
- commit - The commit message to use. Default to `Version Packages`
|
- commit - The commit message to use. Default to `Version Packages`
|
||||||
- title - The pull request title. Default to `Version Packages`
|
- title - The pull request title. Default to `Version Packages`
|
||||||
- setupGitUser - Sets up the git user for commits as `"github-actions[bot]"`. Default to `true`
|
- setupGitUser - Sets up the git user for commits as `"github-actions[bot]"`. Default to `true`
|
||||||
- createGithubReleases - A boolean value to indicate whether to create Github releases after `publish` or not. Default to `true`
|
|
||||||
- cwd - Changes node's `process.cwd()` if the project is not located on the root. Default to `process.cwd()`
|
- cwd - Changes node's `process.cwd()` if the project is not located on the root. Default to `process.cwd()`
|
||||||
|
|
||||||
### Outputs
|
### Outputs
|
||||||
@@ -31,7 +30,7 @@ name: Release
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- master
|
||||||
|
|
||||||
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
|
||||||
@@ -41,12 +40,15 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Setup Node.js 16
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
with:
|
||||||
node-version: 16
|
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Node.js 12.x
|
||||||
|
uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: 12.x
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: yarn
|
run: yarn
|
||||||
@@ -67,7 +69,7 @@ name: Release
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- master
|
||||||
|
|
||||||
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
|
||||||
@@ -77,12 +79,15 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Setup Node.js 16.x
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
with:
|
||||||
node-version: 16.x
|
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Node.js 12.x
|
||||||
|
uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: 12.x
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: yarn
|
run: yarn
|
||||||
@@ -116,54 +121,13 @@ For example, you can add a step before running the Changesets GitHub Action:
|
|||||||
- name: Creating .npmrc
|
- name: Creating .npmrc
|
||||||
run: |
|
run: |
|
||||||
cat << EOF > "$HOME/.npmrc"
|
cat << EOF > "$HOME/.npmrc"
|
||||||
|
email=my@email.com
|
||||||
//registry.npmjs.org/:_authToken=$NPM_TOKEN
|
//registry.npmjs.org/:_authToken=$NPM_TOKEN
|
||||||
EOF
|
EOF
|
||||||
env:
|
env:
|
||||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Custom Publishing
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
```yml
|
|
||||||
name: Release
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
release:
|
|
||||||
name: Release
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout Repo
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Setup Node.js 16.x
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: 16.x
|
|
||||||
|
|
||||||
- name: Install Dependencies
|
|
||||||
run: yarn
|
|
||||||
|
|
||||||
- name: Create Release Pull Request or Publish to npm
|
|
||||||
id: changesets
|
|
||||||
uses: changesets/action@v1
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Publish
|
|
||||||
if: steps.changesets.outputs.hasChangesets == 'false'
|
|
||||||
# You can do something when a publish should happen.
|
|
||||||
run: yarn publish
|
|
||||||
```
|
|
||||||
|
|
||||||
#### With version script
|
#### With version script
|
||||||
|
|
||||||
If you need to add additional logic to the version command, you can do so by using a version script.
|
If you need to add additional logic to the version command, you can do so by using a version script.
|
||||||
@@ -176,7 +140,7 @@ name: Release
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- master
|
||||||
|
|
||||||
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
|
||||||
@@ -186,12 +150,14 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Setup Node.js 16.x
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
with:
|
||||||
node-version: 16.x
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Node.js 12.x
|
||||||
|
uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: 12.x
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: yarn
|
run: yarn
|
||||||
|
|||||||
+1
-5
@@ -1,7 +1,7 @@
|
|||||||
name: Changesets
|
name: Changesets
|
||||||
description: A GitHub action to automate releases with Changesets
|
description: A GitHub action to automate releases with Changesets
|
||||||
runs:
|
runs:
|
||||||
using: "node16"
|
using: "node12"
|
||||||
main: "dist/index.js"
|
main: "dist/index.js"
|
||||||
inputs:
|
inputs:
|
||||||
publish:
|
publish:
|
||||||
@@ -34,10 +34,6 @@ outputs:
|
|||||||
publishedPackages:
|
publishedPackages:
|
||||||
description: >
|
description: >
|
||||||
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"}]`
|
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"}]`
|
||||||
hasChangesets:
|
|
||||||
description: A boolean about whether there were changesets. Useful if you want to create your own publishing functionality.
|
|
||||||
pullRequestNumber:
|
|
||||||
description: The pull request number that was created or updated
|
|
||||||
branding:
|
branding:
|
||||||
icon: "package"
|
icon: "package"
|
||||||
color: "blue"
|
color: "blue"
|
||||||
|
|||||||
Vendored
+921
-59
File diff suppressed because one or more lines are too long
+11
-18
@@ -1,47 +1,43 @@
|
|||||||
{
|
{
|
||||||
"name": "@changesets/action",
|
"name": "@changesets/action",
|
||||||
"version": "1.4.4",
|
"version": "1.2.1",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@changesets/changelog-github": "^0.4.2",
|
"@changesets/changelog-github": "^0.4.2",
|
||||||
"@changesets/cli": "^2.20.0",
|
"@changesets/cli": "^2.20.0",
|
||||||
"@changesets/write": "^0.1.6",
|
"@changesets/write": "^0.1.6",
|
||||||
"@vercel/ncc": "^0.36.1",
|
|
||||||
"fixturez": "^1.1.0",
|
"fixturez": "^1.1.0",
|
||||||
|
"parcel": "^1.12.3",
|
||||||
"prettier": "^2.0.5",
|
"prettier": "^2.0.5",
|
||||||
"typescript": "^5.0.4"
|
"typescript": "^3.5.3"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"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": "jest",
|
||||||
"test:watch": "yarn test --watch",
|
"test:watch": "yarn test --watch",
|
||||||
"changeset": "changeset",
|
"changeset": "changeset",
|
||||||
"bump": "node ./scripts/bump.js",
|
"bump": "node ./scripts/bump.js",
|
||||||
"release": "node ./scripts/release.js"
|
"release": "node ./scripts/release.js"
|
||||||
},
|
},
|
||||||
"engines": {
|
|
||||||
"node": ">= 16"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^1.3.0",
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^1.1.0",
|
||||||
"@actions/github": "^5.1.1",
|
"@actions/github": "^4.0.0",
|
||||||
"@babel/core": "^7.13.10",
|
"@babel/core": "^7.13.10",
|
||||||
"@babel/preset-env": "^7.13.10",
|
"@babel/preset-env": "^7.13.10",
|
||||||
"@babel/preset-typescript": "^7.13.0",
|
"@babel/preset-typescript": "^7.13.0",
|
||||||
"@changesets/pre": "^1.0.9",
|
"@changesets/pre": "^1.0.9",
|
||||||
"@changesets/read": "^0.5.3",
|
"@changesets/read": "^0.5.3",
|
||||||
"@manypkg/get-packages": "^1.1.3",
|
"@manypkg/get-packages": "^1.1.3",
|
||||||
"@octokit/plugin-throttling": "5.1.1",
|
|
||||||
"@types/fs-extra": "^8.0.0",
|
"@types/fs-extra": "^8.0.0",
|
||||||
"@types/jest": "^29.5.1",
|
"@types/jest": "^24.0.18",
|
||||||
"@types/node": "^12.7.1",
|
"@types/node": "^12.7.1",
|
||||||
"@types/semver": "^6.0.2",
|
"@types/semver": "^6.0.2",
|
||||||
"babel-jest": "^29.5.0",
|
"babel-jest": "^24.9.0",
|
||||||
"fs-extra": "^8.1.0",
|
"fs-extra": "^8.1.0",
|
||||||
"husky": "^3.0.3",
|
"husky": "^3.0.3",
|
||||||
"jest": "^29.5.0",
|
"jest": "^24.9.0",
|
||||||
"mdast-util-to-string": "^1.0.6",
|
"mdast-util-to-string": "^1.0.6",
|
||||||
"remark-parse": "^7.0.1",
|
"remark-parse": "^7.0.1",
|
||||||
"remark-stringify": "^7.0.3",
|
"remark-stringify": "^7.0.3",
|
||||||
@@ -52,8 +48,5 @@
|
|||||||
"husky": {
|
"husky": {
|
||||||
"hooks": {}
|
"hooks": {}
|
||||||
},
|
},
|
||||||
"prettier": {},
|
"prettier": {}
|
||||||
"resolutions": {
|
|
||||||
"**/@octokit/core": "4.2.0"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`version creates simple PR 1`] = `
|
exports[`version creates simple PR 1`] = `
|
||||||
[
|
Array [
|
||||||
{
|
Object {
|
||||||
"base": "some-branch",
|
"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.
|
"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.
|
||||||
|
|
||||||
|
|
||||||
# Releases
|
# Releases
|
||||||
## simple-project-pkg-a@1.1.0
|
## simple-project-pkg-a@1.1.0
|
||||||
|
|
||||||
@@ -33,53 +32,12 @@ 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`] = `
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"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.
|
|
||||||
|
|
||||||
|
|
||||||
# Releases
|
|
||||||
|
|
||||||
> All release information have been omitted from this message, as the content exceeds the size limit.",
|
|
||||||
"head": "changeset-release/some-branch",
|
|
||||||
"owner": "changesets",
|
|
||||||
"repo": "action",
|
|
||||||
"title": "Version Packages",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`version does not include changelog entries if full message exceeds size limit 1`] = `
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"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.
|
|
||||||
|
|
||||||
|
|
||||||
# Releases
|
|
||||||
|
|
||||||
> The changelog information of each package has been omitted from this message, as the content exceeds the size limit.
|
|
||||||
|
|
||||||
## simple-project-pkg-a@1.1.0
|
|
||||||
|
|
||||||
",
|
|
||||||
"head": "changeset-release/some-branch",
|
|
||||||
"owner": "changesets",
|
|
||||||
"repo": "action",
|
|
||||||
"title": "Version Packages",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`version doesn't include ignored package that got a dependency update in the PR body 1`] = `
|
exports[`version doesn't include ignored package that got a dependency update in the PR body 1`] = `
|
||||||
[
|
Array [
|
||||||
{
|
Object {
|
||||||
"base": "some-branch",
|
"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.
|
"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.
|
||||||
|
|
||||||
|
|
||||||
# Releases
|
# Releases
|
||||||
## ignored-package-pkg-b@1.1.0
|
## ignored-package-pkg-b@1.1.0
|
||||||
|
|
||||||
@@ -96,12 +54,11 @@ exports[`version doesn't include ignored package that got a dependency update in
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`version only includes bumped packages in the PR body 1`] = `
|
exports[`version only includes bumped packages in the PR body 1`] = `
|
||||||
[
|
Array [
|
||||||
{
|
Object {
|
||||||
"base": "some-branch",
|
"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.
|
"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.
|
||||||
|
|
||||||
|
|
||||||
# Releases
|
# Releases
|
||||||
## simple-project-pkg-a@1.1.0
|
## simple-project-pkg-a@1.1.0
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`it sorts the things right 1`] = `
|
exports[`it sorts the things right 1`] = `
|
||||||
[
|
Array [
|
||||||
{
|
Object {
|
||||||
"highestLevel": 3,
|
"highestLevel": 3,
|
||||||
"name": "c",
|
"name": "c",
|
||||||
"private": false,
|
"private": false,
|
||||||
},
|
},
|
||||||
{
|
Object {
|
||||||
"highestLevel": 1,
|
"highestLevel": 1,
|
||||||
"name": "b",
|
"name": "b",
|
||||||
"private": false,
|
"private": false,
|
||||||
},
|
},
|
||||||
{
|
Object {
|
||||||
"highestLevel": 3,
|
"highestLevel": 3,
|
||||||
"name": "a",
|
"name": "a",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
+4
-3
@@ -1,4 +1,5 @@
|
|||||||
import { exec, getExecOutput } from "@actions/exec";
|
import { exec } from "@actions/exec";
|
||||||
|
import { execWithOutput } from "./utils";
|
||||||
|
|
||||||
export const setupUser = async () => {
|
export const setupUser = async () => {
|
||||||
await exec("git", [
|
await exec("git", [
|
||||||
@@ -34,7 +35,7 @@ export const pushTags = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const switchToMaybeExistingBranch = async (branch: string) => {
|
export const switchToMaybeExistingBranch = async (branch: string) => {
|
||||||
let { stderr } = await getExecOutput("git", ["checkout", branch], {
|
let { stderr } = await execWithOutput("git", ["checkout", branch], {
|
||||||
ignoreReturnCode: true,
|
ignoreReturnCode: true,
|
||||||
});
|
});
|
||||||
let isCreatingBranch = !stderr
|
let isCreatingBranch = !stderr
|
||||||
@@ -58,6 +59,6 @@ export const commitAll = async (message: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const checkIfClean = async (): Promise<boolean> => {
|
export const checkIfClean = async (): Promise<boolean> => {
|
||||||
const { stdout } = await getExecOutput("git", ["status", "--porcelain"]);
|
const { stdout } = await execWithOutput("git", ["status", "--porcelain"]);
|
||||||
return !stdout.length;
|
return !stdout.length;
|
||||||
};
|
};
|
||||||
|
|||||||
+16
-25
@@ -14,32 +14,29 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const inputCwd = core.getInput("cwd");
|
|
||||||
if (inputCwd) {
|
|
||||||
core.info("changing directory to the one given as the input");
|
|
||||||
process.chdir(inputCwd);
|
|
||||||
}
|
|
||||||
|
|
||||||
let setupGitUser = core.getBooleanInput("setupGitUser");
|
let setupGitUser = core.getBooleanInput("setupGitUser");
|
||||||
|
|
||||||
if (setupGitUser) {
|
if (setupGitUser) {
|
||||||
core.info("setting git user");
|
console.log("setting git user");
|
||||||
await gitUtils.setupUser();
|
await gitUtils.setupUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info("setting GitHub credentials");
|
console.log("setting GitHub credentials");
|
||||||
await fs.writeFile(
|
await fs.writeFile(
|
||||||
`${process.env.HOME}/.netrc`,
|
`${process.env.HOME}/.netrc`,
|
||||||
`machine github.com\nlogin github-actions[bot]\npassword ${githubToken}`
|
`machine github.com\nlogin github-actions[bot]\npassword ${githubToken}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const inputCwd = core.getInput("cwd");
|
||||||
|
if (inputCwd) {
|
||||||
|
console.log("changing directory to the one given as the input");
|
||||||
|
process.chdir(inputCwd);
|
||||||
|
}
|
||||||
|
|
||||||
let { changesets } = await readChangesetState();
|
let { changesets } = await readChangesetState();
|
||||||
|
|
||||||
let publishScript = core.getInput("publish");
|
let publishScript = core.getInput("publish");
|
||||||
let hasChangesets = changesets.length !== 0;
|
let hasChangesets = changesets.length !== 0;
|
||||||
const hasNonEmptyChangesets = changesets.some(
|
|
||||||
(changeset) => changeset.releases.length > 0
|
|
||||||
);
|
|
||||||
let hasPublishScript = !!publishScript;
|
let hasPublishScript = !!publishScript;
|
||||||
|
|
||||||
core.setOutput("published", "false");
|
core.setOutput("published", "false");
|
||||||
@@ -48,27 +45,27 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
|||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case !hasChangesets && !hasPublishScript:
|
case !hasChangesets && !hasPublishScript:
|
||||||
core.info("No changesets found");
|
console.log("No changesets found");
|
||||||
return;
|
return;
|
||||||
case !hasChangesets && hasPublishScript: {
|
case !hasChangesets && hasPublishScript: {
|
||||||
core.info(
|
console.log(
|
||||||
"No changesets found, attempting to publish any unpublished packages to npm"
|
"No changesets found, attempting to publish any unpublished packages to npm"
|
||||||
);
|
);
|
||||||
|
|
||||||
let userNpmrcPath = `${process.env.HOME}/.npmrc`;
|
let userNpmrcPath = `${process.env.HOME}/.npmrc`;
|
||||||
if (fs.existsSync(userNpmrcPath)) {
|
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 userNpmrcContent = await fs.readFile(userNpmrcPath, "utf8");
|
||||||
const authLine = userNpmrcContent.split("\n").find((line) => {
|
const authLine = userNpmrcContent.split("\n").find((line) => {
|
||||||
// check based on https://github.com/npm/cli/blob/8f8f71e4dd5ee66b3b17888faad5a7bf6c657eed/test/lib/adduser.js#L103-L105
|
// 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);
|
return /^\s*\/\/registry\.npmjs\.org\/:[_-]authToken=/i.test(line);
|
||||||
});
|
});
|
||||||
if (authLine) {
|
if (authLine) {
|
||||||
core.info(
|
console.log(
|
||||||
"Found existing auth token for the npm registry in the user .npmrc file"
|
"Found existing auth token for the npm registry in the user .npmrc file"
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
core.info(
|
console.log(
|
||||||
"Didn't find existing auth token for the npm registry in the user .npmrc file, creating one"
|
"Didn't find existing auth token for the npm registry in the user .npmrc file, creating one"
|
||||||
);
|
);
|
||||||
fs.appendFileSync(
|
fs.appendFileSync(
|
||||||
@@ -77,7 +74,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
core.info("No user .npmrc file found, creating one");
|
console.log("No user .npmrc file found, creating one");
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
userNpmrcPath,
|
userNpmrcPath,
|
||||||
`//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`
|
`//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`
|
||||||
@@ -99,23 +96,17 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case hasChangesets && !hasNonEmptyChangesets:
|
|
||||||
core.info("All changesets are empty; not creating PR");
|
|
||||||
return;
|
|
||||||
case hasChangesets:
|
case hasChangesets:
|
||||||
const { pullRequestNumber } = await runVersion({
|
await runVersion({
|
||||||
script: getOptionalInput("version"),
|
script: getOptionalInput("version"),
|
||||||
githubToken,
|
githubToken,
|
||||||
prTitle: getOptionalInput("title"),
|
prTitle: getOptionalInput("title"),
|
||||||
commitMessage: getOptionalInput("commit"),
|
commitMessage: getOptionalInput("commit"),
|
||||||
hasPublishScript,
|
hasPublishScript,
|
||||||
});
|
});
|
||||||
|
|
||||||
core.setOutput("pullRequestNumber", String(pullRequestNumber));
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
})().catch((err) => {
|
})().catch((err) => {
|
||||||
core.error(err);
|
console.error(err);
|
||||||
core.setFailed(err.message);
|
core.setFailed(err.message);
|
||||||
});
|
});
|
||||||
|
|||||||
+2
-144
@@ -1,6 +1,5 @@
|
|||||||
import fixturez from "fixturez";
|
import fixturez from "fixturez";
|
||||||
import * as github from "@actions/github";
|
import * as github from "@actions/github";
|
||||||
import * as githubUtils from "@actions/github/lib/utils";
|
|
||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import writeChangeset from "@changesets/write";
|
import writeChangeset from "@changesets/write";
|
||||||
@@ -16,19 +15,7 @@ jest.mock("@actions/github", () => ({
|
|||||||
ref: "refs/heads/some-branch",
|
ref: "refs/heads/some-branch",
|
||||||
sha: "xeac7",
|
sha: "xeac7",
|
||||||
},
|
},
|
||||||
}));
|
getOctokit: jest.fn(),
|
||||||
jest.mock("@actions/github/lib/utils", () => ({
|
|
||||||
GitHub: {
|
|
||||||
plugin: () => {
|
|
||||||
// function necessary to be used as constructor
|
|
||||||
return function() {
|
|
||||||
return {
|
|
||||||
rest: mockedGithubMethods,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
getOctokitOptions: jest.fn(),
|
|
||||||
}));
|
}));
|
||||||
jest.mock("./gitUtils");
|
jest.mock("./gitUtils");
|
||||||
|
|
||||||
@@ -43,6 +30,7 @@ let mockedGithubMethods = {
|
|||||||
createRelease: jest.fn(),
|
createRelease: jest.fn(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
(github.getOctokit as any).mockImplementation(() => mockedGithubMethods);
|
||||||
|
|
||||||
let f = fixturez(__dirname);
|
let f = fixturez(__dirname);
|
||||||
|
|
||||||
@@ -69,10 +57,6 @@ describe("version", () => {
|
|||||||
() => ({ data: { items: [] } })
|
() => ({ data: { items: [] } })
|
||||||
);
|
);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
|
||||||
data: { number: 123 },
|
|
||||||
}));
|
|
||||||
|
|
||||||
await writeChangesets(
|
await writeChangesets(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@@ -108,10 +92,6 @@ describe("version", () => {
|
|||||||
() => ({ data: { items: [] } })
|
() => ({ data: { items: [] } })
|
||||||
);
|
);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
|
||||||
data: { number: 123 },
|
|
||||||
}));
|
|
||||||
|
|
||||||
await writeChangesets(
|
await writeChangesets(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@@ -143,10 +123,6 @@ describe("version", () => {
|
|||||||
() => ({ data: { items: [] } })
|
() => ({ data: { items: [] } })
|
||||||
);
|
);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
|
||||||
data: { number: 123 },
|
|
||||||
}));
|
|
||||||
|
|
||||||
await writeChangesets(
|
await writeChangesets(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@@ -169,122 +145,4 @@ describe("version", () => {
|
|||||||
|
|
||||||
expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot();
|
expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not include changelog entries if full message exceeds size limit", async () => {
|
|
||||||
let cwd = f.copy("simple-project");
|
|
||||||
linkNodeModules(cwd);
|
|
||||||
|
|
||||||
mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce(
|
|
||||||
() => ({ data: { items: [] } })
|
|
||||||
);
|
|
||||||
|
|
||||||
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
|
||||||
data: { number: 123 },
|
|
||||||
}));
|
|
||||||
|
|
||||||
await writeChangesets(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
releases: [
|
|
||||||
{
|
|
||||||
name: "simple-project-pkg-a",
|
|
||||||
type: "minor",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
summary: `# Non manus superum
|
|
||||||
|
|
||||||
## Nec cornibus aequa numinis multo onerosior adde
|
|
||||||
|
|
||||||
Lorem markdownum undas consumpserat malas, nec est lupus; memorant gentisque ab
|
|
||||||
limine auctore. Eatque et promptu deficit, quam videtur aequa est **faciat**,
|
|
||||||
locus. Potentia deus habebat pia quam qui coniuge frater, tibi habent fertque
|
|
||||||
viribus. E et cognoscere arcus, lacus aut sic pro crimina fuit tum **auxilium**
|
|
||||||
dictis, qua, in.
|
|
||||||
|
|
||||||
In modo. Nomen illa membra.
|
|
||||||
|
|
||||||
> Corpora gratissima parens montibus tum coeperat qua remulus caelum Helenamque?
|
|
||||||
> Non poenae modulatur Amathunta in concita superi, procerum pariter rapto cornu
|
|
||||||
> munera. Perrhaebum parvo manus contingere, morari, spes per totiens ut
|
|
||||||
> dividite proculcat facit, visa.
|
|
||||||
|
|
||||||
Adspicit sequitur diffamatamque superi Phoebo qua quin lammina utque: per? Exit
|
|
||||||
decus aut hac inpia, seducta mirantia extremo. Vidi pedes vetus. Saturnius
|
|
||||||
fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
cwd
|
|
||||||
);
|
|
||||||
|
|
||||||
await runVersion({
|
|
||||||
githubToken: "@@GITHUB_TOKEN",
|
|
||||||
cwd,
|
|
||||||
prBodyMaxCharacters: 1000,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot();
|
|
||||||
expect(mockedGithubMethods.pulls.create.mock.calls[0][0].body).toMatch(
|
|
||||||
/The changelog information of each package has been omitted from this message/
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("does not include any release information if a message with simplified release info exceeds size limit", async () => {
|
|
||||||
let cwd = f.copy("simple-project");
|
|
||||||
linkNodeModules(cwd);
|
|
||||||
|
|
||||||
mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce(
|
|
||||||
() => ({ data: { items: [] } })
|
|
||||||
);
|
|
||||||
|
|
||||||
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
|
||||||
data: { number: 123 },
|
|
||||||
}));
|
|
||||||
|
|
||||||
await writeChangesets(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
releases: [
|
|
||||||
{
|
|
||||||
name: "simple-project-pkg-a",
|
|
||||||
type: "minor",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
summary: `# Non manus superum
|
|
||||||
|
|
||||||
## Nec cornibus aequa numinis multo onerosior adde
|
|
||||||
|
|
||||||
Lorem markdownum undas consumpserat malas, nec est lupus; memorant gentisque ab
|
|
||||||
limine auctore. Eatque et promptu deficit, quam videtur aequa est **faciat**,
|
|
||||||
locus. Potentia deus habebat pia quam qui coniuge frater, tibi habent fertque
|
|
||||||
viribus. E et cognoscere arcus, lacus aut sic pro crimina fuit tum **auxilium**
|
|
||||||
dictis, qua, in.
|
|
||||||
|
|
||||||
In modo. Nomen illa membra.
|
|
||||||
|
|
||||||
> Corpora gratissima parens montibus tum coeperat qua remulus caelum Helenamque?
|
|
||||||
> Non poenae modulatur Amathunta in concita superi, procerum pariter rapto cornu
|
|
||||||
> munera. Perrhaebum parvo manus contingere, morari, spes per totiens ut
|
|
||||||
> dividite proculcat facit, visa.
|
|
||||||
|
|
||||||
Adspicit sequitur diffamatamque superi Phoebo qua quin lammina utque: per? Exit
|
|
||||||
decus aut hac inpia, seducta mirantia extremo. Vidi pedes vetus. Saturnius
|
|
||||||
fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
cwd
|
|
||||||
);
|
|
||||||
|
|
||||||
await runVersion({
|
|
||||||
githubToken: "@@GITHUB_TOKEN",
|
|
||||||
cwd,
|
|
||||||
prBodyMaxCharacters: 500,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot();
|
|
||||||
expect(mockedGithubMethods.pulls.create.mock.calls[0][0].body).toMatch(
|
|
||||||
/All release information have been omitted from this message, as the content exceeds the size limit/
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
+55
-168
@@ -1,14 +1,12 @@
|
|||||||
import { exec, getExecOutput } from "@actions/exec";
|
import { exec } from "@actions/exec";
|
||||||
import { GitHub, getOctokitOptions } from "@actions/github/lib/utils";
|
|
||||||
import * as github from "@actions/github";
|
import * as github from "@actions/github";
|
||||||
import * as core from "@actions/core";
|
|
||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
import { getPackages, Package } from "@manypkg/get-packages";
|
import { getPackages, Package } from "@manypkg/get-packages";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import * as semver from "semver";
|
import * as semver from "semver";
|
||||||
import { PreState } from "@changesets/types";
|
|
||||||
import {
|
import {
|
||||||
getChangelogEntry,
|
getChangelogEntry,
|
||||||
|
execWithOutput,
|
||||||
getChangedPackages,
|
getChangedPackages,
|
||||||
sortTheThings,
|
sortTheThings,
|
||||||
getVersionsByDirectory,
|
getVersionsByDirectory,
|
||||||
@@ -16,52 +14,9 @@ import {
|
|||||||
import * as gitUtils from "./gitUtils";
|
import * as gitUtils from "./gitUtils";
|
||||||
import readChangesetState from "./readChangesetState";
|
import readChangesetState from "./readChangesetState";
|
||||||
import resolveFrom from "resolve-from";
|
import resolveFrom from "resolve-from";
|
||||||
import { throttling } from "@octokit/plugin-throttling";
|
|
||||||
// temporary workaround for https://github.com/octokit/plugin-throttling.js/pull/590
|
|
||||||
import type {} from "@octokit/plugin-throttling/dist-types/types.d";
|
|
||||||
|
|
||||||
// GitHub Issues/PRs messages have a max size limit on the
|
|
||||||
// message body payload.
|
|
||||||
// `body is too long (maximum is 65536 characters)`.
|
|
||||||
// To avoid that, we ensure to cap the message to 60k chars.
|
|
||||||
const MAX_CHARACTERS_PER_MESSAGE = 60000;
|
|
||||||
|
|
||||||
const setupOctokit = (githubToken) => {
|
|
||||||
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 (
|
const createRelease = async (
|
||||||
octokit: ReturnType<typeof GitHub>,
|
octokit: ReturnType<typeof github.getOctokit>,
|
||||||
{ pkg, tagName }: { pkg: Package; tagName: string }
|
{ pkg, tagName }: { pkg: Package; tagName: string }
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
@@ -78,7 +33,7 @@ const createRelease = async (
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await octokit.rest.repos.createRelease({
|
await octokit.repos.createRelease({
|
||||||
name: tagName,
|
name: tagName,
|
||||||
tag_name: tagName,
|
tag_name: tagName,
|
||||||
body: changelogEntry.content,
|
body: changelogEntry.content,
|
||||||
@@ -117,11 +72,10 @@ export async function runPublish({
|
|||||||
createGithubReleases,
|
createGithubReleases,
|
||||||
cwd = process.cwd(),
|
cwd = process.cwd(),
|
||||||
}: PublishOptions): Promise<PublishResult> {
|
}: PublishOptions): Promise<PublishResult> {
|
||||||
const octokit = setupOctokit(githubToken);
|
let octokit = github.getOctokit(githubToken);
|
||||||
|
|
||||||
let [publishCommand, ...publishArgs] = script.split(/\s+/);
|
let [publishCommand, ...publishArgs] = script.split(/\s+/);
|
||||||
|
|
||||||
let changesetPublishOutput = await getExecOutput(
|
let changesetPublishOutput = await execWithOutput(
|
||||||
publishCommand,
|
publishCommand,
|
||||||
publishArgs,
|
publishArgs,
|
||||||
{ cwd }
|
{ cwd }
|
||||||
@@ -214,75 +168,6 @@ const requireChangesetsCliPkgJson = (cwd: string) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
type GetMessageOptions = {
|
|
||||||
hasPublishScript: boolean;
|
|
||||||
branch: string;
|
|
||||||
changedPackagesInfo: {
|
|
||||||
highestLevel: number;
|
|
||||||
private: boolean;
|
|
||||||
content: string;
|
|
||||||
header: string;
|
|
||||||
}[];
|
|
||||||
prBodyMaxCharacters: number;
|
|
||||||
preState?: PreState;
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function getVersionPrBody({
|
|
||||||
hasPublishScript,
|
|
||||||
preState,
|
|
||||||
changedPackagesInfo,
|
|
||||||
prBodyMaxCharacters,
|
|
||||||
branch,
|
|
||||||
}: GetMessageOptions) {
|
|
||||||
let messageHeader = `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 ${
|
|
||||||
hasPublishScript
|
|
||||||
? `the packages will be published to npm automatically`
|
|
||||||
: `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 ${branch}, this PR will be updated.
|
|
||||||
`;
|
|
||||||
let messagePrestate = !!preState
|
|
||||||
? `⚠️⚠️⚠️⚠️⚠️⚠️
|
|
||||||
|
|
||||||
\`${branch}\` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run \`changeset pre exit\` on \`${branch}\`.
|
|
||||||
|
|
||||||
⚠️⚠️⚠️⚠️⚠️⚠️
|
|
||||||
`
|
|
||||||
: "";
|
|
||||||
let messageReleasesHeading = `# Releases`;
|
|
||||||
|
|
||||||
let fullMessage = [
|
|
||||||
messageHeader,
|
|
||||||
messagePrestate,
|
|
||||||
messageReleasesHeading,
|
|
||||||
...changedPackagesInfo.map((info) => `${info.header}\n\n${info.content}`),
|
|
||||||
].join("\n");
|
|
||||||
|
|
||||||
// Check that the message does not exceed the size limit.
|
|
||||||
// If not, omit the changelog entries of each package.
|
|
||||||
if (fullMessage.length > prBodyMaxCharacters) {
|
|
||||||
fullMessage = [
|
|
||||||
messageHeader,
|
|
||||||
messagePrestate,
|
|
||||||
messageReleasesHeading,
|
|
||||||
`\n> The changelog information of each package has been omitted from this message, as the content exceeds the size limit.\n`,
|
|
||||||
...changedPackagesInfo.map((info) => `${info.header}\n\n`),
|
|
||||||
].join("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check (again) that the message is within the size limit.
|
|
||||||
// If not, omit all release content this time.
|
|
||||||
if (fullMessage.length > prBodyMaxCharacters) {
|
|
||||||
fullMessage = [
|
|
||||||
messageHeader,
|
|
||||||
messagePrestate,
|
|
||||||
messageReleasesHeading,
|
|
||||||
`\n> All release information have been omitted from this message, as the content exceeds the size limit.`,
|
|
||||||
].join("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return fullMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
type VersionOptions = {
|
type VersionOptions = {
|
||||||
script?: string;
|
script?: string;
|
||||||
githubToken: string;
|
githubToken: string;
|
||||||
@@ -290,11 +175,6 @@ type VersionOptions = {
|
|||||||
prTitle?: string;
|
prTitle?: string;
|
||||||
commitMessage?: string;
|
commitMessage?: string;
|
||||||
hasPublishScript?: boolean;
|
hasPublishScript?: boolean;
|
||||||
prBodyMaxCharacters?: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
type RunVersionResult = {
|
|
||||||
pullRequestNumber: number;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function runVersion({
|
export async function runVersion({
|
||||||
@@ -304,14 +184,11 @@ export async function runVersion({
|
|||||||
prTitle = "Version Packages",
|
prTitle = "Version Packages",
|
||||||
commitMessage = "Version Packages",
|
commitMessage = "Version Packages",
|
||||||
hasPublishScript = false,
|
hasPublishScript = false,
|
||||||
prBodyMaxCharacters = MAX_CHARACTERS_PER_MESSAGE,
|
}: VersionOptions) {
|
||||||
}: VersionOptions): Promise<RunVersionResult> {
|
|
||||||
const octokit = setupOctokit(githubToken);
|
|
||||||
|
|
||||||
let repo = `${github.context.repo.owner}/${github.context.repo.repo}`;
|
let repo = `${github.context.repo.owner}/${github.context.repo.repo}`;
|
||||||
let branch = github.context.ref.replace("refs/heads/", "");
|
let branch = github.context.ref.replace("refs/heads/", "");
|
||||||
let versionBranch = `changeset-release/${branch}`;
|
let versionBranch = `changeset-release/${branch}`;
|
||||||
|
let octokit = github.getOctokit(githubToken);
|
||||||
let { preState } = await readChangesetState(cwd);
|
let { preState } = await readChangesetState(cwd);
|
||||||
|
|
||||||
await gitUtils.switchToMaybeExistingBranch(versionBranch);
|
await gitUtils.switchToMaybeExistingBranch(versionBranch);
|
||||||
@@ -332,27 +209,60 @@ export async function runVersion({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let searchQuery = `repo:${repo}+state:open+head:${versionBranch}+base:${branch}+is:pull-request`;
|
let searchQuery = `repo:${repo}+state:open+head:${versionBranch}+base:${branch}`;
|
||||||
let searchResultPromise = octokit.rest.search.issuesAndPullRequests({
|
let searchResultPromise = octokit.search.issuesAndPullRequests({
|
||||||
q: searchQuery,
|
q: searchQuery,
|
||||||
});
|
});
|
||||||
let changedPackages = await getChangedPackages(cwd, versionsByDirectory);
|
let changedPackages = await getChangedPackages(cwd, versionsByDirectory);
|
||||||
let changedPackagesInfoPromises = Promise.all(
|
|
||||||
|
let prBodyPromise = (async () => {
|
||||||
|
return (
|
||||||
|
`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 ${
|
||||||
|
hasPublishScript
|
||||||
|
? `the packages will be published to npm automatically`
|
||||||
|
: `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 ${branch}, this PR will be updated.
|
||||||
|
${
|
||||||
|
!!preState
|
||||||
|
? `
|
||||||
|
⚠️⚠️⚠️⚠️⚠️⚠️
|
||||||
|
|
||||||
|
\`${branch}\` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run \`changeset pre exit\` on \`${branch}\`.
|
||||||
|
|
||||||
|
⚠️⚠️⚠️⚠️⚠️⚠️
|
||||||
|
`
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
# Releases
|
||||||
|
` +
|
||||||
|
(
|
||||||
|
await Promise.all(
|
||||||
changedPackages.map(async (pkg) => {
|
changedPackages.map(async (pkg) => {
|
||||||
let changelogContents = await fs.readFile(
|
let changelogContents = await fs.readFile(
|
||||||
path.join(pkg.dir, "CHANGELOG.md"),
|
path.join(pkg.dir, "CHANGELOG.md"),
|
||||||
"utf8"
|
"utf8"
|
||||||
);
|
);
|
||||||
|
|
||||||
let entry = getChangelogEntry(changelogContents, pkg.packageJson.version);
|
let entry = getChangelogEntry(
|
||||||
|
changelogContents,
|
||||||
|
pkg.packageJson.version
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
highestLevel: entry.highestLevel,
|
highestLevel: entry.highestLevel,
|
||||||
private: !!pkg.packageJson.private,
|
private: !!pkg.packageJson.private,
|
||||||
content: entry.content,
|
content:
|
||||||
header: `## ${pkg.packageJson.name}@${pkg.packageJson.version}`,
|
`## ${pkg.packageJson.name}@${pkg.packageJson.version}\n\n` +
|
||||||
|
entry.content,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.filter((x) => x)
|
||||||
|
.sort(sortTheThings)
|
||||||
|
.map((x) => x.content)
|
||||||
|
.join("\n ")
|
||||||
);
|
);
|
||||||
|
})();
|
||||||
|
|
||||||
const finalPrTitle = `${prTitle}${!!preState ? ` (${preState.tag})` : ""}`;
|
const finalPrTitle = `${prTitle}${!!preState ? ` (${preState.tag})` : ""}`;
|
||||||
|
|
||||||
@@ -367,46 +277,23 @@ export async function runVersion({
|
|||||||
await gitUtils.push(versionBranch, { force: true });
|
await gitUtils.push(versionBranch, { force: true });
|
||||||
|
|
||||||
let searchResult = await searchResultPromise;
|
let searchResult = await searchResultPromise;
|
||||||
core.info(JSON.stringify(searchResult.data, null, 2));
|
console.log(JSON.stringify(searchResult.data, null, 2));
|
||||||
|
|
||||||
const changedPackagesInfo = (await changedPackagesInfoPromises)
|
|
||||||
.filter((x) => x)
|
|
||||||
.sort(sortTheThings);
|
|
||||||
|
|
||||||
let prBody = await getVersionPrBody({
|
|
||||||
hasPublishScript,
|
|
||||||
preState,
|
|
||||||
branch,
|
|
||||||
changedPackagesInfo,
|
|
||||||
prBodyMaxCharacters,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (searchResult.data.items.length === 0) {
|
if (searchResult.data.items.length === 0) {
|
||||||
core.info("creating pull request");
|
console.log("creating pull request");
|
||||||
const { data: newPullRequest } = await octokit.rest.pulls.create({
|
await octokit.pulls.create({
|
||||||
base: branch,
|
base: branch,
|
||||||
head: versionBranch,
|
head: versionBranch,
|
||||||
title: finalPrTitle,
|
title: finalPrTitle,
|
||||||
body: prBody,
|
body: await prBodyPromise,
|
||||||
...github.context.repo,
|
...github.context.repo,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
|
||||||
pullRequestNumber: newPullRequest.number,
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
const [pullRequest] = searchResult.data.items;
|
octokit.pulls.update({
|
||||||
|
pull_number: searchResult.data.items[0].number,
|
||||||
core.info(`updating found pull request #${pullRequest.number}`);
|
|
||||||
await octokit.rest.pulls.update({
|
|
||||||
pull_number: pullRequest.number,
|
|
||||||
title: finalPrTitle,
|
title: finalPrTitle,
|
||||||
body: prBody,
|
body: await prBodyPromise,
|
||||||
...github.context.repo,
|
...github.context.repo,
|
||||||
});
|
});
|
||||||
|
console.log("pull request found");
|
||||||
return {
|
|
||||||
pullRequestNumber: pullRequest.number,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,6 +87,32 @@ export function getChangelogEntry(changelog: string, version: string) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function execWithOutput(
|
||||||
|
command: string,
|
||||||
|
args?: string[],
|
||||||
|
options?: { ignoreReturnCode?: boolean; cwd?: string }
|
||||||
|
) {
|
||||||
|
let myOutput = "";
|
||||||
|
let myError = "";
|
||||||
|
|
||||||
|
return {
|
||||||
|
code: await exec(command, args, {
|
||||||
|
listeners: {
|
||||||
|
stdout: (data: Buffer) => {
|
||||||
|
myOutput += data.toString();
|
||||||
|
},
|
||||||
|
stderr: (data: Buffer) => {
|
||||||
|
myError += data.toString();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
...options,
|
||||||
|
}),
|
||||||
|
stdout: myOutput,
|
||||||
|
stderr: myError,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function sortTheThings(
|
export function sortTheThings(
|
||||||
a: { private: boolean; highestLevel: number },
|
a: { private: boolean; highestLevel: number },
|
||||||
b: { private: boolean; highestLevel: number }
|
b: { private: boolean; highestLevel: number }
|
||||||
|
|||||||
Reference in New Issue
Block a user