mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
Add parameter to control version script (#23)
* Add version script * Run build Co-authored-by: mitchellhamilton <mitchell@hamil.town>
This commit is contained in:
co-authored by
mitchellhamilton
parent
65b9570cef
commit
d6b65536ef
@@ -64,7 +64,6 @@ jobs:
|
||||
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
|
||||
fetch-depth: 0
|
||||
|
||||
|
||||
- name: Setup Node.js 12.x
|
||||
uses: actions/setup-node@master
|
||||
with:
|
||||
@@ -82,3 +81,44 @@ jobs:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
```
|
||||
|
||||
### With version script
|
||||
|
||||
If you need to add additional logic to the version command, you can do so by using a version script.
|
||||
|
||||
If the version script is present, this action will run that script instead of `changeset version`, so please make sure that your script calls `changeset version` at some point. All the changes made by the script will be included in the PR.
|
||||
|
||||
```yml
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: Release
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@master
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup Node.js 12.x
|
||||
uses: actions/setup-node@master
|
||||
with:
|
||||
node-version: 12.x
|
||||
|
||||
- name: Install Dependencies
|
||||
run: yarn
|
||||
|
||||
- name: Create Release Pull Request
|
||||
uses: changesets/action@master
|
||||
with:
|
||||
# this expects you to have a npm script called version that runs some logic and then calls `changeset version`.
|
||||
version: yarn version
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
Vendored
+9
-9
File diff suppressed because one or more lines are too long
@@ -59,6 +59,7 @@ import readChangesets from "@changesets/read";
|
||||
let hasChangesets = changesets.length !== 0;
|
||||
|
||||
let publishScript = core.getInput("publish");
|
||||
let versionScript = core.getInput("version");
|
||||
|
||||
if (!hasChangesets && !publishScript) {
|
||||
console.log("No changesets found");
|
||||
@@ -164,6 +165,11 @@ import readChangesets from "@changesets/read";
|
||||
}
|
||||
|
||||
await exec("git", ["reset", "--hard", github.context.sha]);
|
||||
|
||||
if (versionScript) {
|
||||
let [versionCommand, ...versionArgs] = versionScript.split(/\s+/);
|
||||
await exec(versionCommand, versionArgs);
|
||||
} else {
|
||||
let changesetsCliPkgJson = await fs.readJson(
|
||||
path.join("node_modules", "@changesets", "cli", "package.json")
|
||||
);
|
||||
@@ -171,6 +177,8 @@ import readChangesets from "@changesets/read";
|
||||
? "bump"
|
||||
: "version";
|
||||
await exec("node", ["./node_modules/@changesets/cli/bin.js", cmd]);
|
||||
}
|
||||
|
||||
let searchQuery = `repo:${repo}+state:open+head:${versionBranch}+base:${branch}`;
|
||||
let searchResultPromise = octokit.search.issuesAndPullRequests({
|
||||
q: searchQuery
|
||||
|
||||
Reference in New Issue
Block a user