mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
Compare commits
@@ -0,0 +1,8 @@
|
||||
# Changesets
|
||||
|
||||
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
|
||||
with multi-package repos, or single-package repos to help you version and publish your code. You can
|
||||
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
|
||||
|
||||
We have a quick list of common questions to get you started engaging with this project in
|
||||
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"$schema": "https://unpkg.com/@changesets/config@1.6.2/schema.json",
|
||||
"changelog": [
|
||||
"@changesets/changelog-github",
|
||||
{ "repo": "changesets/action" }
|
||||
],
|
||||
"commit": false,
|
||||
"linked": [],
|
||||
"access": "restricted",
|
||||
"baseBranch": "main",
|
||||
"updateInternalDependencies": "patch",
|
||||
"ignore": []
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "npm" # See documentation for possible values
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
@@ -1,6 +1,6 @@
|
||||
name: Node CI
|
||||
|
||||
on: [push]
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -9,15 +9,16 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Use Node.js 12
|
||||
uses: actions/setup-node@v1
|
||||
- name: Use Node.js 20
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 12.x
|
||||
node-version: 20.x
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn
|
||||
- name: Install Dependencies
|
||||
run: yarn --frozen-lockfile
|
||||
|
||||
- name: Test
|
||||
run: yarn test
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
name: Version or Publish
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
||||
|
||||
jobs:
|
||||
changesets:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Use Node.js 20
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20.x
|
||||
|
||||
- name: Install Dependencies
|
||||
run: yarn --frozen-lockfile
|
||||
|
||||
- name: Build
|
||||
run: yarn build
|
||||
|
||||
- name: Create Release Pull Request or Publish
|
||||
id: changesets
|
||||
uses: ./
|
||||
with:
|
||||
version: yarn bump
|
||||
publish: yarn release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -2,3 +2,5 @@ node_modules
|
||||
.parcel-cache
|
||||
.cache
|
||||
*.log
|
||||
|
||||
dist/
|
||||
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
# @changesets/action
|
||||
|
||||
## 1.5.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#391](https://github.com/changesets/action/pull/391) [`207dc3d`](https://github.com/changesets/action/commit/207dc3da2d1907cae0454ce123935401332be72b) Thanks [@s0](https://github.com/s0)! - Introduce a new input `commitMode` that allows using the GitHub API for pushing tags and commits instead of the Git CLI.
|
||||
|
||||
When used with `"github-api"` value all tags and commits will be attributed to the user whose GITHUB_TOKEN is used, and also signed using GitHub's internal GPG key.
|
||||
|
||||
## 1.4.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#448](https://github.com/changesets/action/pull/448) [`8b16070`](https://github.com/changesets/action/commit/8b16070fe386eed3456c83eeed9460160432cf26) Thanks [@bluwy](https://github.com/bluwy)! - Use full git email (`41898282+github-actions[bot]@users.noreply.github.com`) for github-actions bot when making commits
|
||||
|
||||
## 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
|
||||
|
||||
- [#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
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#144](https://github.com/changesets/action/pull/144) [`898d125`](https://github.com/changesets/action/commit/898d125cee6ba00c6a11b6cadca512752c6c910c) Thanks [@Andarist](https://github.com/Andarist)! - Updated all Changesets dependencies. This should fix parsing issues for completely empty summaries that has been fixed in `@changesets/parse@0.3.11`.
|
||||
|
||||
## 1.2.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#130](https://github.com/changesets/action/pull/130) [`5c0997b`](https://github.com/changesets/action/commit/5c0997b25e175ecf5e1723ba07210bbcea5d92fb) Thanks [@akphi](https://github.com/akphi)! - Added `createGithubReleases` input option (defaults to `true`) to control whether to create Github releases during publish or not.
|
||||
|
||||
* [#134](https://github.com/changesets/action/pull/134) [`1ed9bc2`](https://github.com/changesets/action/commit/1ed9bc24b7a56462c183eb815c8f4bdf0e2e5785) Thanks [@dmregister](https://github.com/dmregister)! - Added `cwd` input option that can be used in projects that are not in the root directory.
|
||||
|
||||
## 1.1.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#128](https://github.com/changesets/action/pull/128) [`1937303`](https://github.com/changesets/action/commit/19373036c4bad4b0183344b6f2623a3b0e42da6c) Thanks [@dhruvdutt](https://github.com/dhruvdutt)! - Setup the git user in the local config instead of the global one.
|
||||
|
||||
* [#131](https://github.com/changesets/action/pull/131) [`d3db9ec`](https://github.com/changesets/action/commit/d3db9eceaf41d42c56d5370d504c86851627188f) Thanks [@jacklesliewise](https://github.com/jacklesliewise)! - Added `setupGitUser` option to enable or disable setting up a default git user
|
||||
|
||||
## 1.0.0
|
||||
|
||||
### Major Changes
|
||||
|
||||
- [#118](https://github.com/changesets/action/pull/118) [`05c863d`](https://github.com/changesets/action/commit/05c863d3f980125585016a593b5cb45b27d19c2c) Thanks [@Andarist](https://github.com/Andarist)! - From now on this action will be released using the Changesets-based workflow (using itself). Thanks to that we'll have a good release history. The users will be able to find specific versions of the action and will be able to track changes over time. It also improves the security as the build artifact will always get built in the CI environment, using a frozen lockfile.
|
||||
@@ -1,6 +1,6 @@
|
||||
# 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 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.
|
||||
This action for [Changesets](https://github.com/changesets/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.
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -10,10 +10,14 @@ This action for [Changesets](https://github.com/atlassian/changesets) creates a
|
||||
- version - The command to update version, edit CHANGELOG, read and delete changesets. Default to `changeset version` if not provided
|
||||
- commit - The commit message to use. 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`
|
||||
- createGithubReleases - A boolean value to indicate whether to create Github releases after `publish` or not. Default to `true`
|
||||
- commitMode - Specifies the commit mode. Use `"git-cli"` to push changes using the Git CLI, or `"github-api"` to push changes via the GitHub API. When using `"github-api"`, all commits and tags are GPG-signed and attributed to the user or app who owns the `GITHUB_TOKEN`. Default to `git-cli`.
|
||||
- cwd - Changes node's `process.cwd()` if the project is not located on the root. Default to `process.cwd()`
|
||||
|
||||
### Outputs
|
||||
|
||||
- published - A boolean value to indicate whether a publishing is happened or not
|
||||
- published - A boolean value to indicate whether a publishing has 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:
|
||||
@@ -28,7 +32,9 @@ name: Release
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
|
||||
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
||||
|
||||
jobs:
|
||||
release:
|
||||
@@ -36,21 +42,18 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@master
|
||||
with:
|
||||
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
|
||||
fetch-depth: 0
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Node.js 12.x
|
||||
uses: actions/setup-node@master
|
||||
- name: Setup Node.js 20
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 12.x
|
||||
node-version: 20
|
||||
|
||||
- name: Install Dependencies
|
||||
run: yarn
|
||||
|
||||
- name: Create Release Pull Request
|
||||
uses: changesets/action@master
|
||||
uses: changesets/action@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
@@ -65,7 +68,9 @@ name: Release
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
|
||||
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
||||
|
||||
jobs:
|
||||
release:
|
||||
@@ -73,22 +78,19 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@master
|
||||
with:
|
||||
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
|
||||
fetch-depth: 0
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Node.js 12.x
|
||||
uses: actions/setup-node@master
|
||||
- name: Setup Node.js 20.x
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 12.x
|
||||
node-version: 20.x
|
||||
|
||||
- name: Install Dependencies
|
||||
run: yarn
|
||||
|
||||
- name: Create Release Pull Request or Publish to npm
|
||||
id: changesets
|
||||
uses: changesets/action@master
|
||||
uses: changesets/action@v1
|
||||
with:
|
||||
# This expects you to have a script called release which does a build for your packages and calls changeset publish
|
||||
publish: yarn release
|
||||
@@ -115,13 +117,54 @@ For example, you can add a step before running the Changesets GitHub Action:
|
||||
- name: Creating .npmrc
|
||||
run: |
|
||||
cat << EOF > "$HOME/.npmrc"
|
||||
email=my@email.com
|
||||
//registry.npmjs.org/:_authToken=$NPM_TOKEN
|
||||
EOF
|
||||
env:
|
||||
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 20.x
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 20.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
|
||||
|
||||
If you need to add additional logic to the version command, you can do so by using a version script.
|
||||
@@ -134,7 +177,9 @@ name: Release
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
|
||||
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
||||
|
||||
jobs:
|
||||
release:
|
||||
@@ -142,20 +187,18 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@master
|
||||
with:
|
||||
fetch-depth: 0
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Node.js 12.x
|
||||
uses: actions/setup-node@master
|
||||
- name: Setup Node.js 20.x
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 12.x
|
||||
node-version: 20.x
|
||||
|
||||
- name: Install Dependencies
|
||||
run: yarn
|
||||
|
||||
- name: Create Release Pull Request
|
||||
uses: changesets/action@master
|
||||
uses: changesets/action@v1
|
||||
with:
|
||||
# this expects you to have a npm script called version that runs some logic and then calls `changeset version`.
|
||||
version: yarn version
|
||||
@@ -168,7 +211,7 @@ jobs:
|
||||
If you are using [Yarn Plug'n'Play](https://yarnpkg.com/features/pnp), you should use a custom `version` command so that the action can resolve the `changeset` CLI:
|
||||
|
||||
```yaml
|
||||
- uses: changesets/action@master
|
||||
- uses: changesets/action@v1
|
||||
with:
|
||||
version: yarn changeset version
|
||||
...
|
||||
|
||||
+27
-1
@@ -1,7 +1,7 @@
|
||||
name: Changesets
|
||||
description: A GitHub action to automate releases with Changesets
|
||||
runs:
|
||||
using: "node12"
|
||||
using: "node20"
|
||||
main: "dist/index.js"
|
||||
inputs:
|
||||
publish:
|
||||
@@ -10,6 +10,9 @@ inputs:
|
||||
version:
|
||||
description: "The command to update version, edit CHANGELOG, read and delete changesets. Default to `changeset version` if not provided"
|
||||
required: false
|
||||
cwd:
|
||||
description: Sets the cwd for the node process. Default to `process.cwd()`
|
||||
required: false
|
||||
commit:
|
||||
description: |
|
||||
The commit message. Default to `Version Packages`
|
||||
@@ -17,12 +20,35 @@ inputs:
|
||||
title:
|
||||
description: The pull request title. Default to `Version Packages`
|
||||
required: false
|
||||
setupGitUser:
|
||||
description: Sets up the git user for commits as `"github-actions[bot]"`. Default to `true`
|
||||
required: false
|
||||
default: true
|
||||
createGithubReleases:
|
||||
description: "A boolean value to indicate whether to create Github releases after `publish` or not"
|
||||
required: false
|
||||
default: true
|
||||
commitMode:
|
||||
description: >
|
||||
An enum to specify the commit mode. Use "git-cli" to push changes using the Git CLI,
|
||||
or "github-api" to push changes via the GitHub API. When using "github-api",
|
||||
all commits and tags are signed using GitHub's GPG key and attributed to the user
|
||||
or app who owns the GITHUB_TOKEN.
|
||||
required: false
|
||||
default: "git-cli"
|
||||
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
|
||||
publishedPackages:
|
||||
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"}]`
|
||||
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:
|
||||
icon: "package"
|
||||
color: "blue"
|
||||
|
||||
Vendored
+67
-909
File diff suppressed because one or more lines are too long
+44
-31
@@ -1,50 +1,63 @@
|
||||
{
|
||||
"name": "@changesets/action",
|
||||
"version": "0.1.0",
|
||||
"version": "1.5.0",
|
||||
"main": "dist/index.js",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@changesets/cli": "^2.9.1",
|
||||
"@changesets/write": "^0.1.3",
|
||||
"fixturez": "^1.1.0",
|
||||
"parcel": "^1.12.3",
|
||||
"prettier": "^2.0.5",
|
||||
"typescript": "^3.5.3"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "parcel build ./src/index.ts --no-source-maps --target=node --bundle-node-modules",
|
||||
"test": "jest",
|
||||
"test:watch": "yarn test --watch"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.4",
|
||||
"@actions/exec": "^1.0.4",
|
||||
"@actions/github": "^4.0.0",
|
||||
"@babel/core": "^7.13.10",
|
||||
"@babel/preset-env": "^7.13.10",
|
||||
"@babel/preset-typescript": "^7.13.0",
|
||||
"@changesets/pre": "^1.0.4",
|
||||
"@changesets/read": "^0.4.6",
|
||||
"@manypkg/get-packages": "^1.1.1",
|
||||
"@changesets/changelog-github": "^0.4.2",
|
||||
"@changesets/cli": "^2.20.0",
|
||||
"@changesets/write": "^0.1.6",
|
||||
"@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",
|
||||
"@types/jest": "^29.5.1",
|
||||
"@types/node": "^20.11.17",
|
||||
"@types/semver": "^7.5.0",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"babel-jest": "^29.5.0",
|
||||
"fixturez": "^1.1.0",
|
||||
"husky": "^3.0.3",
|
||||
"jest": "^24.9.0",
|
||||
"jest": "^29.5.0",
|
||||
"prettier": "^2.0.5",
|
||||
"typescript": "^5.0.4"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "ncc build src/index.ts -o dist --transpile-only --minify",
|
||||
"test": "jest",
|
||||
"test:watch": "yarn test --watch",
|
||||
"changeset": "changeset",
|
||||
"bump": "node ./scripts/bump.js",
|
||||
"release": "node ./scripts/release.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 20"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/github": "^5.1.1",
|
||||
"@changesets/ghcommit": "1.3.0",
|
||||
"@changesets/pre": "^1.0.9",
|
||||
"@changesets/read": "^0.5.3",
|
||||
"@manypkg/get-packages": "^1.1.3",
|
||||
"@octokit/plugin-throttling": "^5.2.1",
|
||||
"fs-extra": "^8.1.0",
|
||||
"mdast-util-to-string": "^1.0.6",
|
||||
"remark-parse": "^7.0.1",
|
||||
"remark-stringify": "^7.0.3",
|
||||
"resolve-from": "^5.0.0",
|
||||
"semver": "^6.3.0",
|
||||
"semver": "^7.5.3",
|
||||
"unified": "^8.3.2"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "yarn build && git add dist/index.js"
|
||||
}
|
||||
"hooks": {}
|
||||
},
|
||||
"prettier": {}
|
||||
"prettier": {},
|
||||
"resolutions": {
|
||||
"**/@octokit/core": "4.2.0",
|
||||
"trim": "^0.0.3",
|
||||
"y18n": "^4.0.1"
|
||||
},
|
||||
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { exec } = require("@actions/exec");
|
||||
|
||||
process.chdir(path.join(__dirname, ".."));
|
||||
|
||||
(async () => {
|
||||
await exec("changeset", ["version"]);
|
||||
|
||||
const releaseLine = `v${require("../package.json").version.split(".")[0]}`;
|
||||
|
||||
const readmePath = path.join(__dirname, "..", "README.md");
|
||||
const content = fs.readFileSync(readmePath, "utf8");
|
||||
const updatedContent = content.replace(
|
||||
/changesets\/action@[^\s]+/g,
|
||||
`changesets/action@${releaseLine}`
|
||||
);
|
||||
fs.writeFileSync(readmePath, updatedContent);
|
||||
})();
|
||||
@@ -0,0 +1,41 @@
|
||||
const path = require("path");
|
||||
const { exec, getExecOutput } = require("@actions/exec");
|
||||
|
||||
const { version } = require("../package.json");
|
||||
const tag = `v${version}`;
|
||||
const releaseLine = `v${version.split(".")[0]}`;
|
||||
|
||||
process.chdir(path.join(__dirname, ".."));
|
||||
|
||||
(async () => {
|
||||
const { exitCode, stderr } = await getExecOutput(
|
||||
`git`,
|
||||
["ls-remote", "--exit-code", "origin", "--tags", `refs/tags/${tag}`],
|
||||
{
|
||||
ignoreReturnCode: true,
|
||||
}
|
||||
);
|
||||
if (exitCode === 0) {
|
||||
console.log(
|
||||
`Action is not being published because version ${tag} is already published`
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (exitCode !== 2) {
|
||||
throw new Error(`git ls-remote exited with ${exitCode}:\n${stderr}`);
|
||||
}
|
||||
|
||||
await exec("git", ["checkout", "--detach"]);
|
||||
await exec("git", ["add", "--force", "dist"]);
|
||||
await exec("git", ["commit", "-m", tag]);
|
||||
|
||||
await exec("changeset", ["tag"]);
|
||||
|
||||
await exec("git", [
|
||||
"push",
|
||||
"--force",
|
||||
"--follow-tags",
|
||||
"origin",
|
||||
`HEAD:refs/heads/${releaseLine}`,
|
||||
]);
|
||||
})();
|
||||
@@ -1,11 +1,12 @@
|
||||
// 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.
|
||||
|
||||
|
||||
# Releases
|
||||
## simple-project-pkg-a@1.1.0
|
||||
|
||||
@@ -15,7 +16,7 @@ Array [
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [undefined]
|
||||
- Updated dependencies
|
||||
- simple-project-pkg-b@1.1.0
|
||||
|
||||
## simple-project-pkg-b@1.1.0
|
||||
@@ -32,12 +33,53 @@ Array [
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`version doesn't include ignored package that got a dependency update in the PR body 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
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`] = `
|
||||
[
|
||||
{
|
||||
"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
|
||||
## ignored-package-pkg-b@1.1.0
|
||||
|
||||
@@ -54,11 +96,12 @@ Array [
|
||||
`;
|
||||
|
||||
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.
|
||||
|
||||
|
||||
# Releases
|
||||
## simple-project-pkg-a@1.1.0
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
import * as core from "@actions/core";
|
||||
import { exec, getExecOutput } from "@actions/exec";
|
||||
import * as github from "@actions/github";
|
||||
import { commitChangesFromRepo } from "@changesets/ghcommit/git";
|
||||
import { Octokit } from "./octokit";
|
||||
|
||||
const push = async (branch: string, { force }: { force?: boolean } = {}) => {
|
||||
await exec(
|
||||
"git",
|
||||
["push", "origin", `HEAD:${branch}`, force && "--force"].filter<string>(
|
||||
Boolean as any
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const switchToMaybeExistingBranch = async (branch: string) => {
|
||||
let { stderr } = await getExecOutput("git", ["checkout", branch], {
|
||||
ignoreReturnCode: true,
|
||||
});
|
||||
let isCreatingBranch = !stderr
|
||||
.toString()
|
||||
.includes(`Switched to a new branch '${branch}'`);
|
||||
if (isCreatingBranch) {
|
||||
await exec("git", ["checkout", "-b", branch]);
|
||||
}
|
||||
};
|
||||
|
||||
const reset = async (
|
||||
pathSpec: string,
|
||||
mode: "hard" | "soft" | "mixed" = "hard"
|
||||
) => {
|
||||
await exec("git", ["reset", `--${mode}`, pathSpec]);
|
||||
};
|
||||
|
||||
const commitAll = async (message: string) => {
|
||||
await exec("git", ["add", "."]);
|
||||
await exec("git", ["commit", "-m", message]);
|
||||
};
|
||||
|
||||
const checkIfClean = async (): Promise<boolean> => {
|
||||
const { stdout } = await getExecOutput("git", ["status", "--porcelain"]);
|
||||
return !stdout.length;
|
||||
};
|
||||
|
||||
export class Git {
|
||||
octokit;
|
||||
constructor(octokit?: Octokit) {
|
||||
this.octokit = octokit;
|
||||
}
|
||||
|
||||
async setupUser() {
|
||||
if (this.octokit) {
|
||||
return;
|
||||
}
|
||||
await exec("git", ["config", "user.name", `"github-actions[bot]"`]);
|
||||
await exec("git", [
|
||||
"config",
|
||||
"user.email",
|
||||
`"41898282+github-actions[bot]@users.noreply.github.com"`,
|
||||
]);
|
||||
}
|
||||
|
||||
async pushTag(tag: string) {
|
||||
if (this.octokit) {
|
||||
return this.octokit.rest.git
|
||||
.createRef({
|
||||
...github.context.repo,
|
||||
ref: `refs/tags/${tag}`,
|
||||
sha: github.context.sha,
|
||||
})
|
||||
.catch((err) => {
|
||||
// Assuming tag was manually pushed in custom publish script
|
||||
core.warning(`Failed to create tag ${tag}: ${err.message}`);
|
||||
});
|
||||
}
|
||||
await exec("git", ["push", "origin", tag]);
|
||||
}
|
||||
|
||||
async prepareBranch(branch: string) {
|
||||
if (this.octokit) {
|
||||
// Preparing a new local branch is not necessary when using the API
|
||||
return;
|
||||
}
|
||||
await switchToMaybeExistingBranch(branch);
|
||||
await reset(github.context.sha);
|
||||
}
|
||||
|
||||
async pushChanges({ branch, message }: { branch: string; message: string }) {
|
||||
if (this.octokit) {
|
||||
return commitChangesFromRepo({
|
||||
octokit: this.octokit,
|
||||
...github.context.repo,
|
||||
branch,
|
||||
message,
|
||||
base: {
|
||||
commit: github.context.sha,
|
||||
},
|
||||
force: true,
|
||||
});
|
||||
}
|
||||
if (!(await checkIfClean())) {
|
||||
await commitAll(message);
|
||||
}
|
||||
await push(branch, { force: true });
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
import { exec } from "@actions/exec";
|
||||
import { execWithOutput } from "./utils";
|
||||
|
||||
export const setupUser = async () => {
|
||||
await exec("git", [
|
||||
"config",
|
||||
"--global",
|
||||
"user.name",
|
||||
`"github-actions[bot]"`,
|
||||
]);
|
||||
await exec("git", [
|
||||
"config",
|
||||
"--global",
|
||||
"user.email",
|
||||
`"github-actions[bot]@users.noreply.github.com"`,
|
||||
]);
|
||||
};
|
||||
|
||||
export const pullBranch = async (branch: string) => {
|
||||
await exec("git", ["pull", "origin", branch]);
|
||||
};
|
||||
|
||||
export const push = async (
|
||||
branch: string,
|
||||
{ force }: { force?: boolean } = {}
|
||||
) => {
|
||||
await exec(
|
||||
"git",
|
||||
["push", "origin", `HEAD:${branch}`, force && "--force"].filter<string>(
|
||||
Boolean as any
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
export const pushTags = async () => {
|
||||
await exec("git", ["push", "origin", "--tags"]);
|
||||
};
|
||||
|
||||
export const switchToMaybeExistingBranch = async (branch: string) => {
|
||||
let { stderr } = await execWithOutput("git", ["checkout", branch], {
|
||||
ignoreReturnCode: true,
|
||||
});
|
||||
let isCreatingBranch = !stderr
|
||||
.toString()
|
||||
.includes(`Switched to a new branch '${branch}'`);
|
||||
if (isCreatingBranch) {
|
||||
await exec("git", ["checkout", "-b", branch]);
|
||||
}
|
||||
};
|
||||
|
||||
export const reset = async (
|
||||
pathSpec: string,
|
||||
mode: "hard" | "soft" | "mixed" = "hard"
|
||||
) => {
|
||||
await exec("git", ["reset", `--${mode}`, pathSpec]);
|
||||
};
|
||||
|
||||
export const commitAll = async (message: string) => {
|
||||
await exec("git", ["add", "."]);
|
||||
await exec("git", ["commit", "-m", message]);
|
||||
};
|
||||
|
||||
export const checkIfClean = async (): Promise<boolean> => {
|
||||
const { stdout } = await execWithOutput("git", ["status", "--porcelain"]);
|
||||
return !stdout.length;
|
||||
};
|
||||
+53
-17
@@ -1,8 +1,9 @@
|
||||
import * as core from "@actions/core";
|
||||
import fs from "fs-extra";
|
||||
import * as gitUtils from "./gitUtils";
|
||||
import { runPublish, runVersion } from "./run";
|
||||
import { Git } from "./git";
|
||||
import { setupOctokit } from "./octokit";
|
||||
import readChangesetState from "./readChangesetState";
|
||||
import { runPublish, runVersion } from "./run";
|
||||
|
||||
const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
|
||||
@@ -14,10 +15,28 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("setting git user");
|
||||
await gitUtils.setupUser();
|
||||
const inputCwd = core.getInput("cwd");
|
||||
if (inputCwd) {
|
||||
core.info("changing directory to the one given as the input");
|
||||
process.chdir(inputCwd);
|
||||
}
|
||||
|
||||
console.log("setting GitHub credentials");
|
||||
const octokit = setupOctokit(githubToken);
|
||||
const commitMode = getOptionalInput("commitMode") ?? "git-cli";
|
||||
if (commitMode !== "git-cli" && commitMode !== "github-api") {
|
||||
core.setFailed(`Invalid commit mode: ${commitMode}`);
|
||||
return;
|
||||
}
|
||||
const git = new Git(commitMode === "github-api" ? octokit : undefined);
|
||||
|
||||
let setupGitUser = core.getBooleanInput("setupGitUser");
|
||||
|
||||
if (setupGitUser) {
|
||||
core.info("setting git user");
|
||||
await git.setupUser();
|
||||
}
|
||||
|
||||
core.info("setting GitHub credentials");
|
||||
await fs.writeFile(
|
||||
`${process.env.HOME}/.netrc`,
|
||||
`machine github.com\nlogin github-actions[bot]\npassword ${githubToken}`
|
||||
@@ -27,6 +46,9 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
|
||||
let publishScript = core.getInput("publish");
|
||||
let hasChangesets = changesets.length !== 0;
|
||||
const hasNonEmptyChangesets = changesets.some(
|
||||
(changeset) => changeset.releases.length > 0
|
||||
);
|
||||
let hasPublishScript = !!publishScript;
|
||||
|
||||
core.setOutput("published", "false");
|
||||
@@ -35,27 +57,29 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
|
||||
switch (true) {
|
||||
case !hasChangesets && !hasPublishScript:
|
||||
console.log("No changesets found");
|
||||
core.info(
|
||||
"No changesets present or were removed by merging release PR. Not publishing because no publish script found."
|
||||
);
|
||||
return;
|
||||
case !hasChangesets && hasPublishScript: {
|
||||
console.log(
|
||||
"No changesets found, attempting to publish any unpublished packages to npm"
|
||||
core.info(
|
||||
"No changesets found. Attempting to publish any unpublished packages to npm"
|
||||
);
|
||||
|
||||
let userNpmrcPath = `${process.env.HOME}/.npmrc`;
|
||||
if (fs.existsSync(userNpmrcPath)) {
|
||||
console.log("Found existing user .npmrc file");
|
||||
core.info("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) {
|
||||
console.log(
|
||||
core.info(
|
||||
"Found existing auth token for the npm registry in the user .npmrc file"
|
||||
);
|
||||
} else {
|
||||
console.log(
|
||||
core.info(
|
||||
"Didn't find existing auth token for the npm registry in the user .npmrc file, creating one"
|
||||
);
|
||||
fs.appendFileSync(
|
||||
@@ -64,7 +88,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
);
|
||||
}
|
||||
} else {
|
||||
console.log("No user .npmrc file found, creating one");
|
||||
core.info("No user .npmrc file found, creating one");
|
||||
fs.writeFileSync(
|
||||
userNpmrcPath,
|
||||
`//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`
|
||||
@@ -73,7 +97,9 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
|
||||
const result = await runPublish({
|
||||
script: publishScript,
|
||||
githubToken,
|
||||
git,
|
||||
octokit,
|
||||
createGithubReleases: core.getBooleanInput("createGithubReleases"),
|
||||
});
|
||||
|
||||
if (result.published) {
|
||||
@@ -85,17 +111,27 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
}
|
||||
return;
|
||||
}
|
||||
case hasChangesets:
|
||||
await runVersion({
|
||||
case hasChangesets && !hasNonEmptyChangesets:
|
||||
core.info("All changesets are empty; not creating PR");
|
||||
return;
|
||||
case hasChangesets: {
|
||||
const octokit = setupOctokit(githubToken);
|
||||
const { pullRequestNumber } = await runVersion({
|
||||
script: getOptionalInput("version"),
|
||||
githubToken,
|
||||
git,
|
||||
octokit,
|
||||
prTitle: getOptionalInput("title"),
|
||||
commitMessage: getOptionalInput("commit"),
|
||||
hasPublishScript,
|
||||
branch: getOptionalInput("branch"),
|
||||
});
|
||||
|
||||
core.setOutput("pullRequestNumber", String(pullRequestNumber));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
})().catch((err) => {
|
||||
console.error(err);
|
||||
core.error(err);
|
||||
core.setFailed(err.message);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import * as core from "@actions/core";
|
||||
import { GitHub, getOctokitOptions } from "@actions/github/lib/utils";
|
||||
import { throttling } from "@octokit/plugin-throttling";
|
||||
|
||||
export 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;
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
export type Octokit = ReturnType<typeof setupOctokit>;
|
||||
@@ -11,17 +11,19 @@ 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 (isInPreMode) {
|
||||
if (preState !== undefined && preState.mode === "pre") {
|
||||
let changesetsToFilter = new Set(preState.changesets);
|
||||
changesets = changesets.filter((x) => !changesetsToFilter.has(x.id));
|
||||
|
||||
return {
|
||||
preState,
|
||||
changesets: changesets.filter((x) => !changesetsToFilter.has(x.id)),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
preState: isInPreMode ? preState : undefined,
|
||||
preState: undefined,
|
||||
changesets,
|
||||
};
|
||||
}
|
||||
|
||||
+157
-21
@@ -1,9 +1,10 @@
|
||||
import { Changeset } from "@changesets/types";
|
||||
import writeChangeset from "@changesets/write";
|
||||
import fixturez from "fixturez";
|
||||
import * as github from "@actions/github";
|
||||
import fs from "fs-extra";
|
||||
import path from "path";
|
||||
import writeChangeset from "@changesets/write";
|
||||
import { Changeset } from "@changesets/types";
|
||||
import { Git } from "./git";
|
||||
import { setupOctokit } from "./octokit";
|
||||
import { runVersion } from "./run";
|
||||
|
||||
jest.mock("@actions/github", () => ({
|
||||
@@ -15,22 +16,32 @@ jest.mock("@actions/github", () => ({
|
||||
ref: "refs/heads/some-branch",
|
||||
sha: "xeac7",
|
||||
},
|
||||
getOctokit: jest.fn(),
|
||||
}));
|
||||
jest.mock("./gitUtils");
|
||||
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("./git");
|
||||
jest.mock("@changesets/ghcommit/git");
|
||||
|
||||
let mockedGithubMethods = {
|
||||
search: {
|
||||
issuesAndPullRequests: jest.fn(),
|
||||
},
|
||||
pulls: {
|
||||
create: jest.fn(),
|
||||
list: jest.fn(),
|
||||
},
|
||||
repos: {
|
||||
createRelease: jest.fn(),
|
||||
},
|
||||
};
|
||||
(github.getOctokit as any).mockImplementation(() => mockedGithubMethods);
|
||||
|
||||
let f = fixturez(__dirname);
|
||||
|
||||
@@ -53,9 +64,11 @@ describe("version", () => {
|
||||
let cwd = f.copy("simple-project");
|
||||
linkNodeModules(cwd);
|
||||
|
||||
mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce(
|
||||
() => ({ data: { items: [] } })
|
||||
);
|
||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
||||
|
||||
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
||||
data: { number: 123 },
|
||||
}));
|
||||
|
||||
await writeChangesets(
|
||||
[
|
||||
@@ -77,7 +90,8 @@ describe("version", () => {
|
||||
);
|
||||
|
||||
await runVersion({
|
||||
githubToken: "@@GITHUB_TOKEN",
|
||||
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
||||
git: new Git(),
|
||||
cwd,
|
||||
});
|
||||
|
||||
@@ -88,9 +102,11 @@ describe("version", () => {
|
||||
let cwd = f.copy("simple-project");
|
||||
linkNodeModules(cwd);
|
||||
|
||||
mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce(
|
||||
() => ({ data: { items: [] } })
|
||||
);
|
||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
||||
|
||||
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
||||
data: { number: 123 },
|
||||
}));
|
||||
|
||||
await writeChangesets(
|
||||
[
|
||||
@@ -108,7 +124,8 @@ describe("version", () => {
|
||||
);
|
||||
|
||||
await runVersion({
|
||||
githubToken: "@@GITHUB_TOKEN",
|
||||
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
||||
git: new Git(),
|
||||
cwd,
|
||||
});
|
||||
|
||||
@@ -119,9 +136,11 @@ describe("version", () => {
|
||||
let cwd = f.copy("ignored-package");
|
||||
linkNodeModules(cwd);
|
||||
|
||||
mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce(
|
||||
() => ({ data: { items: [] } })
|
||||
);
|
||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
||||
|
||||
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
||||
data: { number: 123 },
|
||||
}));
|
||||
|
||||
await writeChangesets(
|
||||
[
|
||||
@@ -139,10 +158,127 @@ describe("version", () => {
|
||||
);
|
||||
|
||||
await runVersion({
|
||||
githubToken: "@@GITHUB_TOKEN",
|
||||
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
||||
git: new Git(),
|
||||
cwd,
|
||||
});
|
||||
|
||||
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.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
||||
|
||||
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({
|
||||
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
||||
git: new Git(),
|
||||
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.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
||||
|
||||
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({
|
||||
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
||||
git: new Git(),
|
||||
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/
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
+180
-95
@@ -1,22 +1,30 @@
|
||||
import { exec } from "@actions/exec";
|
||||
import * as core from "@actions/core";
|
||||
import { exec, getExecOutput } from "@actions/exec";
|
||||
import * as github from "@actions/github";
|
||||
import { PreState } from "@changesets/types";
|
||||
import { Package, getPackages } from "@manypkg/get-packages";
|
||||
import fs from "fs-extra";
|
||||
import { getPackages, Package } from "@manypkg/get-packages";
|
||||
import path from "path";
|
||||
import * as semver from "semver";
|
||||
import {
|
||||
getChangelogEntry,
|
||||
execWithOutput,
|
||||
getChangedPackages,
|
||||
sortTheThings,
|
||||
getVersionsByDirectory,
|
||||
} from "./utils";
|
||||
import * as gitUtils from "./gitUtils";
|
||||
import readChangesetState from "./readChangesetState";
|
||||
import resolveFrom from "resolve-from";
|
||||
import * as semver from "semver";
|
||||
import { Git } from "./git";
|
||||
import { Octokit } from "./octokit";
|
||||
import readChangesetState from "./readChangesetState";
|
||||
import {
|
||||
getChangedPackages,
|
||||
getChangelogEntry,
|
||||
getVersionsByDirectory,
|
||||
sortTheThings,
|
||||
} from "./utils";
|
||||
|
||||
// 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 createRelease = async (
|
||||
octokit: ReturnType<typeof github.getOctokit>,
|
||||
octokit: Octokit,
|
||||
{ pkg, tagName }: { pkg: Package; tagName: string }
|
||||
) => {
|
||||
try {
|
||||
@@ -33,7 +41,7 @@ const createRelease = async (
|
||||
);
|
||||
}
|
||||
|
||||
await octokit.repos.createRelease({
|
||||
await octokit.rest.repos.createRelease({
|
||||
name: tagName,
|
||||
tag_name: tagName,
|
||||
body: changelogEntry.content,
|
||||
@@ -42,7 +50,12 @@ const createRelease = async (
|
||||
});
|
||||
} catch (err) {
|
||||
// if we can't find a changelog, the user has probably disabled changelogs
|
||||
if (err.code !== "ENOENT") {
|
||||
if (
|
||||
err &&
|
||||
typeof err === "object" &&
|
||||
"code" in err &&
|
||||
err.code !== "ENOENT"
|
||||
) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -50,7 +63,9 @@ const createRelease = async (
|
||||
|
||||
type PublishOptions = {
|
||||
script: string;
|
||||
githubToken: string;
|
||||
octokit: Octokit;
|
||||
createGithubReleases: boolean;
|
||||
git: Git;
|
||||
cwd?: string;
|
||||
};
|
||||
|
||||
@@ -67,20 +82,19 @@ type PublishResult =
|
||||
|
||||
export async function runPublish({
|
||||
script,
|
||||
githubToken,
|
||||
git,
|
||||
octokit,
|
||||
createGithubReleases,
|
||||
cwd = process.cwd(),
|
||||
}: PublishOptions): Promise<PublishResult> {
|
||||
let octokit = github.getOctokit(githubToken);
|
||||
let [publishCommand, ...publishArgs] = script.split(/\s+/);
|
||||
|
||||
let changesetPublishOutput = await execWithOutput(
|
||||
let changesetPublishOutput = await getExecOutput(
|
||||
publishCommand,
|
||||
publishArgs,
|
||||
{ cwd }
|
||||
);
|
||||
|
||||
await gitUtils.pushTags();
|
||||
|
||||
let { packages, tool } = await getPackages(cwd);
|
||||
let releasedPackages: Package[] = [];
|
||||
|
||||
@@ -104,14 +118,15 @@ export async function runPublish({
|
||||
releasedPackages.push(pkg);
|
||||
}
|
||||
|
||||
if (createGithubReleases) {
|
||||
await Promise.all(
|
||||
releasedPackages.map((pkg) =>
|
||||
createRelease(octokit, {
|
||||
pkg,
|
||||
tagName: `${pkg.packageJson.name}@${pkg.packageJson.version}`,
|
||||
releasedPackages.map(async (pkg) => {
|
||||
const tagName = `${pkg.packageJson.name}@${pkg.packageJson.version}`;
|
||||
await git.pushTag(tagName);
|
||||
await createRelease(octokit, { pkg, tagName });
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (packages.length === 0) {
|
||||
throw new Error(
|
||||
@@ -127,10 +142,11 @@ export async function runPublish({
|
||||
|
||||
if (match) {
|
||||
releasedPackages.push(pkg);
|
||||
await createRelease(octokit, {
|
||||
pkg,
|
||||
tagName: `v${pkg.packageJson.version}`,
|
||||
});
|
||||
if (createGithubReleases) {
|
||||
const tagName = `v${pkg.packageJson.version}`;
|
||||
await git.pushTag(tagName);
|
||||
await createRelease(octokit, { pkg, tagName });
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -153,7 +169,12 @@ const requireChangesetsCliPkgJson = (cwd: string) => {
|
||||
try {
|
||||
return require(resolveFrom(cwd, "@changesets/cli/package.json"));
|
||||
} catch (err) {
|
||||
if (err && err.code === "MODULE_NOT_FOUND") {
|
||||
if (
|
||||
err &&
|
||||
typeof err === "object" &&
|
||||
"code" in err &&
|
||||
err.code === "MODULE_NOT_FOUND"
|
||||
) {
|
||||
throw new Error(
|
||||
`Have you forgotten to install \`@changesets/cli\` in "${cwd}"?`
|
||||
);
|
||||
@@ -162,31 +183,107 @@ 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 = {
|
||||
script?: string;
|
||||
githubToken: string;
|
||||
git: Git;
|
||||
octokit: Octokit;
|
||||
cwd?: string;
|
||||
prTitle?: string;
|
||||
commitMessage?: string;
|
||||
hasPublishScript?: boolean;
|
||||
prBodyMaxCharacters?: number;
|
||||
branch?: string;
|
||||
};
|
||||
|
||||
type RunVersionResult = {
|
||||
pullRequestNumber: number;
|
||||
};
|
||||
|
||||
export async function runVersion({
|
||||
script,
|
||||
githubToken,
|
||||
git,
|
||||
octokit,
|
||||
cwd = process.cwd(),
|
||||
prTitle = "Version Packages",
|
||||
commitMessage = "Version Packages",
|
||||
hasPublishScript = false,
|
||||
}: VersionOptions) {
|
||||
let repo = `${github.context.repo.owner}/${github.context.repo.repo}`;
|
||||
let branch = github.context.ref.replace("refs/heads/", "");
|
||||
prBodyMaxCharacters = MAX_CHARACTERS_PER_MESSAGE,
|
||||
branch = github.context.ref.replace("refs/heads/", ""),
|
||||
}: VersionOptions): Promise<RunVersionResult> {
|
||||
let versionBranch = `changeset-release/${branch}`;
|
||||
let octokit = github.getOctokit(githubToken);
|
||||
|
||||
let { preState } = await readChangesetState(cwd);
|
||||
|
||||
await gitUtils.switchToMaybeExistingBranch(versionBranch);
|
||||
await gitUtils.reset(github.context.sha);
|
||||
await git.prepareBranch(versionBranch);
|
||||
|
||||
let versionsByDirectory = await getVersionsByDirectory(cwd);
|
||||
|
||||
@@ -203,91 +300,79 @@ export async function runVersion({
|
||||
});
|
||||
}
|
||||
|
||||
let searchQuery = `repo:${repo}+state:open+head:${versionBranch}+base:${branch}`;
|
||||
let searchResultPromise = octokit.search.issuesAndPullRequests({
|
||||
q: searchQuery,
|
||||
const existingPullRequestsPromise = octokit.rest.pulls.list({
|
||||
...github.context.repo,
|
||||
state: "open",
|
||||
head: `${github.context.repo.owner}:${versionBranch}`,
|
||||
base: branch,
|
||||
});
|
||||
let changedPackages = await getChangedPackages(cwd, versionsByDirectory);
|
||||
|
||||
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(
|
||||
let changedPackagesInfoPromises = Promise.all(
|
||||
changedPackages.map(async (pkg) => {
|
||||
let changelogContents = await fs.readFile(
|
||||
path.join(pkg.dir, "CHANGELOG.md"),
|
||||
"utf8"
|
||||
);
|
||||
|
||||
let entry = getChangelogEntry(
|
||||
changelogContents,
|
||||
pkg.packageJson.version
|
||||
);
|
||||
let entry = getChangelogEntry(changelogContents, pkg.packageJson.version);
|
||||
return {
|
||||
highestLevel: entry.highestLevel,
|
||||
private: !!pkg.packageJson.private,
|
||||
content:
|
||||
`## ${pkg.packageJson.name}@${pkg.packageJson.version}\n\n` +
|
||||
entry.content,
|
||||
content: entry.content,
|
||||
header: `## ${pkg.packageJson.name}@${pkg.packageJson.version}`,
|
||||
};
|
||||
})
|
||||
)
|
||||
)
|
||||
.filter((x) => x)
|
||||
.sort(sortTheThings)
|
||||
.map((x) => x.content)
|
||||
.join("\n ")
|
||||
);
|
||||
})();
|
||||
|
||||
const finalPrTitle = `${prTitle}${!!preState ? ` (${preState.tag})` : ""}`;
|
||||
|
||||
// project with `commit: true` setting could have already committed files
|
||||
if (!(await gitUtils.checkIfClean())) {
|
||||
const finalCommitMessage = `${commitMessage}${
|
||||
!!preState ? ` (${preState.tag})` : ""
|
||||
}`;
|
||||
await gitUtils.commitAll(finalCommitMessage);
|
||||
}
|
||||
|
||||
await gitUtils.push(versionBranch, { force: true });
|
||||
await git.pushChanges({ branch: versionBranch, message: finalCommitMessage });
|
||||
|
||||
let searchResult = await searchResultPromise;
|
||||
console.log(JSON.stringify(searchResult.data, null, 2));
|
||||
if (searchResult.data.items.length === 0) {
|
||||
console.log("creating pull request");
|
||||
await octokit.pulls.create({
|
||||
let existingPullRequests = await existingPullRequestsPromise;
|
||||
core.info(JSON.stringify(existingPullRequests.data, null, 2));
|
||||
|
||||
const changedPackagesInfo = (await changedPackagesInfoPromises)
|
||||
.filter((x) => x)
|
||||
.sort(sortTheThings);
|
||||
|
||||
let prBody = await getVersionPrBody({
|
||||
hasPublishScript,
|
||||
preState,
|
||||
branch,
|
||||
changedPackagesInfo,
|
||||
prBodyMaxCharacters,
|
||||
});
|
||||
|
||||
if (existingPullRequests.data.length === 0) {
|
||||
core.info("creating pull request");
|
||||
const { data: newPullRequest } = await octokit.rest.pulls.create({
|
||||
base: branch,
|
||||
head: versionBranch,
|
||||
title: finalPrTitle,
|
||||
body: await prBodyPromise,
|
||||
body: prBody,
|
||||
...github.context.repo,
|
||||
});
|
||||
|
||||
return {
|
||||
pullRequestNumber: newPullRequest.number,
|
||||
};
|
||||
} else {
|
||||
octokit.pulls.update({
|
||||
pull_number: searchResult.data.items[0].number,
|
||||
const [pullRequest] = existingPullRequests.data;
|
||||
|
||||
core.info(`updating found pull request #${pullRequest.number}`);
|
||||
await octokit.rest.pulls.update({
|
||||
pull_number: pullRequest.number,
|
||||
title: finalPrTitle,
|
||||
body: await prBodyPromise,
|
||||
body: prBody,
|
||||
...github.context.repo,
|
||||
state: "open",
|
||||
});
|
||||
console.log("pull request found");
|
||||
|
||||
return {
|
||||
pullRequestNumber: pullRequest.number,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ 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 = {
|
||||
@@ -87,32 +86,6 @@ 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(
|
||||
a: { private: boolean; highestLevel: number },
|
||||
b: { private: boolean; highestLevel: number }
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
"moduleResolution": "nodenext", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
|
||||
Reference in New Issue
Block a user