mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d89c1de63c |
@@ -1,11 +0,0 @@
|
|||||||
# 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"
|
|
||||||
@@ -10,12 +10,12 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Use Node.js 20
|
- name: Use Node.js 16
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 20.x
|
node-version: 16.x
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: yarn --frozen-lockfile
|
run: yarn --frozen-lockfile
|
||||||
|
|||||||
@@ -12,12 +12,12 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Use Node.js 20
|
- name: Use Node.js 16
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 20.x
|
node-version: 16.x
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: yarn --frozen-lockfile
|
run: yarn --frozen-lockfile
|
||||||
|
|||||||
@@ -1,51 +1,5 @@
|
|||||||
# @changesets/action
|
# @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
|
## 1.4.4
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Changesets Release Action
|
# Changesets Release Action
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@@ -12,12 +12,11 @@ This action for [Changesets](https://github.com/changesets/changesets) creates a
|
|||||||
- 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`
|
- 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()`
|
- cwd - Changes node's `process.cwd()` if the project is not located on the root. Default to `process.cwd()`
|
||||||
|
|
||||||
### Outputs
|
### Outputs
|
||||||
|
|
||||||
- published - A boolean value to indicate whether a publishing has happened or not
|
- published - A boolean value to indicate whether a publishing is happened or not
|
||||||
- publishedPackages - A JSON array to present the published packages. The format is `[{"name": "@xx/xx", "version": "1.2.0"}, {"name": "@xx/xy", "version": "0.8.9"}]`
|
- 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:
|
### Example workflow:
|
||||||
@@ -44,10 +43,10 @@ jobs:
|
|||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Setup Node.js 20
|
- name: Setup Node.js 16
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 16
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: yarn
|
run: yarn
|
||||||
@@ -80,10 +79,10 @@ jobs:
|
|||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Setup Node.js 20.x
|
- name: Setup Node.js 16.x
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 20.x
|
node-version: 16.x
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: yarn
|
run: yarn
|
||||||
@@ -125,7 +124,7 @@ For example, you can add a step before running the Changesets GitHub Action:
|
|||||||
|
|
||||||
#### Custom Publishing
|
#### Custom Publishing
|
||||||
|
|
||||||
If you want to hook into when publishing should occur but have your own publishing functionality, you can utilize the `hasChangesets` output.
|
If you want to hook into when publishing should occur but have your own publishing functionality you can utilize the `hasChangesets` output.
|
||||||
|
|
||||||
Note that you might need to account for things already being published in your script because a commit without any new changesets can always land on your base branch after a successful publish. In such a case you need to figure out on your own how to skip over the actual publishing logic or handle errors gracefully as most package registries won't allow you to publish over already published version.
|
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.
|
||||||
|
|
||||||
@@ -145,10 +144,10 @@ jobs:
|
|||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Setup Node.js 20.x
|
- name: Setup Node.js 16.x
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 20.x
|
node-version: 16.x
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: yarn
|
run: yarn
|
||||||
@@ -189,10 +188,10 @@ jobs:
|
|||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Setup Node.js 20.x
|
- name: Setup Node.js 16.x
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 20.x
|
node-version: 16.x
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: yarn
|
run: yarn
|
||||||
|
|||||||
+1
-12
@@ -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: "node20"
|
using: "node16"
|
||||||
main: "dist/index.js"
|
main: "dist/index.js"
|
||||||
inputs:
|
inputs:
|
||||||
publish:
|
publish:
|
||||||
@@ -28,17 +28,6 @@ inputs:
|
|||||||
description: "A boolean value to indicate whether to create Github releases after `publish` or not"
|
description: "A boolean value to indicate whether to create Github releases after `publish` or not"
|
||||||
required: false
|
required: false
|
||||||
default: true
|
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:
|
outputs:
|
||||||
published:
|
published:
|
||||||
description: A boolean value to indicate whether a publishing is happened or not
|
description: A boolean value to indicate whether a publishing is happened or not
|
||||||
|
|||||||
Vendored
+8
-16
File diff suppressed because one or more lines are too long
+16
-20
@@ -1,24 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "@changesets/action",
|
"name": "@changesets/action",
|
||||||
"version": "1.5.0",
|
"version": "1.4.4",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.13.10",
|
|
||||||
"@babel/preset-env": "^7.13.10",
|
|
||||||
"@babel/preset-typescript": "^7.13.0",
|
|
||||||
"@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",
|
||||||
"@types/fs-extra": "^8.0.0",
|
|
||||||
"@types/jest": "^29.5.1",
|
|
||||||
"@types/node": "^20.11.17",
|
|
||||||
"@types/semver": "^7.5.0",
|
|
||||||
"@vercel/ncc": "^0.36.1",
|
"@vercel/ncc": "^0.36.1",
|
||||||
"babel-jest": "^29.5.0",
|
|
||||||
"fixturez": "^1.1.0",
|
"fixturez": "^1.1.0",
|
||||||
"husky": "^3.0.3",
|
|
||||||
"jest": "^29.5.0",
|
|
||||||
"prettier": "^2.0.5",
|
"prettier": "^2.0.5",
|
||||||
"typescript": "^5.0.4"
|
"typescript": "^5.0.4"
|
||||||
},
|
},
|
||||||
@@ -31,23 +21,32 @@
|
|||||||
"release": "node ./scripts/release.js"
|
"release": "node ./scripts/release.js"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 20"
|
"node": ">= 16"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^1.10.0",
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^1.1.1",
|
||||||
"@actions/github": "^5.1.1",
|
"@actions/github": "^5.1.1",
|
||||||
"@changesets/ghcommit": "1.3.0",
|
"@babel/core": "^7.13.10",
|
||||||
|
"@babel/preset-env": "^7.13.10",
|
||||||
|
"@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.2.1",
|
"@octokit/plugin-throttling": "5.1.1",
|
||||||
|
"@types/fs-extra": "^8.0.0",
|
||||||
|
"@types/jest": "^29.5.1",
|
||||||
|
"@types/node": "^12.7.1",
|
||||||
|
"@types/semver": "^6.0.2",
|
||||||
|
"babel-jest": "^29.5.0",
|
||||||
"fs-extra": "^8.1.0",
|
"fs-extra": "^8.1.0",
|
||||||
|
"husky": "^3.0.3",
|
||||||
|
"jest": "^29.5.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",
|
||||||
"resolve-from": "^5.0.0",
|
"resolve-from": "^5.0.0",
|
||||||
"semver": "^7.5.3",
|
"semver": "^6.3.0",
|
||||||
"unified": "^8.3.2"
|
"unified": "^8.3.2"
|
||||||
},
|
},
|
||||||
"husky": {
|
"husky": {
|
||||||
@@ -55,9 +54,6 @@
|
|||||||
},
|
},
|
||||||
"prettier": {},
|
"prettier": {},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"**/@octokit/core": "4.2.0",
|
"**/@octokit/core": "4.2.0"
|
||||||
"trim": "^0.0.3",
|
}
|
||||||
"y18n": "^4.0.1"
|
|
||||||
},
|
|
||||||
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
||||||
}
|
}
|
||||||
|
|||||||
-106
@@ -1,106 +0,0 @@
|
|||||||
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 });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import { exec, getExecOutput } from "@actions/exec";
|
||||||
|
|
||||||
|
export const setupUser = async () => {
|
||||||
|
await exec("git", [
|
||||||
|
"config",
|
||||||
|
"user.name",
|
||||||
|
`"github-actions[bot]"`,
|
||||||
|
]);
|
||||||
|
await exec("git", [
|
||||||
|
"config",
|
||||||
|
"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 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]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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 getExecOutput("git", ["status", "--porcelain"]);
|
||||||
|
return !stdout.length;
|
||||||
|
};
|
||||||
+8
-24
@@ -1,9 +1,8 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
import { Git } from "./git";
|
import * as gitUtils from "./gitUtils";
|
||||||
import { setupOctokit } from "./octokit";
|
|
||||||
import readChangesetState from "./readChangesetState";
|
|
||||||
import { runPublish, runVersion } from "./run";
|
import { runPublish, runVersion } from "./run";
|
||||||
|
import readChangesetState from "./readChangesetState";
|
||||||
|
|
||||||
const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||||
|
|
||||||
@@ -21,19 +20,11 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
|||||||
process.chdir(inputCwd);
|
process.chdir(inputCwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
let setupGitUser = core.getBooleanInput("setupGitUser");
|
||||||
|
|
||||||
if (setupGitUser) {
|
if (setupGitUser) {
|
||||||
core.info("setting git user");
|
core.info("setting git user");
|
||||||
await git.setupUser();
|
await gitUtils.setupUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info("setting GitHub credentials");
|
core.info("setting GitHub credentials");
|
||||||
@@ -57,13 +48,11 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
|||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case !hasChangesets && !hasPublishScript:
|
case !hasChangesets && !hasPublishScript:
|
||||||
core.info(
|
core.info("No changesets found");
|
||||||
"No changesets present or were removed by merging release PR. Not publishing because no publish script found."
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
case !hasChangesets && hasPublishScript: {
|
case !hasChangesets && hasPublishScript: {
|
||||||
core.info(
|
core.info(
|
||||||
"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`;
|
||||||
@@ -97,8 +86,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
|||||||
|
|
||||||
const result = await runPublish({
|
const result = await runPublish({
|
||||||
script: publishScript,
|
script: publishScript,
|
||||||
git,
|
githubToken,
|
||||||
octokit,
|
|
||||||
createGithubReleases: core.getBooleanInput("createGithubReleases"),
|
createGithubReleases: core.getBooleanInput("createGithubReleases"),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -114,23 +102,19 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
|||||||
case hasChangesets && !hasNonEmptyChangesets:
|
case hasChangesets && !hasNonEmptyChangesets:
|
||||||
core.info("All changesets are empty; not creating PR");
|
core.info("All changesets are empty; not creating PR");
|
||||||
return;
|
return;
|
||||||
case hasChangesets: {
|
case hasChangesets:
|
||||||
const octokit = setupOctokit(githubToken);
|
|
||||||
const { pullRequestNumber } = await runVersion({
|
const { pullRequestNumber } = await runVersion({
|
||||||
script: getOptionalInput("version"),
|
script: getOptionalInput("version"),
|
||||||
git,
|
githubToken,
|
||||||
octokit,
|
|
||||||
prTitle: getOptionalInput("title"),
|
prTitle: getOptionalInput("title"),
|
||||||
commitMessage: getOptionalInput("commit"),
|
commitMessage: getOptionalInput("commit"),
|
||||||
hasPublishScript,
|
hasPublishScript,
|
||||||
branch: getOptionalInput("branch"),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
core.setOutput("pullRequestNumber", String(pullRequestNumber));
|
core.setOutput("pullRequestNumber", String(pullRequestNumber));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})().catch((err) => {
|
})().catch((err) => {
|
||||||
core.error(err);
|
core.error(err);
|
||||||
core.setFailed(err.message);
|
core.setFailed(err.message);
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
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,19 +11,17 @@ export default async function readChangesetState(
|
|||||||
cwd: string = process.cwd()
|
cwd: string = process.cwd()
|
||||||
): Promise<ChangesetState> {
|
): Promise<ChangesetState> {
|
||||||
let preState = await readPreState(cwd);
|
let preState = await readPreState(cwd);
|
||||||
|
let isInPreMode = preState !== undefined && preState.mode === "pre";
|
||||||
|
|
||||||
let changesets = await readChangesets(cwd);
|
let changesets = await readChangesets(cwd);
|
||||||
|
|
||||||
if (preState !== undefined && preState.mode === "pre") {
|
if (isInPreMode) {
|
||||||
let changesetsToFilter = new Set(preState.changesets);
|
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 {
|
return {
|
||||||
preState: undefined,
|
preState: isInPreMode ? preState : undefined,
|
||||||
changesets,
|
changesets,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+31
-25
@@ -1,10 +1,10 @@
|
|||||||
import { Changeset } from "@changesets/types";
|
|
||||||
import writeChangeset from "@changesets/write";
|
|
||||||
import fixturez from "fixturez";
|
import fixturez from "fixturez";
|
||||||
|
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 { Git } from "./git";
|
import writeChangeset from "@changesets/write";
|
||||||
import { setupOctokit } from "./octokit";
|
import { Changeset } from "@changesets/types";
|
||||||
import { runVersion } from "./run";
|
import { runVersion } from "./run";
|
||||||
|
|
||||||
jest.mock("@actions/github", () => ({
|
jest.mock("@actions/github", () => ({
|
||||||
@@ -21,22 +21,23 @@ jest.mock("@actions/github/lib/utils", () => ({
|
|||||||
GitHub: {
|
GitHub: {
|
||||||
plugin: () => {
|
plugin: () => {
|
||||||
// function necessary to be used as constructor
|
// function necessary to be used as constructor
|
||||||
return function () {
|
return function() {
|
||||||
return {
|
return {
|
||||||
rest: mockedGithubMethods,
|
rest: mockedGithubMethods,
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
getOctokitOptions: jest.fn(),
|
getOctokitOptions: jest.fn(),
|
||||||
}));
|
}));
|
||||||
jest.mock("./git");
|
jest.mock("./gitUtils");
|
||||||
jest.mock("@changesets/ghcommit/git");
|
|
||||||
|
|
||||||
let mockedGithubMethods = {
|
let mockedGithubMethods = {
|
||||||
|
search: {
|
||||||
|
issuesAndPullRequests: jest.fn(),
|
||||||
|
},
|
||||||
pulls: {
|
pulls: {
|
||||||
create: jest.fn(),
|
create: jest.fn(),
|
||||||
list: jest.fn(),
|
|
||||||
},
|
},
|
||||||
repos: {
|
repos: {
|
||||||
createRelease: jest.fn(),
|
createRelease: jest.fn(),
|
||||||
@@ -64,7 +65,9 @@ describe("version", () => {
|
|||||||
let cwd = f.copy("simple-project");
|
let cwd = f.copy("simple-project");
|
||||||
linkNodeModules(cwd);
|
linkNodeModules(cwd);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce(
|
||||||
|
() => ({ data: { items: [] } })
|
||||||
|
);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
||||||
data: { number: 123 },
|
data: { number: 123 },
|
||||||
@@ -90,8 +93,7 @@ describe("version", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await runVersion({
|
await runVersion({
|
||||||
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
githubToken: "@@GITHUB_TOKEN",
|
||||||
git: new Git(),
|
|
||||||
cwd,
|
cwd,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -102,7 +104,9 @@ describe("version", () => {
|
|||||||
let cwd = f.copy("simple-project");
|
let cwd = f.copy("simple-project");
|
||||||
linkNodeModules(cwd);
|
linkNodeModules(cwd);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce(
|
||||||
|
() => ({ data: { items: [] } })
|
||||||
|
);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
||||||
data: { number: 123 },
|
data: { number: 123 },
|
||||||
@@ -124,8 +128,7 @@ describe("version", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await runVersion({
|
await runVersion({
|
||||||
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
githubToken: "@@GITHUB_TOKEN",
|
||||||
git: new Git(),
|
|
||||||
cwd,
|
cwd,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -136,7 +139,9 @@ describe("version", () => {
|
|||||||
let cwd = f.copy("ignored-package");
|
let cwd = f.copy("ignored-package");
|
||||||
linkNodeModules(cwd);
|
linkNodeModules(cwd);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce(
|
||||||
|
() => ({ data: { items: [] } })
|
||||||
|
);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
||||||
data: { number: 123 },
|
data: { number: 123 },
|
||||||
@@ -158,8 +163,7 @@ describe("version", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await runVersion({
|
await runVersion({
|
||||||
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
githubToken: "@@GITHUB_TOKEN",
|
||||||
git: new Git(),
|
|
||||||
cwd,
|
cwd,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -170,7 +174,9 @@ describe("version", () => {
|
|||||||
let cwd = f.copy("simple-project");
|
let cwd = f.copy("simple-project");
|
||||||
linkNodeModules(cwd);
|
linkNodeModules(cwd);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce(
|
||||||
|
() => ({ data: { items: [] } })
|
||||||
|
);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
||||||
data: { number: 123 },
|
data: { number: 123 },
|
||||||
@@ -212,8 +218,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
|||||||
);
|
);
|
||||||
|
|
||||||
await runVersion({
|
await runVersion({
|
||||||
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
githubToken: "@@GITHUB_TOKEN",
|
||||||
git: new Git(),
|
|
||||||
cwd,
|
cwd,
|
||||||
prBodyMaxCharacters: 1000,
|
prBodyMaxCharacters: 1000,
|
||||||
});
|
});
|
||||||
@@ -228,7 +233,9 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
|||||||
let cwd = f.copy("simple-project");
|
let cwd = f.copy("simple-project");
|
||||||
linkNodeModules(cwd);
|
linkNodeModules(cwd);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce(
|
||||||
|
() => ({ data: { items: [] } })
|
||||||
|
);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
||||||
data: { number: 123 },
|
data: { number: 123 },
|
||||||
@@ -270,8 +277,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
|||||||
);
|
);
|
||||||
|
|
||||||
await runVersion({
|
await runVersion({
|
||||||
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
githubToken: "@@GITHUB_TOKEN",
|
||||||
git: new Git(),
|
|
||||||
cwd,
|
cwd,
|
||||||
prBodyMaxCharacters: 500,
|
prBodyMaxCharacters: 500,
|
||||||
});
|
});
|
||||||
|
|||||||
+85
-51
@@ -1,21 +1,24 @@
|
|||||||
import * as core from "@actions/core";
|
|
||||||
import { exec, getExecOutput } from "@actions/exec";
|
import { exec, getExecOutput } from "@actions/exec";
|
||||||
|
import { GitHub, getOctokitOptions } from "@actions/github/lib/utils";
|
||||||
import * as github from "@actions/github";
|
import * as github from "@actions/github";
|
||||||
import { PreState } from "@changesets/types";
|
import * as core from "@actions/core";
|
||||||
import { Package, getPackages } from "@manypkg/get-packages";
|
|
||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
|
import { getPackages, Package } from "@manypkg/get-packages";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import resolveFrom from "resolve-from";
|
|
||||||
import * as semver from "semver";
|
import * as semver from "semver";
|
||||||
import { Git } from "./git";
|
import { PreState } from "@changesets/types";
|
||||||
import { Octokit } from "./octokit";
|
|
||||||
import readChangesetState from "./readChangesetState";
|
|
||||||
import {
|
import {
|
||||||
getChangedPackages,
|
|
||||||
getChangelogEntry,
|
getChangelogEntry,
|
||||||
getVersionsByDirectory,
|
getChangedPackages,
|
||||||
sortTheThings,
|
sortTheThings,
|
||||||
|
getVersionsByDirectory,
|
||||||
} from "./utils";
|
} from "./utils";
|
||||||
|
import * as gitUtils from "./gitUtils";
|
||||||
|
import readChangesetState from "./readChangesetState";
|
||||||
|
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
|
// GitHub Issues/PRs messages have a max size limit on the
|
||||||
// message body payload.
|
// message body payload.
|
||||||
@@ -23,8 +26,42 @@ import {
|
|||||||
// To avoid that, we ensure to cap the message to 60k chars.
|
// To avoid that, we ensure to cap the message to 60k chars.
|
||||||
const MAX_CHARACTERS_PER_MESSAGE = 60000;
|
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: Octokit,
|
octokit: ReturnType<typeof GitHub>,
|
||||||
{ pkg, tagName }: { pkg: Package; tagName: string }
|
{ pkg, tagName }: { pkg: Package; tagName: string }
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
@@ -50,12 +87,7 @@ const createRelease = async (
|
|||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// if we can't find a changelog, the user has probably disabled changelogs
|
// if we can't find a changelog, the user has probably disabled changelogs
|
||||||
if (
|
if (err.code !== "ENOENT") {
|
||||||
err &&
|
|
||||||
typeof err === "object" &&
|
|
||||||
"code" in err &&
|
|
||||||
err.code !== "ENOENT"
|
|
||||||
) {
|
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,9 +95,8 @@ const createRelease = async (
|
|||||||
|
|
||||||
type PublishOptions = {
|
type PublishOptions = {
|
||||||
script: string;
|
script: string;
|
||||||
octokit: Octokit;
|
githubToken: string;
|
||||||
createGithubReleases: boolean;
|
createGithubReleases: boolean;
|
||||||
git: Git;
|
|
||||||
cwd?: string;
|
cwd?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -82,11 +113,12 @@ type PublishResult =
|
|||||||
|
|
||||||
export async function runPublish({
|
export async function runPublish({
|
||||||
script,
|
script,
|
||||||
git,
|
githubToken,
|
||||||
octokit,
|
|
||||||
createGithubReleases,
|
createGithubReleases,
|
||||||
cwd = process.cwd(),
|
cwd = process.cwd(),
|
||||||
}: PublishOptions): Promise<PublishResult> {
|
}: PublishOptions): Promise<PublishResult> {
|
||||||
|
const octokit = setupOctokit(githubToken);
|
||||||
|
|
||||||
let [publishCommand, ...publishArgs] = script.split(/\s+/);
|
let [publishCommand, ...publishArgs] = script.split(/\s+/);
|
||||||
|
|
||||||
let changesetPublishOutput = await getExecOutput(
|
let changesetPublishOutput = await getExecOutput(
|
||||||
@@ -95,6 +127,8 @@ export async function runPublish({
|
|||||||
{ cwd }
|
{ cwd }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await gitUtils.pushTags();
|
||||||
|
|
||||||
let { packages, tool } = await getPackages(cwd);
|
let { packages, tool } = await getPackages(cwd);
|
||||||
let releasedPackages: Package[] = [];
|
let releasedPackages: Package[] = [];
|
||||||
|
|
||||||
@@ -120,11 +154,12 @@ export async function runPublish({
|
|||||||
|
|
||||||
if (createGithubReleases) {
|
if (createGithubReleases) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
releasedPackages.map(async (pkg) => {
|
releasedPackages.map((pkg) =>
|
||||||
const tagName = `${pkg.packageJson.name}@${pkg.packageJson.version}`;
|
createRelease(octokit, {
|
||||||
await git.pushTag(tagName);
|
pkg,
|
||||||
await createRelease(octokit, { pkg, tagName });
|
tagName: `${pkg.packageJson.name}@${pkg.packageJson.version}`,
|
||||||
})
|
})
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -143,9 +178,10 @@ export async function runPublish({
|
|||||||
if (match) {
|
if (match) {
|
||||||
releasedPackages.push(pkg);
|
releasedPackages.push(pkg);
|
||||||
if (createGithubReleases) {
|
if (createGithubReleases) {
|
||||||
const tagName = `v${pkg.packageJson.version}`;
|
await createRelease(octokit, {
|
||||||
await git.pushTag(tagName);
|
pkg,
|
||||||
await createRelease(octokit, { pkg, tagName });
|
tagName: `v${pkg.packageJson.version}`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -169,12 +205,7 @@ const requireChangesetsCliPkgJson = (cwd: string) => {
|
|||||||
try {
|
try {
|
||||||
return require(resolveFrom(cwd, "@changesets/cli/package.json"));
|
return require(resolveFrom(cwd, "@changesets/cli/package.json"));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (
|
if (err && err.code === "MODULE_NOT_FOUND") {
|
||||||
err &&
|
|
||||||
typeof err === "object" &&
|
|
||||||
"code" in err &&
|
|
||||||
err.code === "MODULE_NOT_FOUND"
|
|
||||||
) {
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Have you forgotten to install \`@changesets/cli\` in "${cwd}"?`
|
`Have you forgotten to install \`@changesets/cli\` in "${cwd}"?`
|
||||||
);
|
);
|
||||||
@@ -254,14 +285,12 @@ export async function getVersionPrBody({
|
|||||||
|
|
||||||
type VersionOptions = {
|
type VersionOptions = {
|
||||||
script?: string;
|
script?: string;
|
||||||
git: Git;
|
githubToken: string;
|
||||||
octokit: Octokit;
|
|
||||||
cwd?: string;
|
cwd?: string;
|
||||||
prTitle?: string;
|
prTitle?: string;
|
||||||
commitMessage?: string;
|
commitMessage?: string;
|
||||||
hasPublishScript?: boolean;
|
hasPublishScript?: boolean;
|
||||||
prBodyMaxCharacters?: number;
|
prBodyMaxCharacters?: number;
|
||||||
branch?: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type RunVersionResult = {
|
type RunVersionResult = {
|
||||||
@@ -270,20 +299,23 @@ type RunVersionResult = {
|
|||||||
|
|
||||||
export async function runVersion({
|
export async function runVersion({
|
||||||
script,
|
script,
|
||||||
git,
|
githubToken,
|
||||||
octokit,
|
|
||||||
cwd = process.cwd(),
|
cwd = process.cwd(),
|
||||||
prTitle = "Version Packages",
|
prTitle = "Version Packages",
|
||||||
commitMessage = "Version Packages",
|
commitMessage = "Version Packages",
|
||||||
hasPublishScript = false,
|
hasPublishScript = false,
|
||||||
prBodyMaxCharacters = MAX_CHARACTERS_PER_MESSAGE,
|
prBodyMaxCharacters = MAX_CHARACTERS_PER_MESSAGE,
|
||||||
branch = github.context.ref.replace("refs/heads/", ""),
|
|
||||||
}: VersionOptions): Promise<RunVersionResult> {
|
}: VersionOptions): Promise<RunVersionResult> {
|
||||||
|
const octokit = setupOctokit(githubToken);
|
||||||
|
|
||||||
|
let repo = `${github.context.repo.owner}/${github.context.repo.repo}`;
|
||||||
|
let branch = github.context.ref.replace("refs/heads/", "");
|
||||||
let versionBranch = `changeset-release/${branch}`;
|
let versionBranch = `changeset-release/${branch}`;
|
||||||
|
|
||||||
let { preState } = await readChangesetState(cwd);
|
let { preState } = await readChangesetState(cwd);
|
||||||
|
|
||||||
await git.prepareBranch(versionBranch);
|
await gitUtils.switchToMaybeExistingBranch(versionBranch);
|
||||||
|
await gitUtils.reset(github.context.sha);
|
||||||
|
|
||||||
let versionsByDirectory = await getVersionsByDirectory(cwd);
|
let versionsByDirectory = await getVersionsByDirectory(cwd);
|
||||||
|
|
||||||
@@ -300,11 +332,9 @@ export async function runVersion({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const existingPullRequestsPromise = octokit.rest.pulls.list({
|
let searchQuery = `repo:${repo}+state:open+head:${versionBranch}+base:${branch}+is:pull-request`;
|
||||||
...github.context.repo,
|
let searchResultPromise = octokit.rest.search.issuesAndPullRequests({
|
||||||
state: "open",
|
q: searchQuery,
|
||||||
head: `${github.context.repo.owner}:${versionBranch}`,
|
|
||||||
base: branch,
|
|
||||||
});
|
});
|
||||||
let changedPackages = await getChangedPackages(cwd, versionsByDirectory);
|
let changedPackages = await getChangedPackages(cwd, versionsByDirectory);
|
||||||
let changedPackagesInfoPromises = Promise.all(
|
let changedPackagesInfoPromises = Promise.all(
|
||||||
@@ -325,14 +355,19 @@ export async function runVersion({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const finalPrTitle = `${prTitle}${!!preState ? ` (${preState.tag})` : ""}`;
|
const finalPrTitle = `${prTitle}${!!preState ? ` (${preState.tag})` : ""}`;
|
||||||
|
|
||||||
|
// project with `commit: true` setting could have already committed files
|
||||||
|
if (!(await gitUtils.checkIfClean())) {
|
||||||
const finalCommitMessage = `${commitMessage}${
|
const finalCommitMessage = `${commitMessage}${
|
||||||
!!preState ? ` (${preState.tag})` : ""
|
!!preState ? ` (${preState.tag})` : ""
|
||||||
}`;
|
}`;
|
||||||
|
await gitUtils.commitAll(finalCommitMessage);
|
||||||
|
}
|
||||||
|
|
||||||
await git.pushChanges({ branch: versionBranch, message: finalCommitMessage });
|
await gitUtils.push(versionBranch, { force: true });
|
||||||
|
|
||||||
let existingPullRequests = await existingPullRequestsPromise;
|
let searchResult = await searchResultPromise;
|
||||||
core.info(JSON.stringify(existingPullRequests.data, null, 2));
|
core.info(JSON.stringify(searchResult.data, null, 2));
|
||||||
|
|
||||||
const changedPackagesInfo = (await changedPackagesInfoPromises)
|
const changedPackagesInfo = (await changedPackagesInfoPromises)
|
||||||
.filter((x) => x)
|
.filter((x) => x)
|
||||||
@@ -346,7 +381,7 @@ export async function runVersion({
|
|||||||
prBodyMaxCharacters,
|
prBodyMaxCharacters,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (existingPullRequests.data.length === 0) {
|
if (searchResult.data.items.length === 0) {
|
||||||
core.info("creating pull request");
|
core.info("creating pull request");
|
||||||
const { data: newPullRequest } = await octokit.rest.pulls.create({
|
const { data: newPullRequest } = await octokit.rest.pulls.create({
|
||||||
base: branch,
|
base: branch,
|
||||||
@@ -360,7 +395,7 @@ export async function runVersion({
|
|||||||
pullRequestNumber: newPullRequest.number,
|
pullRequestNumber: newPullRequest.number,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
const [pullRequest] = existingPullRequests.data;
|
const [pullRequest] = searchResult.data.items;
|
||||||
|
|
||||||
core.info(`updating found pull request #${pullRequest.number}`);
|
core.info(`updating found pull request #${pullRequest.number}`);
|
||||||
await octokit.rest.pulls.update({
|
await octokit.rest.pulls.update({
|
||||||
@@ -368,7 +403,6 @@ export async function runVersion({
|
|||||||
title: finalPrTitle,
|
title: finalPrTitle,
|
||||||
body: prBody,
|
body: prBody,
|
||||||
...github.context.repo,
|
...github.context.repo,
|
||||||
state: "open",
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import remarkParse from "remark-parse";
|
|||||||
import remarkStringify from "remark-stringify";
|
import remarkStringify from "remark-stringify";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import mdastToString from "mdast-util-to-string";
|
import mdastToString from "mdast-util-to-string";
|
||||||
|
import { exec } from "@actions/exec";
|
||||||
import { getPackages, Package } from "@manypkg/get-packages";
|
import { getPackages, Package } from "@manypkg/get-packages";
|
||||||
|
|
||||||
export const BumpLevels = {
|
export const BumpLevels = {
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@
|
|||||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||||
|
|
||||||
/* Module Resolution Options */
|
/* Module Resolution Options */
|
||||||
"moduleResolution": "nodenext", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
// "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'. */
|
// "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. */
|
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||||
|
|||||||
Reference in New Issue
Block a user