mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
Add outputs variable published and publishedPackages (#26)
* Add outputs variable `published` * publishedPackages
This commit is contained in:
@@ -4,7 +4,20 @@ This action for [Changesets](https://github.com/atlassian/changesets) creates a
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### Without Publishing
|
|
||||||
|
### Inputs
|
||||||
|
|
||||||
|
- publish - The command to use to build and publish packages
|
||||||
|
- version - The command to update version, edit CHANGELOG, read and delete changesets. Default to `changeset version` if not provided
|
||||||
|
|
||||||
|
### Outputs
|
||||||
|
|
||||||
|
- published - A boolean value to indicate whether a publishing is happened or not
|
||||||
|
- publishedPackages - A JSON array to present the published packages. The format is `[{"name": "@xx/xx", "version": "1.2.0"}, {"name": "@xx/xy", "version": "0.8.9"}]`
|
||||||
|
|
||||||
|
### Example workflow:
|
||||||
|
|
||||||
|
#### Without Publishing
|
||||||
|
|
||||||
Create a file at `.github/workflows/release.yml` with the following content.
|
Create a file at `.github/workflows/release.yml` with the following content.
|
||||||
|
|
||||||
@@ -41,7 +54,7 @@ jobs:
|
|||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
```
|
```
|
||||||
|
|
||||||
### With Publishing
|
#### With Publishing
|
||||||
|
|
||||||
Before you can setup this action with publishing, you'll need to have an [npm token](https://docs.npmjs.com/creating-and-viewing-authentication-tokens) that can publish the packages in the repo you're setting up the action for and doesn't have 2FA on publish enabled(2FA on auth can be enabled). You'll also need to [add it as a secret on your GitHub repo](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables) with the name `NPM_TOKEN`. Once you've done that, you can create a file at `.github/workflows/release.yml` with the following content.
|
Before you can setup this action with publishing, you'll need to have an [npm token](https://docs.npmjs.com/creating-and-viewing-authentication-tokens) that can publish the packages in the repo you're setting up the action for and doesn't have 2FA on publish enabled(2FA on auth can be enabled). You'll also need to [add it as a secret on your GitHub repo](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables) with the name `NPM_TOKEN`. Once you've done that, you can create a file at `.github/workflows/release.yml` with the following content.
|
||||||
|
|
||||||
@@ -73,16 +86,23 @@ jobs:
|
|||||||
run: yarn
|
run: yarn
|
||||||
|
|
||||||
- name: Create Release Pull Request or Publish to npm
|
- name: Create Release Pull Request or Publish to npm
|
||||||
|
id: changesets
|
||||||
uses: changesets/action@master
|
uses: changesets/action@master
|
||||||
with:
|
with:
|
||||||
# this expects you to have a script called release which does a build for your packages and calls changeset publish
|
# This expects you to have a script called release which does a build for your packages and calls changeset publish
|
||||||
publish: yarn release
|
publish: yarn release
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
|
||||||
|
- name: Send a Slack notification if a publish happens
|
||||||
|
if: steps.changesets.outputs.published == 'true'
|
||||||
|
# You can do something when a publish happens.
|
||||||
|
run: my-slack-bot send-notification --message "A new version of ${GITHUB_REPOSITORY} was published!"
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### With version script
|
#### With version script
|
||||||
|
|
||||||
If you need to add additional logic to the version command, you can do so by using a version script.
|
If you need to add additional logic to the version command, you can do so by using a version script.
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,15 @@ inputs:
|
|||||||
publish:
|
publish:
|
||||||
description: "The command to use to build and publish packages"
|
description: "The command to use to build and publish packages"
|
||||||
required: false
|
required: false
|
||||||
|
version:
|
||||||
|
description: "The command to update version, edit CHANGELOG, read and delete changesets. Default to `changeset version` 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"}]`
|
||||||
branding:
|
branding:
|
||||||
icon: "package"
|
icon: "package"
|
||||||
color: "blue"
|
color: "blue"
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -60,6 +60,8 @@ import readChangesets from "@changesets/read";
|
|||||||
|
|
||||||
let publishScript = core.getInput("publish");
|
let publishScript = core.getInput("publish");
|
||||||
let versionScript = core.getInput("version");
|
let versionScript = core.getInput("version");
|
||||||
|
core.setOutput('published', 'false');
|
||||||
|
core.setOutput('publishedPackages', '[]');
|
||||||
|
|
||||||
if (!hasChangesets && !publishScript) {
|
if (!hasChangesets && !publishScript) {
|
||||||
console.log("No changesets found");
|
console.log("No changesets found");
|
||||||
@@ -90,6 +92,7 @@ import readChangesets from "@changesets/read";
|
|||||||
publishCommand,
|
publishCommand,
|
||||||
publishArgs
|
publishArgs
|
||||||
);
|
);
|
||||||
|
|
||||||
await exec("git", ["pull", "origin", branch]);
|
await exec("git", ["pull", "origin", branch]);
|
||||||
|
|
||||||
await exec("git", ["push", "origin", `HEAD:${branch}`, "--tags"]);
|
await exec("git", ["push", "origin", `HEAD:${branch}`, "--tags"]);
|
||||||
@@ -149,6 +152,13 @@ import readChangesets from "@changesets/read";
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (releasedWorkspaces.length) {
|
||||||
|
core.setOutput('published', 'true');
|
||||||
|
core.setOutput('publishedPackages', JSON.stringify(releasedWorkspaces.map(
|
||||||
|
workspace => ({name: workspace.name, version: workspace.config.version})
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,7 +175,7 @@ import readChangesets from "@changesets/read";
|
|||||||
}
|
}
|
||||||
|
|
||||||
await exec("git", ["reset", "--hard", github.context.sha]);
|
await exec("git", ["reset", "--hard", github.context.sha]);
|
||||||
|
|
||||||
if (versionScript) {
|
if (versionScript) {
|
||||||
let [versionCommand, ...versionArgs] = versionScript.split(/\s+/);
|
let [versionCommand, ...versionArgs] = versionScript.split(/\s+/);
|
||||||
await exec(versionCommand, versionArgs);
|
await exec(versionCommand, versionArgs);
|
||||||
|
|||||||
Reference in New Issue
Block a user