mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a45c4d594a |
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
"@changesets/action": patch
|
|
||||||
---
|
|
||||||
|
|
||||||
Fix the computed publish plan path passed internally to `changeset pack` by the `/pack` subaction.
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
---
|
|
||||||
"@changesets/action": major
|
|
||||||
---
|
|
||||||
|
|
||||||
Add a new `push-git-tags` option that complements `create-github-releases` to control specifically if git tags should be created but not GitHub releases.
|
|
||||||
|
|
||||||
If `create-github-releases` was previously set to `false`, which also indirectly disabled git tag creation, git tags will now be created instead by default. If this is not desired, set `push-git-tags` to `false` explicitly.
|
|
||||||
@@ -1,14 +1,13 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://unpkg.com/@changesets/config@4.0.0-next.6/schema.json",
|
"$schema": "https://unpkg.com/@changesets/config@1.6.2/schema.json",
|
||||||
"changelog": "@changesets/changelog-github",
|
"changelog": [
|
||||||
|
"@changesets/changelog-github",
|
||||||
|
{ "repo": "changesets/action" }
|
||||||
|
],
|
||||||
"commit": false,
|
"commit": false,
|
||||||
"linked": [],
|
"linked": [],
|
||||||
"access": "restricted",
|
"access": "restricted",
|
||||||
"baseBranch": "main",
|
"baseBranch": "main",
|
||||||
"updateInternalDependencies": "patch",
|
"updateInternalDependencies": "patch",
|
||||||
"ignore": [],
|
"ignore": []
|
||||||
"privatePackages": {
|
|
||||||
"version": true,
|
|
||||||
"tag": true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
"@changesets/action": minor
|
|
||||||
---
|
|
||||||
|
|
||||||
Add new `/select-mode`, `/version`, and `/publish` sub-actions to better control version and publish steps
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
"@changesets/action": major
|
|
||||||
---
|
|
||||||
|
|
||||||
Removed compatibility support for old Changesets v1.
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
---
|
|
||||||
"@changesets/action": major
|
|
||||||
---
|
|
||||||
|
|
||||||
Rename the root action inputs and outputs to better match the sub-actions' conventions.
|
|
||||||
|
|
||||||
Inputs:
|
|
||||||
|
|
||||||
- `version` -> `version-script`
|
|
||||||
- `publish` -> `publish-script`
|
|
||||||
- `commit` -> `commit-message`
|
|
||||||
- `title` -> `pr-title`
|
|
||||||
- `branch` -> `pr-base-branch`
|
|
||||||
|
|
||||||
Outputs:
|
|
||||||
|
|
||||||
- `pull-request-number` -> `pr-number`
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
"@changesets/action": major
|
|
||||||
---
|
|
||||||
|
|
||||||
Remove support for passing custom GitHub token through the GITHUB_TOKEN environment variable. It should be passed to the `github-token` input instead.
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
"@changesets/action": patch
|
|
||||||
---
|
|
||||||
|
|
||||||
Authenticate git CLI pushes with the configured GitHub token using Git extra headers instead of writing to a global `.netrc` file.
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
"@changesets/action": patch
|
|
||||||
---
|
|
||||||
|
|
||||||
Derive the Git server URL from the GitHub Actions context when configuring git CLI authentication to support GitHub Enterprise Server setups.
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
"@changesets/action": major
|
|
||||||
---
|
|
||||||
|
|
||||||
Remove `cwd` option for `changesets/action`. Use the step `working-directory` option instead to change the directory.
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"mode": "pre",
|
|
||||||
"tag": "next",
|
|
||||||
"changesets": [
|
|
||||||
"all-cars-grin",
|
|
||||||
"chubby-geese-sink",
|
|
||||||
"eight-clocks-pull",
|
|
||||||
"eighty-doors-swim",
|
|
||||||
"eighty-parks-tickle",
|
|
||||||
"fiery-toes-vanish",
|
|
||||||
"git-cli-auth-header",
|
|
||||||
"git-cli-server-url",
|
|
||||||
"lemon-turtles-itch",
|
|
||||||
"ready-mangos-boil",
|
|
||||||
"shaky-rings-type",
|
|
||||||
"shy-months-crash",
|
|
||||||
"silent-tips-dance",
|
|
||||||
"yellow-roses-fix"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
"@changesets/action": patch
|
|
||||||
---
|
|
||||||
|
|
||||||
Fixed usage of `--from-publish-plan` flag used by the `/pack` subaction
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
"@changesets/action": major
|
|
||||||
---
|
|
||||||
|
|
||||||
Update to Changesets v3 packages
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
"@changesets/action": minor
|
|
||||||
---
|
|
||||||
|
|
||||||
Published packages detection done through stdout parsing was replaced with one based on the shared output file using `CHANGESETS_OUTPUT` environment variable. When using custom scripts this environment variable should always be passed down to the Changesets CLI invocations.
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
"@changesets/action": patch
|
|
||||||
---
|
|
||||||
|
|
||||||
Fix the `/version` subaction to not crash on missing `pr-base-branch` input. This input is meant to be optional.
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
"@changesets/action": major
|
|
||||||
---
|
|
||||||
|
|
||||||
Rename the input and output names to kebab-case instead of camelCase to match the official GitHub actions pattern
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
/.github/** @Andarist @bluwy @emmatown
|
/.github/workflows/** @Andarist @bluwy @emmatown
|
||||||
/action.yml @Andarist @bluwy @emmatown
|
/action.yml @Andarist @bluwy @emmatown
|
||||||
/scripts/bump.ts @Andarist @bluwy @emmatown
|
/scripts/bump.ts @Andarist @bluwy @emmatown
|
||||||
/scripts/release.ts @Andarist @bluwy @emmatown
|
/scripts/release.ts @Andarist @bluwy @emmatown
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
name: Setup bot auth
|
|
||||||
description: Create a GitHub App token and configure matching git identity
|
|
||||||
|
|
||||||
inputs:
|
|
||||||
client-id:
|
|
||||||
description: GitHub App client ID
|
|
||||||
required: true
|
|
||||||
private-key:
|
|
||||||
description: GitHub App private key
|
|
||||||
required: true
|
|
||||||
permission-contents:
|
|
||||||
description: Contents permission for the GitHub App token
|
|
||||||
required: false
|
|
||||||
default: write
|
|
||||||
permission-pull-requests:
|
|
||||||
description: Pull requests permission for the GitHub App token
|
|
||||||
required: false
|
|
||||||
|
|
||||||
outputs:
|
|
||||||
token:
|
|
||||||
description: GitHub App installation access token
|
|
||||||
value: ${{ steps.app-token.outputs.token }}
|
|
||||||
|
|
||||||
runs:
|
|
||||||
using: composite
|
|
||||||
steps:
|
|
||||||
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
|
|
||||||
id: app-token
|
|
||||||
with:
|
|
||||||
client-id: ${{ inputs.client-id }}
|
|
||||||
private-key: ${{ inputs.private-key }}
|
|
||||||
permission-contents: ${{ inputs.permission-contents }}
|
|
||||||
permission-pull-requests: ${{ inputs.permission-pull-requests }}
|
|
||||||
|
|
||||||
- name: Setup Git user
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
app_user="$APP_SLUG[bot]"
|
|
||||||
app_id="$(gh api "/users/$app_user" --jq .id)"
|
|
||||||
git config user.name "$app_user"
|
|
||||||
git config user.email "$app_id+$app_user@users.noreply.github.com"
|
|
||||||
env:
|
|
||||||
APP_SLUG: ${{ steps.app-token.outputs.app-slug }}
|
|
||||||
GH_TOKEN: ${{ steps.app-token.outputs.token }}
|
|
||||||
+8
-27
@@ -1,32 +1,13 @@
|
|||||||
|
# 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
|
version: 2
|
||||||
updates:
|
updates:
|
||||||
- package-ecosystem: "npm"
|
- package-ecosystem: "npm" # See documentation for possible values
|
||||||
directory: "/"
|
directory: "/" # Location of package manifests
|
||||||
schedule:
|
schedule:
|
||||||
interval: "monthly"
|
interval: "weekly"
|
||||||
cooldown:
|
cooldown:
|
||||||
default-days: 7
|
default-days: 7
|
||||||
open-pull-requests-limit: 10
|
|
||||||
versioning-strategy: increase
|
|
||||||
groups:
|
|
||||||
production-dependencies:
|
|
||||||
dependency-type: "production"
|
|
||||||
update-types:
|
|
||||||
- minor
|
|
||||||
- patch
|
|
||||||
development-dependencies:
|
|
||||||
dependency-type: "development"
|
|
||||||
update-types:
|
|
||||||
- minor
|
|
||||||
- patch
|
|
||||||
- package-ecosystem: "github-actions"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "monthly"
|
|
||||||
cooldown:
|
|
||||||
default-days: 7
|
|
||||||
open-pull-requests-limit: 5
|
|
||||||
groups:
|
|
||||||
github-actions:
|
|
||||||
patterns:
|
|
||||||
- "*"
|
|
||||||
|
|||||||
+11
-11
@@ -7,9 +7,6 @@ on:
|
|||||||
merge_group:
|
merge_group:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- next
|
|
||||||
# merge group rulesets don't allow wildcards so in settings each maintenance branch needs to be added separately
|
|
||||||
- "maintenance/v*" # branch rulesets don't support v[0-9]+
|
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
@@ -27,12 +24,12 @@ jobs:
|
|||||||
security-events: write # allow writing security events
|
security-events: write # allow writing security events
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
- name: Run zizmor
|
- name: Run zizmor
|
||||||
uses: zizmorcore/zizmor-action@5f14fd08f7cf1cb1609c1e344975f152c7ee938d # v0.5.6
|
uses: zizmorcore/zizmor-action@b1d7e1fb5de872772f31590499237e7cce841e8e # v0.5.3
|
||||||
with:
|
with:
|
||||||
persona: pedantic
|
persona: pedantic
|
||||||
annotations: true
|
annotations: true
|
||||||
@@ -40,11 +37,12 @@ jobs:
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
name: Test
|
name: Test
|
||||||
runs-on: ubuntu-latest
|
|
||||||
timeout-minutes: 20
|
timeout-minutes: 20
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repo
|
- name: Check out repo
|
||||||
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
@@ -55,11 +53,12 @@ jobs:
|
|||||||
|
|
||||||
typecheck:
|
typecheck:
|
||||||
name: Typecheck
|
name: Typecheck
|
||||||
runs-on: ubuntu-latest
|
|
||||||
timeout-minutes: 20
|
timeout-minutes: 20
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repo
|
- name: Check out repo
|
||||||
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
@@ -70,11 +69,12 @@ jobs:
|
|||||||
|
|
||||||
lint:
|
lint:
|
||||||
name: Lint
|
name: Lint
|
||||||
runs-on: ubuntu-latest
|
|
||||||
timeout-minutes: 20
|
timeout-minutes: 20
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repo
|
- name: Check out repo
|
||||||
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- next
|
|
||||||
- "maintenance/v*" # branch rulesets don't support v[0-9]+
|
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
@@ -15,43 +13,20 @@ concurrency:
|
|||||||
permissions: {} # each job should define its own permission explicitly
|
permissions: {} # each job should define its own permission explicitly
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
select-mode:
|
|
||||||
name: Select mode
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
timeout-minutes: 20
|
|
||||||
outputs:
|
|
||||||
mode: ${{ steps.select-mode.outputs.mode }}
|
|
||||||
permissions:
|
|
||||||
contents: read # to check out repo (actions/checkout)
|
|
||||||
steps:
|
|
||||||
- name: Check out repo
|
|
||||||
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
|
|
||||||
- uses: ./.github/actions/ci-setup
|
|
||||||
with:
|
|
||||||
skip-cache: true # avoid cache poisoning attacks
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
run: pnpm build
|
|
||||||
|
|
||||||
- name: Select mode
|
|
||||||
id: select-mode
|
|
||||||
uses: ./select-mode
|
|
||||||
|
|
||||||
version:
|
version:
|
||||||
name: Version
|
name: Version
|
||||||
if: needs.select-mode.outputs.mode == 'version'
|
|
||||||
needs: select-mode
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment: version
|
environment: version
|
||||||
timeout-minutes: 20
|
timeout-minutes: 20
|
||||||
|
outputs:
|
||||||
|
hasChangesets: ${{ steps.changesets.outputs.hasChangesets }}
|
||||||
permissions:
|
permissions:
|
||||||
contents: read # to check out repo (actions/checkout)
|
contents: write # to create release (changesets/action)
|
||||||
|
issues: write # to post issue comments (changesets/action)
|
||||||
|
pull-requests: write # to create pull request (changesets/action)
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repo
|
- name: Check out repo
|
||||||
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
@@ -62,36 +37,41 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: pnpm build
|
run: pnpm build
|
||||||
|
|
||||||
- uses: ./.github/actions/setup-bot-auth
|
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
|
||||||
id: bot-auth
|
id: app-token
|
||||||
with:
|
with:
|
||||||
client-id: ${{ vars.APP_CLIENT_ID }}
|
client-id: ${{ vars.APP_CLIENT_ID }}
|
||||||
private-key: ${{ secrets.APP_PRIVATE_KEY }}
|
private-key: ${{ secrets.APP_PRIVATE_KEY }}
|
||||||
permission-contents: write # to create version commits (changesets/action)
|
|
||||||
permission-pull-requests: write # to create pull request (changesets/action)
|
|
||||||
|
|
||||||
- name: Create or update release pull request
|
- name: Create or update release pull request
|
||||||
id: changesets
|
id: changesets
|
||||||
uses: ./version
|
uses: ./
|
||||||
with:
|
with:
|
||||||
github-token: ${{ steps.bot-auth.outputs.token }}
|
github-token: ${{ steps.app-token.outputs.token }}
|
||||||
setup-git-user: false
|
version: pnpm bump
|
||||||
script: pnpm bump
|
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
name: Publish
|
name: Publish
|
||||||
if: needs.select-mode.outputs.mode == 'publish'
|
if: needs.version.outputs.hasChangesets == 'false'
|
||||||
needs: select-mode
|
needs: version
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment: marketplace
|
environment: marketplace
|
||||||
timeout-minutes: 20
|
timeout-minutes: 20
|
||||||
permissions:
|
permissions:
|
||||||
contents: write # to create release and have it authored by github-actions (changesets/action)
|
contents: write # to create release and have it authored by github-actions (changesets/action)
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repo
|
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
|
||||||
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
id: app-token
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
client-id: ${{ vars.APP_CLIENT_ID }}
|
||||||
|
private-key: ${{ secrets.APP_PRIVATE_KEY }}
|
||||||
|
|
||||||
|
- name: Check out repo
|
||||||
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: true
|
||||||
|
# we need this token to bypass the branch and tag protection rules
|
||||||
|
token: ${{ steps.app-token.outputs.token }}
|
||||||
|
|
||||||
- uses: ./.github/actions/ci-setup
|
- uses: ./.github/actions/ci-setup
|
||||||
with:
|
with:
|
||||||
@@ -100,15 +80,7 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: pnpm build
|
run: pnpm build
|
||||||
|
|
||||||
- uses: ./.github/actions/setup-bot-auth
|
|
||||||
id: bot-auth
|
|
||||||
with:
|
|
||||||
client-id: ${{ vars.APP_CLIENT_ID }}
|
|
||||||
private-key: ${{ secrets.APP_PRIVATE_KEY }}
|
|
||||||
permission-contents: write # to bypass branch and tag protection rules (release.ts)
|
|
||||||
|
|
||||||
- name: Publish to marketplace
|
- name: Publish to marketplace
|
||||||
uses: ./publish
|
uses: ./
|
||||||
with:
|
with:
|
||||||
github-token: ${{ steps.bot-auth.outputs.token }}
|
publish: pnpm release
|
||||||
script: pnpm release
|
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repo
|
- name: Check out repo
|
||||||
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
@@ -166,17 +166,13 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: pnpm build
|
run: pnpm build
|
||||||
|
|
||||||
- uses: ./.github/actions/setup-bot-auth
|
- name: Setup Git user
|
||||||
id: bot-auth
|
run: |
|
||||||
with:
|
git config --global user.name "github-actions[bot]"
|
||||||
client-id: ${{ vars.APP_CLIENT_ID }}
|
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||||
private-key: ${{ secrets.APP_PRIVATE_KEY }}
|
|
||||||
permission-contents: write # to push the release snapshot branch (release-pr.ts)
|
|
||||||
|
|
||||||
- name: Release snapshot version
|
- name: Release snapshot version
|
||||||
run: pnpm release:pr
|
run: pnpm release:pr
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ steps.bot-auth.outputs.token }}
|
|
||||||
|
|
||||||
- name: Add success reaction
|
- name: Add success reaction
|
||||||
run: gh api "/repos/$GH_REPO/issues/comments/$COMMENT_ID/reactions" -f content='rocket'
|
run: gh api "/repos/$GH_REPO/issues/comments/$COMMENT_ID/reactions" -f content='rocket'
|
||||||
|
|||||||
@@ -1,65 +1,5 @@
|
|||||||
# @changesets/action
|
# @changesets/action
|
||||||
|
|
||||||
## 2.0.0-next.3
|
|
||||||
|
|
||||||
### Major Changes
|
|
||||||
|
|
||||||
- [#680](https://github.com/changesets/action/pull/680) [`ca57073`](https://github.com/changesets/action/commit/ca57073900dc678254406a052a03c0c8824e319d) Thanks [@bluwy](https://github.com/bluwy)! - Add a new `push-git-tags` option that complements `create-github-releases` to control specifically if git tags should be created but not GitHub releases.
|
|
||||||
|
|
||||||
If `create-github-releases` was previously set to `false`, which also indirectly disabled git tag creation, git tags will now be created instead by default. If this is not desired, set `push-git-tags` to `false` explicitly.
|
|
||||||
|
|
||||||
- [#681](https://github.com/changesets/action/pull/681) [`7359107`](https://github.com/changesets/action/commit/73591071e61c7f61cf322dd7a6341dc29a8e1d4e) Thanks [@bluwy](https://github.com/bluwy)! - Rename the root action inputs and outputs to better match the sub-actions' conventions.
|
|
||||||
|
|
||||||
Inputs:
|
|
||||||
- `version` -> `version-script`
|
|
||||||
- `publish` -> `publish-script`
|
|
||||||
- `commit` -> `commit-message`
|
|
||||||
- `title` -> `pr-title`
|
|
||||||
- `branch` -> `pr-base-branch`
|
|
||||||
|
|
||||||
Outputs:
|
|
||||||
- `pull-request-number` -> `pr-number`
|
|
||||||
|
|
||||||
- [#674](https://github.com/changesets/action/pull/674) [`164652b`](https://github.com/changesets/action/commit/164652bdd60525670d95291addb8c6f92833ac60) Thanks [@bluwy](https://github.com/bluwy)! - Remove support for passing custom GitHub token through the GITHUB_TOKEN environment variable. It should be passed to the `github-token` input instead.
|
|
||||||
|
|
||||||
- [#673](https://github.com/changesets/action/pull/673) [`823cf74`](https://github.com/changesets/action/commit/823cf741ca57c5e22652123d3a847dfafcd77ca0) Thanks [@bluwy](https://github.com/bluwy)! - Update to Changesets v3 packages
|
|
||||||
|
|
||||||
- [#668](https://github.com/changesets/action/pull/668) [`0eae789`](https://github.com/changesets/action/commit/0eae789230defbc4ad287e9b476aba7e842e34e0) Thanks [@bluwy](https://github.com/bluwy)! - Rename the input and output names to kebab-case instead of camelCase to match the official GitHub actions pattern
|
|
||||||
|
|
||||||
### Minor Changes
|
|
||||||
|
|
||||||
- [#678](https://github.com/changesets/action/pull/678) [`f71ae04`](https://github.com/changesets/action/commit/f71ae043ed5deb17952900091e009a60edef9507) Thanks [@Andarist](https://github.com/Andarist)! - Published packages detection done through stdout parsing was replaced with one based on the shared output file using `CHANGESETS_OUTPUT` environment variable. When using custom scripts this environment variable should always be passed down to the Changesets CLI invocations.
|
|
||||||
|
|
||||||
## 2.0.0-next.2
|
|
||||||
|
|
||||||
### Patch Changes
|
|
||||||
|
|
||||||
- [#670](https://github.com/changesets/action/pull/670) [`5a8b9b7`](https://github.com/changesets/action/commit/5a8b9b721bf683e3bf9bd72ea92a685dc024147b) Thanks [@Andarist](https://github.com/Andarist)! - Authenticate git CLI pushes with the configured GitHub token using Git extra headers instead of writing to a global `.netrc` file.
|
|
||||||
|
|
||||||
- [#670](https://github.com/changesets/action/pull/670) [`5a8b9b7`](https://github.com/changesets/action/commit/5a8b9b721bf683e3bf9bd72ea92a685dc024147b) Thanks [@Andarist](https://github.com/Andarist)! - Derive the Git server URL from the GitHub Actions context when configuring git CLI authentication to support GitHub Enterprise Server setups.
|
|
||||||
|
|
||||||
## 2.0.0-next.1
|
|
||||||
|
|
||||||
### Patch Changes
|
|
||||||
|
|
||||||
- [#663](https://github.com/changesets/action/pull/663) [`ccb3811`](https://github.com/changesets/action/commit/ccb38113eaaa4a13eb6aabe09520e49cc8519b84) Thanks [@Andarist](https://github.com/Andarist)! - Fix the computed publish plan path passed internally to `changeset pack` by the `/pack` subaction.
|
|
||||||
|
|
||||||
- [#662](https://github.com/changesets/action/pull/662) [`5c88881`](https://github.com/changesets/action/commit/5c88881fff1f0d8b055d4a2d3a74a8ce843db6f3) Thanks [@Andarist](https://github.com/Andarist)! - Fixed usage of `--from-publish-plan` flag used by the `/pack` subaction
|
|
||||||
|
|
||||||
- [#666](https://github.com/changesets/action/pull/666) [`dc29b73`](https://github.com/changesets/action/commit/dc29b738b532d9e95f46b9bf493e2e3fdf48a7ed) Thanks [@Andarist](https://github.com/Andarist)! - Fix the `/version` subaction to not crash on missing `pr-base-branch` input. This input is meant to be optional.
|
|
||||||
|
|
||||||
## 2.0.0-next.0
|
|
||||||
|
|
||||||
### Major Changes
|
|
||||||
|
|
||||||
- [#657](https://github.com/changesets/action/pull/657) [`4f718b5`](https://github.com/changesets/action/commit/4f718b5921490b1efeb015a81abb6a4633892851) Thanks [@Andarist](https://github.com/Andarist)! - Removed compatibility support for old Changesets v1.
|
|
||||||
|
|
||||||
- [#659](https://github.com/changesets/action/pull/659) [`5649ff4`](https://github.com/changesets/action/commit/5649ff41b8eb1b7a281011e45df781c6d4628fd0) Thanks [@bluwy](https://github.com/bluwy)! - Remove `cwd` option for `changesets/action`. Use the step `working-directory` option instead to change the directory.
|
|
||||||
|
|
||||||
### Minor Changes
|
|
||||||
|
|
||||||
- [#656](https://github.com/changesets/action/pull/656) [`a12d90d`](https://github.com/changesets/action/commit/a12d90de8394e63c952622b2fd3f98c8729c48b0) Thanks [@bluwy](https://github.com/bluwy)! - Add new `/select-mode`, `/version`, and `/publish` sub-actions to better control version and publish steps
|
|
||||||
|
|
||||||
## 1.9.0
|
## 1.9.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
# Changesets Release Action
|
# Changesets Release Action
|
||||||
|
|
||||||
> [!IMPORTANT]
|
|
||||||
> This is the development branch for `changesets/action` v2 compatible with Changesets v3. For the v1 code compatible with Changesets v2, check out the [`maintenance/v1`](https://github.com/changesets/action/tree/maintenance/v1) branch.
|
|
||||||
|
|
||||||
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/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.
|
||||||
|
|
||||||
There are also sub-actions hosted in this repository. Check out their respective READMEs for more details:
|
There are also sub-actions hosted in this repository. Check out their respective READMEs for more details:
|
||||||
@@ -65,7 +62,7 @@ jobs:
|
|||||||
run: pnpm install --frozen-lockfile
|
run: pnpm install --frozen-lockfile
|
||||||
|
|
||||||
- name: Create Release Pull Request
|
- name: Create Release Pull Request
|
||||||
uses: changesets/action@v2
|
uses: changesets/action@v1
|
||||||
```
|
```
|
||||||
|
|
||||||
#### With Publishing
|
#### With Publishing
|
||||||
@@ -103,10 +100,10 @@ jobs:
|
|||||||
|
|
||||||
- name: Create Release Pull Request or Publish to npm
|
- name: Create Release Pull Request or Publish to npm
|
||||||
id: changesets
|
id: changesets
|
||||||
uses: changesets/action@v2
|
uses: changesets/action@v1
|
||||||
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-script: pnpm release
|
publish: pnpm release
|
||||||
env:
|
env:
|
||||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
|
||||||
@@ -170,7 +167,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Create Release Pull Request or Publish to npm
|
- name: Create Release Pull Request or Publish to npm
|
||||||
id: changesets
|
id: changesets
|
||||||
uses: changesets/action@v2
|
uses: changesets/action@v1
|
||||||
|
|
||||||
- name: Publish
|
- name: Publish
|
||||||
if: steps.changesets.outputs.hasChangesets == 'false'
|
if: steps.changesets.outputs.hasChangesets == 'false'
|
||||||
@@ -214,10 +211,10 @@ jobs:
|
|||||||
run: pnpm install --frozen-lockfile
|
run: pnpm install --frozen-lockfile
|
||||||
|
|
||||||
- name: Create Release Pull Request
|
- name: Create Release Pull Request
|
||||||
uses: changesets/action@v2
|
uses: changesets/action@v1
|
||||||
with:
|
with:
|
||||||
# this expects you to have a npm script called version that runs some logic and then calls `changeset version`.
|
# this expects you to have a npm script called version that runs some logic and then calls `changeset version`.
|
||||||
version-script: pnpm version
|
version: pnpm version
|
||||||
```
|
```
|
||||||
|
|
||||||
#### With Yarn 2 / Plug'n'Play
|
#### With Yarn 2 / Plug'n'Play
|
||||||
@@ -225,8 +222,8 @@ 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:
|
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
|
```yaml
|
||||||
- uses: changesets/action@v2
|
- uses: changesets/action@v1
|
||||||
with:
|
with:
|
||||||
version-script: yarn changeset version
|
version: yarn changeset version
|
||||||
# ...
|
# ...
|
||||||
```
|
```
|
||||||
|
|||||||
+22
-26
@@ -8,37 +8,31 @@ inputs:
|
|||||||
description: "The GitHub token to use for authentication. Defaults to the GitHub-provided token."
|
description: "The GitHub token to use for authentication. Defaults to the GitHub-provided token."
|
||||||
required: false
|
required: false
|
||||||
default: ${{ github.token }}
|
default: ${{ github.token }}
|
||||||
publish-script:
|
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-script:
|
version:
|
||||||
description: "The command to update version, edit CHANGELOG, read and delete changesets. Default to `changeset version` if not provided"
|
description: "The command to update version, edit CHANGELOG, read and delete changesets. Default to `changeset version` if not provided"
|
||||||
required: false
|
required: false
|
||||||
commit-message:
|
cwd:
|
||||||
description: "The commit message. Default to `Version Packages`"
|
description: Sets the cwd for the node process. Default to `process.cwd()`
|
||||||
required: false
|
required: false
|
||||||
default: "Version Packages"
|
commit:
|
||||||
pr-title:
|
description: |
|
||||||
description: "The pull request title. Default to `Version Packages`"
|
The commit message. Default to `Version Packages`
|
||||||
required: false
|
required: false
|
||||||
default: "Version Packages"
|
title:
|
||||||
pr-draft:
|
description: The pull request title. Default to `Version Packages`
|
||||||
description: "Controls draft PR behavior. Use 'create' to create new version PRs as draft, or 'always' to also convert existing version PRs back to draft when updating them."
|
|
||||||
required: false
|
required: false
|
||||||
pr-base-branch:
|
setupGitUser:
|
||||||
description: "Sets the base branch of the PR. Defaults to `github.ref_name`."
|
description: Sets up the git user for commits as `"github-actions[bot]"`. Default to `true`
|
||||||
required: false
|
|
||||||
create-github-releases:
|
|
||||||
description: "Whether to create Github releases after publish"
|
|
||||||
required: false
|
required: false
|
||||||
default: true
|
default: true
|
||||||
push-git-tags:
|
createGithubReleases:
|
||||||
description: >
|
description: "A boolean value to indicate whether to create Github releases after `publish` or not"
|
||||||
Whether to create git tags after publish. If `create-github-releases` is set to `true`,
|
|
||||||
this option will also always be `true`.
|
|
||||||
required: false
|
required: false
|
||||||
default: true
|
default: true
|
||||||
commit-mode:
|
commitMode:
|
||||||
description: >
|
description: >
|
||||||
An enum to specify the commit mode. Use "git-cli" to push changes using the Git CLI,
|
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",
|
or "github-api" to push changes via the GitHub API. When using "github-api",
|
||||||
@@ -46,19 +40,21 @@ inputs:
|
|||||||
or app who owns the GITHUB_TOKEN.
|
or app who owns the GITHUB_TOKEN.
|
||||||
required: false
|
required: false
|
||||||
default: "git-cli"
|
default: "git-cli"
|
||||||
setup-git-user:
|
branch:
|
||||||
description: Sets up the git user for commits as `"github-actions[bot]"`. Default to `true`
|
description: Sets the branch in which the action will run. Default to `github.ref_name` if not provided
|
||||||
|
required: false
|
||||||
|
prDraft:
|
||||||
|
description: 'Controls draft PR behavior. Use "create" to create new version PRs as draft, or "always" to also convert existing version PRs back to draft when updating them.'
|
||||||
required: false
|
required: false
|
||||||
default: true
|
|
||||||
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
|
||||||
published-packages:
|
publishedPackages:
|
||||||
description: >
|
description: >
|
||||||
A JSON array to present the published packages. The format is `[{"name": "@xx/xx", "version": "1.2.0"}, {"name": "@xx/xy", "version": "0.8.9"}]`
|
A JSON array to present the published packages. The format is `[{"name": "@xx/xx", "version": "1.2.0"}, {"name": "@xx/xy", "version": "0.8.9"}]`
|
||||||
has-changesets:
|
hasChangesets:
|
||||||
description: A boolean about whether there were changesets. Useful if you want to create your own publishing functionality.
|
description: A boolean about whether there were changesets. Useful if you want to create your own publishing functionality.
|
||||||
pr-number:
|
pullRequestNumber:
|
||||||
description: The pull request number that was created or updated
|
description: The pull request number that was created or updated
|
||||||
branding:
|
branding:
|
||||||
icon: "package"
|
icon: "package"
|
||||||
|
|||||||
Vendored
-12
File diff suppressed because one or more lines are too long
Vendored
+18
File diff suppressed because one or more lines are too long
Vendored
+150
-2
File diff suppressed because one or more lines are too long
Vendored
+96
File diff suppressed because one or more lines are too long
-143
File diff suppressed because one or more lines are too long
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
import{m as e,p as t}from"./manypkg-get-packages-BoFCbqAx.js";import{n,p as r,s as i,t as a}from"./utils-DxGVktYo.js";import o from"node:fs/promises";import s from"node:path";import c from"node:os";try{await l()}catch(e){t(e.message)}async function l(){let t=i(`publish-plan-artifact-id`),n=process.cwd(),a=process.env.RUNNER_TEMP??await o.realpath(c.tmpdir()),l=s.join(a,`changeset-pack-${Date.now()}`);await u(n,{outDir:l,publishPlanPath:t?await d(a,Number(t)):void 0});let p=await r.uploadArtifact(`changeset-pack-${Date.now()}`,await f(l),l,{retentionDays:30});if(p.id===void 0)throw Error(`Packed artifact upload did not return an artifact id`);e(`pack-dir-artifact-id`,String(p.id))}async function u(e,t){let r=[`pack`,`--out-dir`,t.outDir];t.publishPlanPath&&r.push(`--from-publish-plan`,t.publishPlanPath),await n(r,{cwd:e,env:process.env})}async function d(e,t){let n=await a(e,t,`changeset-publish-plan`);return s.join(n,`publish-plan.json`)}async function f(e){let t=await o.readdir(e,{withFileTypes:!0});return(await Promise.all(t.map(async t=>{let n=s.join(e,t.name);return t.isDirectory()?f(n):[n]}))).flat()}export{};
|
|
||||||
Vendored
+1
-1
@@ -1 +1 @@
|
|||||||
import{a as e,f as t,i as n,m as r,p as i}from"./manypkg-get-packages-BoFCbqAx.js";import{c as a,s as o}from"./utils-DxGVktYo.js";try{await s()}catch(e){i(e.message)}async function s(){let i=n.payload.pull_request;if(!i)throw Error("This action should only be run on `pull_request_target` or `pull_request` events");let s=a(`github-token`),l=a(`body`),u=o(`update-id`),d=u?c(u):null,f=d?`${d}\n\n${l}`:l,p={repo:i.base.repo.name,owner:i.base.repo.owner.login,issue_number:i.number,body:f},m=e(s),h;d&&(t(`Checking for existing comment...`),h=await m.rest.issues.listComments({repo:i.base.repo.name,owner:i.base.repo.owner.login,issue_number:i.number}).then(e=>e.data.find(e=>e.body?.includes(d))?.id)),h?(t(`Updating existing comment (id: ${h})...`),await m.rest.issues.updateComment({...p,comment_id:h}),r(`comment-id`,h)):(t(`Creating new comment...`),r(`comment-id`,(await m.rest.issues.createComment(p)).data.id)),t(`Done!`)}function c(e){let t=`changesets-action-pr-comment`;return t===e?`<!-- ${t} -->`:`<!-- ${t}:${e} -->`}export{};
|
import{a as e,c as t,n,o as r,s as i,t as a}from"./github-DTObde6f.js";try{await o()}catch(e){i(e.message)}async function o(){let i=a.payload.pull_request;if(!i)throw Error("This action should only be run on `pull_request_target` or `pull_request` events");let o=e(`github-token`,{required:!0}),c=e(`body`,{required:!0}),l=e(`update-id`),u=l?s(l):null,d=u?`${u}\n\n${c}`:c,f={repo:i.base.repo.name,owner:i.base.repo.owner.login,issue_number:i.number,body:d},p=n(o),m;u&&(r(`Checking for existing comment...`),m=await p.rest.issues.listComments({repo:i.base.repo.name,owner:i.base.repo.owner.login,issue_number:i.number}).then(e=>e.data.find(e=>e.body?.includes(u))?.id)),m?(r(`Updating existing comment (id: ${m})...`),await p.rest.issues.updateComment({...f,comment_id:m}),t(`comment-id`,m)):(r(`Creating new comment...`),t(`comment-id`,(await p.rest.issues.createComment(f)).data.id)),r(`Done!`)}function s(e){let t=`changesets-action-pr-comment`;return t===e?`<!-- ${t} -->`:`<!-- ${t}:${e} -->`}export{};
|
||||||
Vendored
+11
-10
File diff suppressed because one or more lines are too long
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
import{m as e,p as t,u as n}from"./manypkg-get-packages-BoFCbqAx.js";import{r,t as i}from"./run-Bw2IS-rI.js";import{c as a,s as o,t as s}from"./utils-DxGVktYo.js";import c from"node:fs/promises";import l from"node:os";try{await u()}catch(e){t(e.message)}async function u(){let t=a(`github-token`),u=o(`script`),d=o(`pack-dir-artifact-id`),f=n(`create-github-releases`),p=n(`push-git-tags`);if(f&&!p)throw Error(`The input 'create-github-releases' is set to true, but 'push-git-tags' is set to false. Creating GitHub releases requires pushing git tags. Please set 'push-git-tags' to true or set 'create-github-releases' to false.`);let m=process.cwd(),h=await i({script:u,github:new r({cwd:m,githubToken:t,commitMode:`github-api`}),createGithubReleases:f,pushGitTags:p,cwd:m,fromPackDir:d?await s(process.env.RUNNER_TEMP??await c.realpath(l.tmpdir()),Number(d),`changeset-pack`):void 0});if(h.published?(e(`published`,`true`),e(`published-packages`,JSON.stringify(h.publishedPackages))):e(`published`,`false`),h.exitCode!==0)throw Error(`Publish command exited with code ${h.exitCode}${h.published?`, but some packages were published: ${h.publishedPackages.map(e=>`${e.name}@${e.version}`).join(`, `)}`:``}`)}export{};
|
|
||||||
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
import{i as e,t}from"./dist-IQHIouET.js";async function n(n=process.cwd()){let r=await e(n),i=await t(n);if(r!==void 0&&r.mode===`pre`){let e=new Set(r.changesets);return{preState:r,changesets:i.filter(t=>!e.has(t.id))}}return{preState:void 0,changesets:i}}export{n as t};
|
|
||||||
Vendored
-98
@@ -1,98 +0,0 @@
|
|||||||
import{T as e,_ as t,a as n,f as r,g as i,i as a,t as o,v as s}from"./manypkg-get-packages-BoFCbqAx.js";import{o as c}from"./dist-IQHIouET.js";import{a as l,d as u,i as d,l as f,m as p,n as m,o as h,u as g}from"./utils-DxGVktYo.js";import{t as ee}from"./readChangesetState-wtnwjhXS.js";import _ from"node:fs/promises";import v from"path";import{Buffer as y}from"node:buffer";import{randomUUID as b}from"node:crypto";import x from"node:path";import S from"node:os";const C=async(e,t)=>(await e.graphql(`
|
|
||||||
query getRepositoryMetadata(
|
|
||||||
$owner: String!
|
|
||||||
$repo: String!
|
|
||||||
$baseRef: String!
|
|
||||||
$targetRef: String!
|
|
||||||
) {
|
|
||||||
repository(owner: $owner, name: $repo) {
|
|
||||||
id
|
|
||||||
baseRef: ref(qualifiedName: $baseRef) {
|
|
||||||
id
|
|
||||||
target {
|
|
||||||
oid
|
|
||||||
... on Tag {
|
|
||||||
target {
|
|
||||||
oid
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
targetBranch: ref(qualifiedName: $targetRef) {
|
|
||||||
id
|
|
||||||
target {
|
|
||||||
oid
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`,t)).repository,w=async(e,t)=>e.graphql(`
|
|
||||||
mutation createCommitOnBranch($input: CreateCommitOnBranchInput!) {
|
|
||||||
createCommitOnBranch(input: $input) {
|
|
||||||
commit {
|
|
||||||
oid
|
|
||||||
}
|
|
||||||
ref {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`,t);function T(e){if(typeof e==`object`)return{headline:e.headline.trim(),body:e.body?.trim()};if(!e.includes(`
|
|
||||||
`))return{headline:e.trim()};let[t,...n]=e.split(`
|
|
||||||
`);return{headline:t.trim(),body:n.join(`
|
|
||||||
`).trim()}}function E(e){return`branch`in e?`refs/heads/${e.branch}`:`tag`in e?`refs/tags/${e.tag}`:e.commit}async function D({octokit:e,owner:t,repo:n,branch:r,base:i,force:a=!1,message:o,fileChanges:s}){let c=E(i),l=await C(e,{owner:t,repo:n,baseRef:c,targetRef:`refs/heads/${r}`});if(!l)throw Error(`Repository "${t}/${n}" not found`);let u=`commit`in i?i.commit:O(l.baseRef);if(!u)throw Error(`Could not determine sha for base ref "${c}"`);let d=l.targetBranch?.target?.oid??null,f=async(t,n)=>{let r=await w(e,{input:{branch:{id:t},expectedHeadOid:u,message:T(o),fileChanges:s}});if(r.createCommitOnBranch?.ref?.id==null)throw Error(`Failed to create commit on branch "${n}"`);if(r.createCommitOnBranch?.commit?.oid==null)throw Error(`Failed to determine commit sha for commit on branch "${n}"`);return{commitSha:r.createCommitOnBranch.commit.oid}};if(d==null){let i=(await e.rest.git.createRef({owner:t,repo:n,ref:`refs/heads/${r}`,sha:u})).data.node_id;if(!i)throw Error(`Failed to create branch "${r}"`);return await f(i,r),{refId:i}}else if(d===u){let e=l.targetBranch.id;return await f(e,r),{refId:e}}else if(a){let i=`changesets-ghcommit-temp/${r}`;try{let{tempRefId:a}=await k({octokit:e,owner:t,repo:n,tempBranch:i,baseSha:u}),{commitSha:o}=await f(a,i),s=(await e.rest.git.updateRef({owner:t,repo:n,ref:`heads/${r}`,sha:o,force:!0})).data.node_id;if(!s)throw Error(`Failed to force update branch "${r}"`);return{refId:s}}finally{await e.rest.git.deleteRef({owner:t,repo:n,ref:`heads/${i}`})}}else throw Error(`Branch "${r}" exists but its HEAD does not match the base ${u} and \`force\` is set to false`)}function O(e){return e?.target?`target`in e.target?e.target.target.oid:e.target.oid:null}async function k({octokit:e,owner:t,repo:n,tempBranch:r,baseSha:i}){try{let a=(await e.rest.git.createRef({owner:t,repo:n,ref:`refs/heads/${r}`,sha:i})).data.node_id;if(!a)throw Error(`Failed to create temporary branch "${r}"`);return{tempRefId:a}}catch(a){if(!A(a))throw a;let o=(await e.rest.git.updateRef({owner:t,repo:n,ref:`heads/${r}`,sha:i,force:!0})).data.node_id;if(!o)throw Error(`Failed to force update temporary branch "${r}"`);return{tempRefId:o}}}function A(e){return typeof e==`object`&&!!e&&`status`in e&&`message`in e&&typeof e.status==`number`&&typeof e.message==`string`&&e.status===422&&e.message.includes(`Reference already exists`)}async function j({cwd:e,filterFiles:t,...n}){e=v.resolve(e??process.cwd());let r=E(n.base??{commit:`HEAD`}),i=await N(e,r);if(!i)throw Error(`Could not determine sha for ref ${r}`);return await D({...n,fileChanges:await M(e,i,t),base:{commit:i}})}async function M(e,t,n){let r=await P(e),i=[],a=[],o=async e=>{if(n&&!n(e))return;let t=v.join(r,e),a=await _.lstat(t);if(a.isSymbolicLink())throw Error(`Unexpected symlink at ${e}, GitHub API only supports files and directories. You may need to add this file to .gitignore`);if(a.mode&73)throw Error(`Unexpected executable file at ${e}, GitHub API only supports non-executable files and directories. You may need to add this file to .gitignore`);i.push({path:e,contents:await _.readFile(t,`base64`)})},s=e=>{n&&!n(e)||a.push({path:e})},[l,u]=await Promise.all([c(`git`,[`diff`,`--name-status`,`--diff-filter=ACDMRT`,t],{throwOnError:!0,nodeOptions:{cwd:r}}),c(`git`,[`ls-files`,`--others`,`--exclude-standard`],{throwOnError:!0,nodeOptions:{cwd:r}})]);for(let e of l.stdout.trim().split(`
|
|
||||||
`)){if(!e)continue;let[t,...n]=e.split(` `);if(t.startsWith(`R`)||t.startsWith(`C`)){let[e,t]=n;s(e),await o(t);continue}let r=n[0];t===`D`?s(r):await o(r)}for(let e of u.stdout.trim().split(`
|
|
||||||
`))e&&await o(e);return i.sort((e,t)=>e.path>t.path?1:-1),a.sort((e,t)=>e.path>t.path?1:-1),{additions:i,deletions:a}}async function N(e,t){try{let{stdout:n}=await c(`git`,[`rev-parse`,t],{throwOnError:!0,nodeOptions:{cwd:e}});return n.trim()}catch{return null}}async function P(e){try{let{stdout:t}=await c(`git`,[`rev-parse`,`--git-dir`],{throwOnError:!0,nodeOptions:{cwd:e}});return v.dirname(v.resolve(e,t.trim()))}catch{return e}}var F=e(p(),1),I=`0.0.0-development`,L=()=>Promise.resolve();function R(e,t,n){return e.retryLimiter.schedule(z,e,t,n)}async function z(e,t,n){let{pathname:r}=new URL(n.url,`http://github.test`),i=B(n.method,r),a=!i&&n.method!==`GET`&&n.method!==`HEAD`,o=n.method===`GET`&&r.startsWith(`/search/`),s=r.startsWith(`/graphql`),c=~~t.retryCount>0?{priority:0,weight:0}:{};e.clustering&&(c.expiration=1e3*60),(a||s)&&await e.write.key(e.id).schedule(c,L),a&&e.triggersNotification(r)&&await e.notifications.key(e.id).schedule(c,L),o&&await e.search.key(e.id).schedule(c,L);let l=(i?e.auth:e.global).key(e.id).schedule(c,t,n);if(s){let e=await l;if(e.data.errors!=null&&e.data.errors.some(e=>e.type===`RATE_LIMITED`))throw Object.assign(Error(`GraphQL Rate Limit Exceeded`),{response:e,data:e.data})}return l}function B(e,t){return e===`PATCH`&&/^\/applications\/[^/]+\/token\/scoped$/.test(t)||e===`POST`&&(/^\/applications\/[^/]+\/token$/.test(t)||/^\/app\/installations\/[^/]+\/access_tokens$/.test(t)||t===`/login/oauth/access_token`)}var V=[`/orgs/{org}/invitations`,`/orgs/{org}/invitations/{invitation_id}`,`/orgs/{org}/teams/{team_slug}/discussions`,`/orgs/{org}/teams/{team_slug}/discussions/{discussion_number}/comments`,`/repos/{owner}/{repo}/collaborators/{username}`,`/repos/{owner}/{repo}/commits/{commit_sha}/comments`,`/repos/{owner}/{repo}/issues`,`/repos/{owner}/{repo}/issues/{issue_number}/comments`,`/repos/{owner}/{repo}/issues/{issue_number}/sub_issue`,`/repos/{owner}/{repo}/issues/{issue_number}/sub_issues/priority`,`/repos/{owner}/{repo}/pulls`,`/repos/{owner}/{repo}/pulls/{pull_number}/comments`,`/repos/{owner}/{repo}/pulls/{pull_number}/comments/{comment_id}/replies`,`/repos/{owner}/{repo}/pulls/{pull_number}/merge`,`/repos/{owner}/{repo}/pulls/{pull_number}/requested_reviewers`,`/repos/{owner}/{repo}/pulls/{pull_number}/reviews`,`/repos/{owner}/{repo}/releases`,`/teams/{team_id}/discussions`,`/teams/{team_id}/discussions/{discussion_number}/comments`];function H(e){let t=`^(?:${e.map(e=>e.split(`/`).map(e=>e.startsWith(`{`)?`(?:.+?)`:e).join(`/`)).map(e=>`(?:${e})`).join(`|`)})[^/]*$`;return new RegExp(t,`i`)}var U=H(V),W=U.test.bind(U),G={},K=function(e,t){G.global=new e.Group({id:`octokit-global`,maxConcurrent:10,...t}),G.auth=new e.Group({id:`octokit-auth`,maxConcurrent:1,...t}),G.search=new e.Group({id:`octokit-search`,maxConcurrent:1,minTime:2e3,...t}),G.write=new e.Group({id:`octokit-write`,maxConcurrent:1,minTime:1e3,...t}),G.notifications=new e.Group({id:`octokit-notifications`,maxConcurrent:1,minTime:3e3,...t})};function q(e,t){let{enabled:n=!0,Bottleneck:r=F.default,id:i=`no-id`,timeout:a=1e3*60*2,connection:o}=t.throttle||{};if(!n)return{};let s={timeout:a};o!==void 0&&(s.connection=o),G.global??K(r,s);let c=Object.assign({clustering:o!=null,triggersNotification:W,fallbackSecondaryRateRetryAfter:60,retryAfterBaseValue:1e3,retryLimiter:new r,id:i,...G},t.throttle);if(typeof c.onSecondaryRateLimit!=`function`||typeof c.onRateLimit!=`function`)throw Error(`octokit/plugin-throttling error:
|
|
||||||
You must pass the onSecondaryRateLimit and onRateLimit error handlers.
|
|
||||||
See https://octokit.github.io/rest.js/#throttling
|
|
||||||
|
|
||||||
const octokit = new Octokit({
|
|
||||||
throttle: {
|
|
||||||
onSecondaryRateLimit: (retryAfter, options) => {/* ... */},
|
|
||||||
onRateLimit: (retryAfter, options) => {/* ... */}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
`);let l={},u=new r.Events(l);return l.on(`secondary-limit`,c.onSecondaryRateLimit),l.on(`rate-limit`,c.onRateLimit),l.on(`error`,t=>e.log.warn(`Error in throttling-plugin limit handler`,t)),c.retryLimiter.on(`failed`,async function(t,n){let[r,i,a]=n.args,{pathname:o}=new URL(a.url,`http://github.test`);if(!(o.startsWith(`/graphql`)&&t.status!==401||t.status===403||t.status===429))return;let s=~~i.retryCount;i.retryCount=s,a.request.retryCount=s;let{wantRetry:c,retryAfter:l=0}=await(async function(){if(/\bsecondary rate\b/i.test(t.message)){let n=Number(t.response.headers[`retry-after`])||r.fallbackSecondaryRateRetryAfter;return{wantRetry:await u.trigger(`secondary-limit`,n,a,e,s),retryAfter:n}}if(t.response.headers!=null&&t.response.headers[`x-ratelimit-remaining`]===`0`||(t.response.data?.errors??[]).some(e=>e.type===`RATE_LIMITED`)){let n=new Date(~~t.response.headers[`x-ratelimit-reset`]*1e3).getTime(),r=Math.max(Math.ceil((n-Date.now())/1e3)+1,0);return{wantRetry:await u.trigger(`rate-limit`,r,a,e,s),retryAfter:r}}return{}})();if(c)return i.retryCount++,l*r.retryAfterBaseValue}),e.hook.wrap(`request`,R.bind(null,c)),{}}q.VERSION=I,q.triggersNotification=W;const J=e=>n(e,{throttle:{onRateLimit:(e,t,n,a)=>{if(i(`Request quota exhausted for request ${t.method} ${t.url}`),a<=2)return r(`Retrying after ${e} seconds!`),!0},onSecondaryRateLimit:(e,t,n,a)=>{if(i(`SecondaryRateLimit detected for request ${t.method} ${t.url}`),a<=2)return r(`Retrying after ${e} seconds!`),!0}}},q),Y=async(e,n)=>{await t(`git`,[`push`,`origin`,`HEAD:${e}`,`--force`],n)},X=async(e,n)=>{let{stderr:r}=await s(`git`,[`checkout`,e],{ignoreReturnCode:!0,...n});r.toString().includes(`Switched to a new branch '${e}'`)||await t(`git`,[`checkout`,`-b`,e],n)},Z=async(e,n)=>{await t(`git`,[`reset`,`--hard`,e],n)},Q=async(e,n)=>{await t(`git`,[`add`,`.`],n),await t(`git`,[`commit`,`-m`,e],n)},te=async e=>{let{stdout:t}=await s(`git`,[`status`,`--porcelain`],e);return!t.length};var ne=class{#e;octokit;cwd;commitMode;constructor(e){this.#e=e.githubToken,this.cwd=e.cwd,this.commitMode=e.commitMode??`git-cli`,this.octokit=J(e.githubToken)}getToken(){return this.#e}#t(){let e=y.from(`x-access-token:${this.#e}`).toString(`base64`),t=(a.serverUrl??process.env.GITHUB_SERVER_URL??`https://github.com`).replace(/\/+$/,``),n=Number(process.env.GIT_CONFIG_COUNT??0);if(!Number.isInteger(n)||n<0)throw Error(`Invalid GIT_CONFIG_COUNT value: ${process.env.GIT_CONFIG_COUNT}`);return{GIT_CONFIG_COUNT:String(n+1),[`GIT_CONFIG_KEY_${n}`]:`http.${t}/.extraheader`,[`GIT_CONFIG_VALUE_${n}`]:`AUTHORIZATION: basic ${e}`}}async setupUser(){this.commitMode!==`github-api`&&(await t(`git`,[`config`,`user.name`,`"github-actions[bot]"`],{cwd:this.cwd}),await t(`git`,[`config`,`user.email`,`"41898282+github-actions[bot]@users.noreply.github.com"`],{cwd:this.cwd}))}async pushTag(e){if(this.commitMode===`github-api`)return this.octokit.rest.git.createRef({...a.repo,ref:`refs/tags/${e}`,sha:a.sha}).catch(t=>{i(`Failed to create tag ${e}: ${t.message}`)});await t(`git`,[`push`,`origin`,e],{cwd:this.cwd,env:{...process.env,...this.#t()}})}async prepareBranch(e){this.commitMode!==`github-api`&&(await X(e,{cwd:this.cwd}),await Z(a.sha,{cwd:this.cwd}))}async pushChanges({branch:e,message:t}){if(this.commitMode===`github-api`){await j({octokit:this.octokit,...a.repo,branch:e,message:t,base:{commit:a.sha},cwd:this.cwd});return}await te({cwd:this.cwd})||await Q(t,{cwd:this.cwd}),await Y(e,{cwd:this.cwd,env:{...process.env,...this.#t()}})}};const re=async(e,{pkg:t,tagName:n})=>{let r;try{r=await _.readFile(x.join(t.dir,`CHANGELOG.md`),`utf8`)}catch(e){if(g(e,`ENOENT`))return;throw e}let i=l(r,t.packageJson.version);if(!i)throw Error(`Could not find changelog entry for ${t.packageJson.name}@${t.packageJson.version}`);await e.rest.repos.createRelease({name:n,tag_name:n,body:i.content,prerelease:t.packageJson.version.includes(`-`),...a.repo})};function $(e){return typeof e==`object`&&!!e}function ie(e){return $(e)&&`type`in e&&e.type===`git-tag`&&`tag`in e&&typeof e.tag==`string`&&`packageName`in e&&typeof e.packageName==`string`}async function ae(e){let t;try{t=await _.readFile(e,`utf8`)}catch(t){throw Error(`Failed to read changesets output at ${e}`,{cause:t})}let n=[],r=0;for(;r<=t.length;){let e=t.indexOf(`
|
|
||||||
`,r);e===-1&&(e=t.length);let i=t.slice(r,e);if(r=e+1,/^\s*$/.test(i))continue;let a;try{a=JSON.parse(i)}catch(e){throw Error(`Failed to parse changesets output event: ${i}`,{cause:e})}ie(a)&&n.push(a)}return n}async function oe({script:e,fromPackDir:t,github:n,createGithubReleases:r,pushGitTags:i,cwd:a}){let{octokit:c}=n,l,u=x.join(process.env.RUNNER_TEMP??await _.realpath(S.tmpdir()),`changesets-output-${b()}.ndjson`),d={cwd:a,ignoreReturnCode:!0,env:{...process.env,GITHUB_TOKEN:n.getToken(),CHANGESETS_OUTPUT:u}};if(e)l=await s(e,void 0,d);else{let e=[`publish`];t&&e.push(`--from-pack-dir`,t),l=await h(e,d)}let{packages:f,tool:p}=await o(a),m=new Map(f.map(e=>[e.packageJson.name,e])),g=(await ae(u)).map(e=>{let t=m.get(e.packageName);if(t===void 0)throw Error(`Package "${e.packageName}" not found.This is probably a bug in the action, please open an issue`);return{pkg:t,tag:e.tag}});if(p.type===`root`&&f.length===0)throw Error(`No package found.This is probably a bug in the action, please open an issue`);return(r||i)&&await Promise.all(g.map(async({pkg:e,tag:t})=>{i&&await n.pushTag(t),r&&await re(c,{pkg:e,tagName:t})})),g.length?{published:!0,publishedPackages:g.map(({pkg:e})=>({name:e.packageJson.name,version:e.packageJson.version})),exitCode:l.exitCode}:{published:!1,exitCode:l.exitCode}}async function se({hasPublishScript:e,preState:t,changedPackagesInfo:n,prBodyMaxCharacters:r,branch:i}){let a=`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 ${e?`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 ${i}, this PR will be updated.
|
|
||||||
`,o=t?`⚠️⚠️⚠️⚠️⚠️⚠️
|
|
||||||
|
|
||||||
\`${i}\` 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 \`${i}\`.
|
|
||||||
|
|
||||||
⚠️⚠️⚠️⚠️⚠️⚠️
|
|
||||||
`:``,s=`# Releases`,c=[a,o,s,...n.map(e=>`${e.header}\n\n${e.content}`)].join(`
|
|
||||||
`);return c.length>r&&(c=[a,o,s,`
|
|
||||||
> The changelog information of each package has been omitted from this message, as the content exceeds the size limit.
|
|
||||||
`,...n.map(e=>`${e.header}\n\n`)].join(`
|
|
||||||
`)),c.length>r&&(c=[a,o,s,`
|
|
||||||
> All release information have been omitted from this message, as the content exceeds the size limit.`].join(`
|
|
||||||
`)),c}async function ce({script:e,github:n,cwd:i=process.cwd(),prTitle:o=`Version Packages`,commitMessage:s=`Version Packages`,hasPublishScript:c=!1,prBodyMaxCharacters:p=6e4,branch:h=a.ref.replace(`refs/heads/`,``),prDraft:g}){let{octokit:v}=n,y=`changeset-release/${h}`,{preState:b}=await ee(i);await n.prepareBranch(y);let S=await f(i),C={...process.env,GITHUB_TOKEN:n.getToken()};e?await t(e,void 0,{cwd:i,env:C}):await m([`version`],{cwd:i,env:C});let w=await d(i,S),T=Promise.all(w.map(async e=>{let t=l(await _.readFile(x.join(e.dir,`CHANGELOG.md`),`utf8`),e.packageJson.version);return{highestLevel:t.highestLevel,private:!!e.packageJson.private,content:t.content,header:`## ${e.packageJson.name}@${e.packageJson.version}`}})),E=`${o}${b?` (${b.tag})`:``}`,D=`${s}${b?` (${b.tag})`:``}`,O=await v.rest.pulls.list({...a.repo,state:`open`,head:`${a.repo.owner}:${y}`,base:h});r(`Existing pull requests: ${JSON.stringify(O.data,null,2)}`),await n.pushChanges({branch:y,message:D});let k=await se({hasPublishScript:c,preState:b,branch:h,changedPackagesInfo:(await T).filter(e=>e).sort(u),prBodyMaxCharacters:p});if(O.data.length===0){r(`creating pull request`);let{data:e}=await v.rest.pulls.create({base:h,head:y,title:E,body:k,draft:g!==void 0,...a.repo});return{pullRequestNumber:e.number}}else{let[e]=O.data;r(`updating found pull request #${e.number}`);let t=`
|
|
||||||
mutation UpdatePullRequest(
|
|
||||||
$pullRequestId: ID!
|
|
||||||
$title: String!
|
|
||||||
$body: String!
|
|
||||||
) {
|
|
||||||
${g===`always`?`
|
|
||||||
convertPullRequestToDraft(
|
|
||||||
input: {
|
|
||||||
pullRequestId: $pullRequestId
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
pullRequest {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}`:``}
|
|
||||||
|
|
||||||
updatePullRequest(
|
|
||||||
input: {
|
|
||||||
pullRequestId: $pullRequestId
|
|
||||||
title: $title
|
|
||||||
body: $body
|
|
||||||
state: OPEN
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
pullRequest {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;return await v.graphql(t,{pullRequestId:e.node_id,title:E,body:k}),{pullRequestNumber:e.number}}}export{ce as n,ne as r,oe as t};
|
|
||||||
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
import{m as e,p as t}from"./manypkg-get-packages-BoFCbqAx.js";import{n,p as r}from"./utils-DxGVktYo.js";import{t as i}from"./readChangesetState-wtnwjhXS.js";import a from"node:fs/promises";import o from"node:path";import s from"node:os";try{await c()}catch(e){t(e.message)}async function c(){let t=await l();if(e(`mode`,t.mode),t.mode===`publish`){let n=await r.uploadArtifact(o.basename(t.publishPlanPath,`.json`),[t.publishPlanPath],o.dirname(t.publishPlanPath),{skipArchive:!0,retentionDays:30});if(n.id===void 0)throw Error(`Publish plan artifact upload did not return an artifact id`);e(`publish-plan-artifact-id`,String(n.id))}}async function l(){let{changesets:e}=await i();if(e.length>0)return e.some(e=>e.releases.length>0)?{mode:`version`}:{mode:`none`};let t=process.cwd(),r=o.join(process.env.RUNNER_TEMP??await a.realpath(s.tmpdir()),`changeset-publish-plan-${Date.now()}`,`publish-plan.json`);return await n([`publish-plan`,`--output`,r],{cwd:t,env:process.env}),(await u(r)).length===0?{mode:`none`}:{mode:`publish`,publishPlanPath:r}}async function u(e){let t;try{t=await a.readFile(e,`utf8`)}catch(t){throw Error(`Failed to read publish plan at ${e}`,{cause:t})}let n;try{n=JSON.parse(t)}catch(t){throw Error(`Failed to parse publish plan at ${e}`,{cause:t})}if(typeof n!=`object`||!n||!(`version`in n)||typeof n.version!=`number`||!(`plan`in n)||!Array.isArray(n.plan))throw Error(`Invalid publish plan at ${e}: expected { version: number; plan: unknown[] }`);return n.plan}export{};
|
|
||||||
Vendored
-82
File diff suppressed because one or more lines are too long
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
import{f as e,m as t,p as n,u as r}from"./manypkg-get-packages-BoFCbqAx.js";import{n as i,r as a}from"./run-Bw2IS-rI.js";import{c as o,s}from"./utils-DxGVktYo.js";try{await c()}catch(e){n(e.message)}async function c(){let n=o(`github-token`),c=s(`script`),l=o(`commit-message`),u=o(`pr-title`),d=s(`pr-draft`),f=s(`pr-base-branch`),p=s(`commit-mode`)??`git-cli`,m=r(`setup-git-user`);if(d!==void 0&&d!==`always`&&d!==`create`)throw Error(`Invalid pr-draft input: ${d}`);if(p!==`git-cli`&&p!==`github-api`)throw Error(`Invalid commit-mode input: ${p}`);let h=process.cwd(),g=new a({cwd:h,githubToken:n,commitMode:p});m&&(e(`setting git user`),await g.setupUser());let{pullRequestNumber:_}=await i({script:c,github:g,cwd:h,prTitle:u,commitMessage:l,hasPublishScript:!0,prDraft:d,branch:f});t(`pr-number`,String(_))}export{};
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
# changesets/action/pack
|
|
||||||
|
|
||||||
TODO
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
name: Changesets - Pack
|
|
||||||
description: Pack publishable packages into tarballs
|
|
||||||
runs:
|
|
||||||
using: node24
|
|
||||||
main: ../dist/pack.js
|
|
||||||
inputs:
|
|
||||||
publish-plan-artifact-id:
|
|
||||||
description: "Artifact id for a publish plan generated by the select-mode subaction"
|
|
||||||
required: false
|
|
||||||
outputs:
|
|
||||||
pack-dir-artifact-id:
|
|
||||||
description: "Artifact id for the packed output directory"
|
|
||||||
branding:
|
|
||||||
icon: package
|
|
||||||
color: blue
|
|
||||||
+13
-15
@@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@changesets/action",
|
"name": "@changesets/action",
|
||||||
"version": "2.0.0-next.3",
|
"version": "1.9.0",
|
||||||
"private": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@@ -18,28 +17,27 @@
|
|||||||
"release:pr": "node --experimental-strip-types ./scripts/release-pr.ts"
|
"release:pr": "node --experimental-strip-types ./scripts/release-pr.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/artifact": "^6.2.1",
|
|
||||||
"@actions/core": "^3.0.1",
|
"@actions/core": "^3.0.1",
|
||||||
"@actions/exec": "^3.0.0",
|
"@actions/exec": "^3.0.0",
|
||||||
"@actions/github": "^9.1.1",
|
"@actions/github": "^9.1.1",
|
||||||
"@changesets/get-release-plan": "^5.0.0-next.7",
|
"@changesets/get-release-plan": "^4.0.16",
|
||||||
"@changesets/ghcommit": "^3.0.0-next.1",
|
"@changesets/ghcommit": "^2.1.1",
|
||||||
"@changesets/git": "^4.0.0-next.6",
|
"@changesets/git": "^3.0.4",
|
||||||
"@changesets/pre": "^3.0.0-next.6",
|
"@changesets/pre": "^2.0.2",
|
||||||
"@changesets/read": "^1.0.0-next.7",
|
"@changesets/read": "^0.6.7",
|
||||||
"@manypkg/get-packages": "^3.1.0",
|
"@manypkg/get-packages": "^1.1.3",
|
||||||
"@octokit/core": "^7.0.6",
|
"@octokit/core": "^7.0.6",
|
||||||
"@octokit/plugin-throttling": "^11.0.3",
|
"@octokit/plugin-throttling": "^11.0.3",
|
||||||
"human-id": "^4.1.3",
|
"human-id": "^4.1.3",
|
||||||
"markdown-table": "^3.0.4",
|
"markdown-table": "^3.0.4",
|
||||||
"semver": "^7.8.1",
|
"semver": "^7.8.0",
|
||||||
"tinyexec": "^1.2.4"
|
"tinyexec": "^1.1.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@changesets/changelog-github": "^1.0.0-next.6",
|
"@changesets/changelog-github": "^0.7.0",
|
||||||
"@changesets/cli": "^3.0.0-next.8",
|
"@changesets/cli": "^2.31.0",
|
||||||
"@changesets/types": "^7.0.0-next.6",
|
"@changesets/types": "^6.1.0",
|
||||||
"@changesets/write": "^1.0.0-next.6",
|
"@changesets/write": "^0.4.0",
|
||||||
"@tsconfig/node24": "^24.0.4",
|
"@tsconfig/node24": "^24.0.4",
|
||||||
"@types/node": "^24.12.4",
|
"@types/node": "^24.12.4",
|
||||||
"@types/semver": "^7.7.1",
|
"@types/semver": "^7.7.1",
|
||||||
|
|||||||
Generated
+952
-1131
File diff suppressed because it is too large
Load Diff
+1
-17
@@ -3,23 +3,7 @@ dedupePeers: true
|
|||||||
dedupePeerDependents: true
|
dedupePeerDependents: true
|
||||||
minimumReleaseAge: 10080
|
minimumReleaseAge: 10080
|
||||||
minimumReleaseAgeExclude:
|
minimumReleaseAgeExclude:
|
||||||
- "@changesets/apply-release-plan@8.0.0-next.7"
|
- "@changesets/ghcommit@2.1.1"
|
||||||
- "@changesets/assemble-release-plan@7.0.0-next.7"
|
|
||||||
- "@changesets/changelog-git@1.0.0-next.6"
|
|
||||||
- "@changesets/changelog-github@1.0.0-next.6"
|
|
||||||
- "@changesets/cli@3.0.0-next.8"
|
|
||||||
- "@changesets/config@4.0.0-next.6"
|
|
||||||
- "@changesets/get-dependents-graph@3.0.0-next.6"
|
|
||||||
- "@changesets/get-github-info@1.0.0-next.3"
|
|
||||||
- "@changesets/get-release-plan@5.0.0-next.7"
|
|
||||||
- "@changesets/ghcommit@3.0.0-next.1"
|
|
||||||
- "@changesets/git@4.0.0-next.6"
|
|
||||||
- "@changesets/parse@1.0.0-next.7"
|
|
||||||
- "@changesets/pre@3.0.0-next.6"
|
|
||||||
- "@changesets/read@1.0.0-next.7"
|
|
||||||
- "@changesets/should-skip-package@1.0.0-next.6"
|
|
||||||
- "@changesets/types@7.0.0-next.6"
|
|
||||||
- "@changesets/write@1.0.0-next.6"
|
|
||||||
|
|
||||||
overrides:
|
overrides:
|
||||||
lightningcss: "-" # we do not bundle any css
|
lightningcss: "-" # we do not bundle any css
|
||||||
|
|||||||
+5
-15
@@ -2,18 +2,7 @@
|
|||||||
|
|
||||||
This action generates the changesets status in PRs, e.g. whether it has changeset files and which packages will be released if the PR is merged.
|
This action generates the changesets status in PRs, e.g. whether it has changeset files and which packages will be released if the PR is merged.
|
||||||
|
|
||||||
It requires the repo to be checked out, and automatically fetches the PR head ref into a temporary detached worktree in order to infer the changed files and packages.
|
It requires the repo to be checked out, and automatically fetches the PR head ref into a temporary detached worktree in order to infer the changed files and packages. It also requires the [`pull_request_target`](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request_target) event to be triggered in order to have permissions to comment on the PR and to work in PRs from forks.
|
||||||
|
|
||||||
See the [action metadata](action.yml) for details on the inputs and outputs.
|
|
||||||
|
|
||||||
> [!CAUTION]
|
|
||||||
> **This action uses `pull_request_target` by default to support PRs from forks.**
|
|
||||||
>
|
|
||||||
> **Do not run untrusted code** when using the `pull_request_target` event.
|
|
||||||
>
|
|
||||||
> The example below only **_checks out_** and **_reads_** code, and does not **_execute_** any code from the fork.
|
|
||||||
>
|
|
||||||
> Read more about the `pull_request_target` event in the [GitHub documentation](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request_target).
|
|
||||||
|
|
||||||
You can also use the [`pull_request`](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request) event if you prefer to lock permissions down and not run for PRs from forks. Make sure to add an if check to prevent the action from failing in fork PRs:
|
You can also use the [`pull_request`](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request) event if you prefer to lock permissions down and not run for PRs from forks. Make sure to add an if check to prevent the action from failing in fork PRs:
|
||||||
|
|
||||||
@@ -24,7 +13,10 @@ jobs:
|
|||||||
# ...
|
# ...
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also use the [Changesets Bot](https://github.com/apps/changeset-bot) if you don't want an extra action in your repo, or are worried about the `pull_request_target` event.
|
See the [action metadata](action.yml) for details on the inputs and outputs.
|
||||||
|
|
||||||
|
> [!WARNING]
|
||||||
|
> **Do not run untrusted code** when using the `pull_request_target` event. The example below only checks out code and does not run any code from the PR. Read more about the `pull_request_target` event in the [GitHub documentation](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request_target).
|
||||||
|
|
||||||
## Example setup
|
## Example setup
|
||||||
|
|
||||||
@@ -35,8 +27,6 @@ name: Comment Changesets status in PRs
|
|||||||
on:
|
on:
|
||||||
pull_request_target:
|
pull_request_target:
|
||||||
|
|
||||||
permissions: {} # require explicitly stating all permissions in each job
|
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
# changesets/action/publish
|
|
||||||
|
|
||||||
TODO
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
name: Changesets - Publish
|
|
||||||
description: Publish packages to npm
|
|
||||||
runs:
|
|
||||||
using: node24
|
|
||||||
main: ../dist/publish.js
|
|
||||||
inputs:
|
|
||||||
github-token:
|
|
||||||
description: "The GitHub token to use for authentication. Defaults to the GitHub-provided token."
|
|
||||||
required: false
|
|
||||||
default: ${{ github.token }}
|
|
||||||
script:
|
|
||||||
description: "The command to use to publish packages"
|
|
||||||
required: false
|
|
||||||
pack-dir-artifact-id:
|
|
||||||
description: "Artifact id for packed publish output generated by the pack subaction"
|
|
||||||
required: false
|
|
||||||
create-github-releases:
|
|
||||||
description: "Whether to create Github releases after publish"
|
|
||||||
required: false
|
|
||||||
default: true
|
|
||||||
push-git-tags:
|
|
||||||
description: >
|
|
||||||
Whether to create git tags after publish. If `create-github-releases` is set to `true`,
|
|
||||||
this option will also always be `true`.
|
|
||||||
required: false
|
|
||||||
default: true
|
|
||||||
outputs:
|
|
||||||
published:
|
|
||||||
description: "A boolean value to indicate whether a publishing has happened or not"
|
|
||||||
published-packages:
|
|
||||||
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:
|
|
||||||
icon: package
|
|
||||||
color: blue
|
|
||||||
+2
-6
@@ -3,12 +3,8 @@ import { defineConfig } from "rolldown";
|
|||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
input: {
|
input: {
|
||||||
index: "src/index.ts",
|
index: "src/index.ts",
|
||||||
pack: "src/pack/index.ts",
|
["pr-status"]: "src/pr-status/index.ts",
|
||||||
"pr-status": "src/pr-status/index.ts",
|
["pr-comment"]: "src/pr-comment/index.ts",
|
||||||
"pr-comment": "src/pr-comment/index.ts",
|
|
||||||
"select-mode": "src/select-mode/index.ts",
|
|
||||||
version: "src/version/index.ts",
|
|
||||||
publish: "src/publish/index.ts",
|
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
dir: "dist",
|
dir: "dist",
|
||||||
|
|||||||
+1
-3
@@ -1,14 +1,12 @@
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { exec } from "@actions/exec";
|
import { exec } from "@actions/exec";
|
||||||
|
import pkgJson from "../package.json" with { type: "json" };
|
||||||
|
|
||||||
process.chdir(path.join(import.meta.dirname, ".."));
|
process.chdir(path.join(import.meta.dirname, ".."));
|
||||||
|
|
||||||
await exec("changeset", ["version"]);
|
await exec("changeset", ["version"]);
|
||||||
|
|
||||||
// read after versioning to get the new version
|
|
||||||
const pkgJson = (await import("../package.json", { with: { type: "json" } }))
|
|
||||||
.default;
|
|
||||||
const releaseLine = `v${pkgJson.version.split(".")[0]}`;
|
const releaseLine = `v${pkgJson.version.split(".")[0]}`;
|
||||||
|
|
||||||
const readmePath = path.join(import.meta.dirname, "..", "README.md");
|
const readmePath = path.join(import.meta.dirname, "..", "README.md");
|
||||||
|
|||||||
+6
-19
@@ -1,21 +1,9 @@
|
|||||||
import { Buffer } from "node:buffer";
|
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { exec } from "@actions/exec";
|
import { exec } from "@actions/exec";
|
||||||
import pkgJson from "../package.json" with { type: "json" };
|
import pkgJson from "../package.json" with { type: "json" };
|
||||||
|
|
||||||
const tag = `v${pkgJson.version}`;
|
const tag = `v${pkgJson.version}`;
|
||||||
const releaseLine = "pr-release";
|
const releaseLine = "pr-release";
|
||||||
const githubToken = process.env.GITHUB_TOKEN;
|
|
||||||
if (!githubToken) {
|
|
||||||
throw new Error("GITHUB_TOKEN is required");
|
|
||||||
}
|
|
||||||
const basic = Buffer.from(`x-access-token:${githubToken}`).toString("base64");
|
|
||||||
const gitEnv = {
|
|
||||||
...process.env,
|
|
||||||
GIT_CONFIG_COUNT: "1",
|
|
||||||
GIT_CONFIG_KEY_0: "http.https://github.com/.extraheader",
|
|
||||||
GIT_CONFIG_VALUE_0: `AUTHORIZATION: basic ${basic}`,
|
|
||||||
};
|
|
||||||
|
|
||||||
process.chdir(path.join(import.meta.dirname, ".."));
|
process.chdir(path.join(import.meta.dirname, ".."));
|
||||||
|
|
||||||
@@ -23,10 +11,9 @@ await exec("git", ["checkout", "--detach"]);
|
|||||||
await exec("git", ["add", "--force", "dist"]);
|
await exec("git", ["add", "--force", "dist"]);
|
||||||
await exec("git", ["commit", "-m", tag]);
|
await exec("git", ["commit", "-m", tag]);
|
||||||
|
|
||||||
await exec(
|
await exec("git", [
|
||||||
"git",
|
"push",
|
||||||
["push", "--force", "origin", `HEAD:refs/heads/${releaseLine}`],
|
"--force",
|
||||||
{
|
"origin",
|
||||||
env: gitEnv,
|
`HEAD:refs/heads/${releaseLine}`,
|
||||||
},
|
]);
|
||||||
);
|
|
||||||
|
|||||||
+30
-36
@@ -1,47 +1,41 @@
|
|||||||
import { Buffer } from "node:buffer";
|
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { exec } from "@actions/exec";
|
import { exec, getExecOutput } from "@actions/exec";
|
||||||
import pkgJson from "../package.json" with { type: "json" };
|
import pkgJson from "../package.json" with { type: "json" };
|
||||||
|
|
||||||
const tag = `v${pkgJson.version}`;
|
const tag = `v${pkgJson.version}`;
|
||||||
const releaseLine = `v${pkgJson.version.split(".")[0]}`;
|
const releaseLine = `v${pkgJson.version.split(".")[0]}`;
|
||||||
const isPrerelease = pkgJson.version.includes("-");
|
|
||||||
const githubToken = process.env.GITHUB_TOKEN;
|
|
||||||
if (!githubToken) {
|
|
||||||
throw new Error("GITHUB_TOKEN is required");
|
|
||||||
}
|
|
||||||
const basic = Buffer.from(`x-access-token:${githubToken}`).toString("base64");
|
|
||||||
const gitEnv = {
|
|
||||||
...process.env,
|
|
||||||
GIT_CONFIG_COUNT: "1",
|
|
||||||
GIT_CONFIG_KEY_0: "http.https://github.com/.extraheader",
|
|
||||||
GIT_CONFIG_VALUE_0: `AUTHORIZATION: basic ${basic}`,
|
|
||||||
};
|
|
||||||
|
|
||||||
process.chdir(path.join(import.meta.dirname, ".."));
|
process.chdir(path.join(import.meta.dirname, ".."));
|
||||||
|
|
||||||
await exec("git", ["checkout", "--detach"]);
|
(async () => {
|
||||||
await exec("git", ["add", "--force", "dist"]);
|
const { exitCode, stderr } = await getExecOutput(
|
||||||
await exec("git", ["commit", "-m", tag]);
|
`git`,
|
||||||
|
["ls-remote", "--exit-code", "origin", "--tags", `refs/tags/${tag}`],
|
||||||
await exec("changeset", ["git-tag"]);
|
|
||||||
|
|
||||||
if (isPrerelease) {
|
|
||||||
await exec("git", ["push", "origin", `refs/tags/${tag}`], {
|
|
||||||
env: gitEnv,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
await exec(
|
|
||||||
"git",
|
|
||||||
[
|
|
||||||
"push",
|
|
||||||
"--force",
|
|
||||||
"--follow-tags",
|
|
||||||
"origin",
|
|
||||||
`HEAD:refs/heads/${releaseLine}`,
|
|
||||||
],
|
|
||||||
{
|
{
|
||||||
env: gitEnv,
|
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,3 +0,0 @@
|
|||||||
# changesets/action/select-mode
|
|
||||||
|
|
||||||
TODO
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
name: Changesets - Select Mode
|
|
||||||
description: Whether to version or publish in the current repo state
|
|
||||||
runs:
|
|
||||||
using: node24
|
|
||||||
main: ../dist/select-mode.js
|
|
||||||
inputs: {}
|
|
||||||
outputs:
|
|
||||||
mode:
|
|
||||||
description: "The mode to use for the current repo state: 'version', 'publish', or 'none'."
|
|
||||||
publish-plan-artifact-id:
|
|
||||||
description: "Artifact id for the generated publish plan when mode is `publish`"
|
|
||||||
branding:
|
|
||||||
icon: package
|
|
||||||
color: blue
|
|
||||||
+28
-71
@@ -1,15 +1,11 @@
|
|||||||
import { Buffer } from "node:buffer";
|
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import { exec, getExecOutput } from "@actions/exec";
|
import { exec, getExecOutput } from "@actions/exec";
|
||||||
import { context } from "@actions/github";
|
import * as github from "@actions/github";
|
||||||
import { commitChangesSinceBase } from "@changesets/ghcommit";
|
import { commitChangesFromRepo } from "@changesets/ghcommit/git";
|
||||||
import { setupOctokit, type Octokit } from "./octokit.ts";
|
import type { Octokit } from "./octokit.ts";
|
||||||
|
|
||||||
export type CommitMode = "git-cli" | "github-api";
|
|
||||||
|
|
||||||
type GitOptions = {
|
type GitOptions = {
|
||||||
cwd: string;
|
cwd: string;
|
||||||
env?: Record<string, string>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const push = async (branch: string, options: GitOptions) => {
|
const push = async (branch: string, options: GitOptions) => {
|
||||||
@@ -50,51 +46,17 @@ const checkIfClean = async (options: GitOptions): Promise<boolean> => {
|
|||||||
return !stdout.length;
|
return !stdout.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class GitHub {
|
export class Git {
|
||||||
readonly #githubToken: string;
|
readonly octokit: Octokit | null;
|
||||||
readonly octokit: Octokit;
|
|
||||||
readonly cwd: string;
|
readonly cwd: string;
|
||||||
readonly commitMode: CommitMode;
|
|
||||||
|
|
||||||
constructor(options: {
|
constructor(args: { octokit?: Octokit; cwd: string }) {
|
||||||
githubToken: string;
|
this.octokit = args.octokit ?? null;
|
||||||
cwd: string;
|
this.cwd = args.cwd;
|
||||||
commitMode?: CommitMode;
|
|
||||||
}) {
|
|
||||||
this.#githubToken = options.githubToken;
|
|
||||||
this.cwd = options.cwd;
|
|
||||||
this.commitMode = options.commitMode ?? "git-cli";
|
|
||||||
this.octokit = setupOctokit(options.githubToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
getToken() {
|
|
||||||
return this.#githubToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
#getCliAuthEnv(): Record<string, string> {
|
|
||||||
const basic = Buffer.from(`x-access-token:${this.#githubToken}`).toString(
|
|
||||||
"base64",
|
|
||||||
);
|
|
||||||
const serverUrl = (
|
|
||||||
context.serverUrl ??
|
|
||||||
process.env.GITHUB_SERVER_URL ??
|
|
||||||
"https://github.com"
|
|
||||||
).replace(/\/+$/, "");
|
|
||||||
const gitConfigCount = Number(process.env.GIT_CONFIG_COUNT ?? 0);
|
|
||||||
if (!Number.isInteger(gitConfigCount) || gitConfigCount < 0) {
|
|
||||||
throw new Error(
|
|
||||||
`Invalid GIT_CONFIG_COUNT value: ${process.env.GIT_CONFIG_COUNT}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
GIT_CONFIG_COUNT: String(gitConfigCount + 1),
|
|
||||||
[`GIT_CONFIG_KEY_${gitConfigCount}`]: `http.${serverUrl}/.extraheader`,
|
|
||||||
[`GIT_CONFIG_VALUE_${gitConfigCount}`]: `AUTHORIZATION: basic ${basic}`,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async setupUser() {
|
async setupUser() {
|
||||||
if (this.commitMode === "github-api") {
|
if (this.octokit) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await exec("git", ["config", "user.name", `"github-actions[bot]"`], {
|
await exec("git", ["config", "user.name", `"github-actions[bot]"`], {
|
||||||
@@ -114,59 +76,54 @@ export class GitHub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async pushTag(tag: string) {
|
async pushTag(tag: string) {
|
||||||
if (this.commitMode === "github-api") {
|
if (this.octokit) {
|
||||||
return this.octokit.rest.git
|
return this.octokit.rest.git
|
||||||
.createRef({
|
.createRef({
|
||||||
...context.repo,
|
...github.context.repo,
|
||||||
ref: `refs/tags/${tag}`,
|
ref: `refs/tags/${tag}`,
|
||||||
sha: context.sha,
|
sha: github.context.sha,
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
// Assuming tag was manually pushed in custom publish script
|
// Assuming tag was manually pushed in custom publish script
|
||||||
core.warning(`Failed to create tag ${tag}: ${err.message}`);
|
core.warning(`Failed to create tag ${tag}: ${err.message}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
await exec("git", ["push", "origin", tag], {
|
await exec("git", ["push", "origin", tag], { cwd: this.cwd });
|
||||||
cwd: this.cwd,
|
|
||||||
env: {
|
|
||||||
...process.env,
|
|
||||||
...this.#getCliAuthEnv(),
|
|
||||||
} as Record<string, string>,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async prepareBranch(branch: string) {
|
async prepareBranch(branch: string) {
|
||||||
if (this.commitMode === "github-api") {
|
if (this.octokit) {
|
||||||
// Preparing a new local branch is not necessary when using the API
|
// Preparing a new local branch is not necessary when using the API
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await switchToMaybeExistingBranch(branch, { cwd: this.cwd });
|
await switchToMaybeExistingBranch(branch, { cwd: this.cwd });
|
||||||
await reset(context.sha, { cwd: this.cwd });
|
await reset(github.context.sha, { cwd: this.cwd });
|
||||||
}
|
}
|
||||||
|
|
||||||
async pushChanges({ branch, message }: { branch: string; message: string }) {
|
async pushChanges({ branch, message }: { branch: string; message: string }) {
|
||||||
if (this.commitMode === "github-api") {
|
if (this.octokit) {
|
||||||
await commitChangesSinceBase({
|
/**
|
||||||
|
* Only add files form the current working directory
|
||||||
|
*
|
||||||
|
* This will emulate the behavior of `git add .`,
|
||||||
|
* used in {@link commitAll}.
|
||||||
|
*/
|
||||||
|
const addFromDirectory = this.cwd;
|
||||||
|
return commitChangesFromRepo({
|
||||||
octokit: this.octokit,
|
octokit: this.octokit,
|
||||||
...context.repo,
|
...github.context.repo,
|
||||||
branch,
|
branch,
|
||||||
message,
|
message,
|
||||||
base: {
|
base: {
|
||||||
commit: context.sha,
|
commit: github.context.sha,
|
||||||
},
|
},
|
||||||
cwd: this.cwd,
|
cwd: this.cwd,
|
||||||
|
force: true,
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (!(await checkIfClean({ cwd: this.cwd }))) {
|
if (!(await checkIfClean({ cwd: this.cwd }))) {
|
||||||
await commitAll(message, { cwd: this.cwd });
|
await commitAll(message, { cwd: this.cwd });
|
||||||
}
|
}
|
||||||
await push(branch, {
|
await push(branch, { cwd: this.cwd });
|
||||||
cwd: this.cwd,
|
|
||||||
env: {
|
|
||||||
...process.env,
|
|
||||||
...this.#getCliAuthEnv(),
|
|
||||||
} as Record<string, string>,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+45
-59
@@ -1,66 +1,59 @@
|
|||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
|
import path from "node:path";
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import { GitHub } from "./github.ts";
|
import { Git } from "./git.ts";
|
||||||
|
import { setupOctokit } from "./octokit.ts";
|
||||||
import readChangesetState from "./readChangesetState.ts";
|
import readChangesetState from "./readChangesetState.ts";
|
||||||
import { runPublish, runVersion } from "./run.ts";
|
import { runPublish, runVersion } from "./run.ts";
|
||||||
import {
|
import { fileExists } from "./utils.ts";
|
||||||
fileExists,
|
|
||||||
getOptionalInput,
|
const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||||
getRequiredInput,
|
|
||||||
throwOnRenamedInputs,
|
|
||||||
} from "./utils.ts";
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
throwOnRenamedInputs({
|
// to maintain compatibility with workflows created before github-token input was introduced
|
||||||
publish: "publish-script",
|
// it's important to prefer the explicitly set GITHUB_TOKEN over the default token coming from github.token
|
||||||
version: "version-script",
|
let githubToken = process.env.GITHUB_TOKEN || core.getInput("github-token");
|
||||||
commit: "commit-mesage",
|
|
||||||
title: "pr-title",
|
|
||||||
branch: "pr-base-branch",
|
|
||||||
prDraft: "pr-draft",
|
|
||||||
createGithubReleases: "create-github-releases",
|
|
||||||
commitMode: "commit-mode",
|
|
||||||
setupGitUser: "setup-git-user",
|
|
||||||
});
|
|
||||||
|
|
||||||
const githubToken = getRequiredInput("github-token");
|
if (!githubToken) {
|
||||||
if (process.env.GITHUB_TOKEN && process.env.GITHUB_TOKEN !== githubToken) {
|
core.setFailed("Please add the GITHUB_TOKEN to the changesets action");
|
||||||
throw new Error(
|
return;
|
||||||
'The GITHUB_TOKEN environment variable is set and does not match the "github-token" input. ' +
|
|
||||||
'Please pass the custom GitHub token to the "github-token" input and ' +
|
|
||||||
"remove the GITHUB_TOKEN environment variable to avoid conflicts.",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the user needs to change the cwd, set `working-directory` in the step instead
|
const cwd = path.resolve(getOptionalInput("cwd") ?? "");
|
||||||
const cwd = process.cwd();
|
core.info(`using resolved cwd: ${cwd}`);
|
||||||
|
|
||||||
const commitMode = getOptionalInput("commit-mode") ?? "git-cli";
|
const octokit = setupOctokit(githubToken);
|
||||||
const prDraft = getOptionalInput("pr-draft");
|
const commitMode = getOptionalInput("commitMode") ?? "git-cli";
|
||||||
|
const prDraft = getOptionalInput("prDraft");
|
||||||
if (commitMode !== "git-cli" && commitMode !== "github-api") {
|
if (commitMode !== "git-cli" && commitMode !== "github-api") {
|
||||||
core.setFailed(`Invalid commit mode: ${commitMode}`);
|
core.setFailed(`Invalid commit mode: ${commitMode}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (prDraft !== undefined && prDraft !== "always" && prDraft !== "create") {
|
if (prDraft !== undefined && prDraft !== "always" && prDraft !== "create") {
|
||||||
core.setFailed(`Invalid pr-draft: ${prDraft}`);
|
core.setFailed(`Invalid prDraft: ${prDraft}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const github = new GitHub({
|
const git = new Git({
|
||||||
|
octokit: commitMode === "github-api" ? octokit : undefined,
|
||||||
cwd,
|
cwd,
|
||||||
githubToken,
|
|
||||||
commitMode,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let setupGitUser = core.getBooleanInput("setup-git-user");
|
let setupGitUser = core.getBooleanInput("setupGitUser");
|
||||||
|
|
||||||
if (setupGitUser) {
|
if (setupGitUser) {
|
||||||
core.info("setting git user");
|
core.info("setting git user");
|
||||||
await github.setupUser();
|
await git.setupUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core.info("setting GitHub credentials");
|
||||||
|
await fs.writeFile(
|
||||||
|
`${process.env.HOME}/.netrc`,
|
||||||
|
`machine github.com\nlogin github-actions[bot]\npassword ${githubToken}`,
|
||||||
|
);
|
||||||
|
|
||||||
let { changesets } = await readChangesetState(cwd);
|
let { changesets } = await readChangesetState(cwd);
|
||||||
|
|
||||||
let publishScript = core.getInput("publish-script");
|
let publishScript = core.getInput("publish");
|
||||||
let hasChangesets = changesets.length !== 0;
|
let hasChangesets = changesets.length !== 0;
|
||||||
const hasNonEmptyChangesets = changesets.some(
|
const hasNonEmptyChangesets = changesets.some(
|
||||||
(changeset) => changeset.releases.length > 0,
|
(changeset) => changeset.releases.length > 0,
|
||||||
@@ -68,8 +61,8 @@ import {
|
|||||||
let hasPublishScript = !!publishScript;
|
let hasPublishScript = !!publishScript;
|
||||||
|
|
||||||
core.setOutput("published", "false");
|
core.setOutput("published", "false");
|
||||||
core.setOutput("published-packages", "[]");
|
core.setOutput("publishedPackages", "[]");
|
||||||
core.setOutput("has-changesets", String(hasChangesets));
|
core.setOutput("hasChangesets", String(hasChangesets));
|
||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case !hasChangesets && !hasPublishScript:
|
case !hasChangesets && !hasPublishScript:
|
||||||
@@ -127,29 +120,19 @@ import {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const createGithubReleases = core.getBooleanInput(
|
|
||||||
"create-github-releases",
|
|
||||||
);
|
|
||||||
const pushGitTags = core.getBooleanInput("push-git-tags");
|
|
||||||
if (createGithubReleases && !pushGitTags) {
|
|
||||||
throw new Error(
|
|
||||||
"The input 'create-github-releases' is set to true, but 'push-git-tags' is set to false. " +
|
|
||||||
"Creating GitHub releases requires pushing git tags. Please set 'push-git-tags' to true " +
|
|
||||||
"or set 'create-github-releases' to false.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const result = await runPublish({
|
const result = await runPublish({
|
||||||
script: publishScript,
|
script: publishScript,
|
||||||
github,
|
githubToken,
|
||||||
createGithubReleases,
|
git,
|
||||||
pushGitTags,
|
octokit,
|
||||||
|
createGithubReleases: core.getBooleanInput("createGithubReleases"),
|
||||||
cwd,
|
cwd,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result.published) {
|
if (result.published) {
|
||||||
core.setOutput("published", "true");
|
core.setOutput("published", "true");
|
||||||
core.setOutput(
|
core.setOutput(
|
||||||
"published-packages",
|
"publishedPackages",
|
||||||
JSON.stringify(result.publishedPackages),
|
JSON.stringify(result.publishedPackages),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -172,18 +155,21 @@ import {
|
|||||||
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"),
|
script: getOptionalInput("version"),
|
||||||
github,
|
githubToken,
|
||||||
|
git,
|
||||||
|
octokit,
|
||||||
cwd,
|
cwd,
|
||||||
prTitle: getOptionalInput("pr-title"),
|
prTitle: getOptionalInput("title"),
|
||||||
commitMessage: getOptionalInput("commit-message"),
|
commitMessage: getOptionalInput("commit"),
|
||||||
hasPublishScript,
|
hasPublishScript,
|
||||||
prDraft,
|
prDraft,
|
||||||
branch: getOptionalInput("pr-base-branch"),
|
branch: getOptionalInput("branch"),
|
||||||
});
|
});
|
||||||
|
|
||||||
core.setOutput("pr-number", String(pullRequestNumber));
|
core.setOutput("pullRequestNumber", String(pullRequestNumber));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,86 +0,0 @@
|
|||||||
import fs from "node:fs/promises";
|
|
||||||
import os from "node:os";
|
|
||||||
import path from "node:path";
|
|
||||||
import artifact from "@actions/artifact";
|
|
||||||
import * as core from "@actions/core";
|
|
||||||
import {
|
|
||||||
downloadArtifact,
|
|
||||||
execChangesetsCli,
|
|
||||||
getOptionalInput,
|
|
||||||
} from "../utils.ts";
|
|
||||||
|
|
||||||
try {
|
|
||||||
await main();
|
|
||||||
} catch (err) {
|
|
||||||
core.setFailed((err as Error).message);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
const publishPlanArtifactId = getOptionalInput("publish-plan-artifact-id");
|
|
||||||
|
|
||||||
// If the user needs to change the cwd, set `working-directory` in the step instead
|
|
||||||
const cwd = process.cwd();
|
|
||||||
const tmpDir = process.env.RUNNER_TEMP ?? (await fs.realpath(os.tmpdir()));
|
|
||||||
const outDir = path.join(tmpDir, `changeset-pack-${Date.now()}`);
|
|
||||||
|
|
||||||
await pack(cwd, {
|
|
||||||
outDir,
|
|
||||||
publishPlanPath: publishPlanArtifactId
|
|
||||||
? await downloadPublishPlanArtifact(tmpDir, Number(publishPlanArtifactId))
|
|
||||||
: undefined,
|
|
||||||
});
|
|
||||||
|
|
||||||
const packDirArtifact = await artifact.uploadArtifact(
|
|
||||||
`changeset-pack-${Date.now()}`,
|
|
||||||
await getFiles(outDir),
|
|
||||||
outDir,
|
|
||||||
{
|
|
||||||
retentionDays: 30,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
if (packDirArtifact.id === undefined) {
|
|
||||||
throw new Error("Packed artifact upload did not return an artifact id");
|
|
||||||
}
|
|
||||||
core.setOutput("pack-dir-artifact-id", String(packDirArtifact.id));
|
|
||||||
}
|
|
||||||
|
|
||||||
async function pack(
|
|
||||||
cwd: string,
|
|
||||||
args: {
|
|
||||||
outDir: string;
|
|
||||||
publishPlanPath?: string;
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
const cliArgs = ["pack", "--out-dir", args.outDir];
|
|
||||||
if (args.publishPlanPath) {
|
|
||||||
cliArgs.push("--from-publish-plan", args.publishPlanPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
await execChangesetsCli(cliArgs, {
|
|
||||||
cwd,
|
|
||||||
env: process.env,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function downloadPublishPlanArtifact(tmpDir: string, artifactId: number) {
|
|
||||||
const downloadPath = await downloadArtifact(
|
|
||||||
tmpDir,
|
|
||||||
artifactId,
|
|
||||||
"changeset-publish-plan",
|
|
||||||
);
|
|
||||||
return path.join(downloadPath, "publish-plan.json");
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getFiles(dir: string): Promise<string[]> {
|
|
||||||
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
||||||
const files = await Promise.all(
|
|
||||||
entries.map(async (entry) => {
|
|
||||||
const entryPath = path.join(dir, entry.name);
|
|
||||||
if (entry.isDirectory()) {
|
|
||||||
return getFiles(entryPath);
|
|
||||||
}
|
|
||||||
return [entryPath];
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
return files.flat();
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import * as github from "@actions/github";
|
import * as github from "@actions/github";
|
||||||
import { getOptionalInput, getRequiredInput } from "../utils.ts";
|
|
||||||
|
|
||||||
type Octokit = ReturnType<typeof github.getOctokit>;
|
type Octokit = ReturnType<typeof github.getOctokit>;
|
||||||
type CreateCommentParams = NonNullable<
|
type CreateCommentParams = NonNullable<
|
||||||
@@ -24,9 +23,9 @@ async function main() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const githubToken = getRequiredInput("github-token");
|
const githubToken = core.getInput("github-token", { required: true });
|
||||||
const body = getRequiredInput("body");
|
const body = core.getInput("body", { required: true });
|
||||||
const updateId = getOptionalInput("update-id");
|
const updateId = core.getInput("update-id");
|
||||||
|
|
||||||
const commentMarker = updateId ? getCommentMarker(updateId) : null;
|
const commentMarker = updateId ? getCommentMarker(updateId) : null;
|
||||||
const commentBody = commentMarker ? `${commentMarker}\n\n${body}` : body;
|
const commentBody = commentMarker ? `${commentMarker}\n\n${body}` : body;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as github from "@actions/github";
|
import * as github from "@actions/github";
|
||||||
import { getReleasePlan } from "@changesets/get-release-plan";
|
import getReleasePlan from "@changesets/get-release-plan";
|
||||||
import type {
|
import type {
|
||||||
ComprehensiveRelease,
|
ComprehensiveRelease,
|
||||||
ReleasePlan,
|
ReleasePlan,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { pathToFileURL } from "node:url";
|
import { pathToFileURL } from "node:url";
|
||||||
import type * as github from "@actions/github";
|
import type * as github from "@actions/github";
|
||||||
import { getReleasePlan } from "@changesets/get-release-plan";
|
import getReleasePlan from "@changesets/get-release-plan";
|
||||||
import { createFixture } from "fs-fixture";
|
import { createFixture } from "fs-fixture";
|
||||||
import { exec } from "tinyexec";
|
import { exec } from "tinyexec";
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
@@ -28,7 +28,6 @@ describe("getPullRequestWorktree", () => {
|
|||||||
private: true,
|
private: true,
|
||||||
workspaces: ["packages/*"],
|
workspaces: ["packages/*"],
|
||||||
}),
|
}),
|
||||||
"package-lock.json": "",
|
|
||||||
"packages/pkg-a/package.json": JSON.stringify({
|
"packages/pkg-a/package.json": JSON.stringify({
|
||||||
name: "pkg-a",
|
name: "pkg-a",
|
||||||
version: "1.0.0",
|
version: "1.0.0",
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
import fs from "node:fs/promises";
|
|
||||||
import os from "node:os";
|
|
||||||
import * as core from "@actions/core";
|
|
||||||
import { GitHub } from "../github.ts";
|
|
||||||
import { runPublish } from "../run.ts";
|
|
||||||
import {
|
|
||||||
downloadArtifact,
|
|
||||||
getOptionalInput,
|
|
||||||
getRequiredInput,
|
|
||||||
} from "../utils.ts";
|
|
||||||
|
|
||||||
try {
|
|
||||||
await main();
|
|
||||||
} catch (err) {
|
|
||||||
core.setFailed((err as Error).message);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
const githubToken = getRequiredInput("github-token");
|
|
||||||
const script = getOptionalInput("script");
|
|
||||||
const packDirArtifactId = getOptionalInput("pack-dir-artifact-id");
|
|
||||||
const createGithubReleases = core.getBooleanInput("create-github-releases");
|
|
||||||
const pushGitTags = core.getBooleanInput("push-git-tags");
|
|
||||||
|
|
||||||
if (createGithubReleases && !pushGitTags) {
|
|
||||||
throw new Error(
|
|
||||||
"The input 'create-github-releases' is set to true, but 'push-git-tags' is set to false. " +
|
|
||||||
"Creating GitHub releases requires pushing git tags. Please set 'push-git-tags' to true " +
|
|
||||||
"or set 'create-github-releases' to false.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the user needs to change the cwd, set `working-directory` in the step instead
|
|
||||||
const cwd = process.cwd();
|
|
||||||
|
|
||||||
// NOTE: Always use API mode here as publish does not need a commit-mode.
|
|
||||||
const github = new GitHub({ cwd, githubToken, commitMode: "github-api" });
|
|
||||||
|
|
||||||
const fromPackDir = packDirArtifactId
|
|
||||||
? await downloadArtifact(
|
|
||||||
process.env.RUNNER_TEMP ?? (await fs.realpath(os.tmpdir())),
|
|
||||||
Number(packDirArtifactId),
|
|
||||||
"changeset-pack",
|
|
||||||
)
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
const result = await runPublish({
|
|
||||||
script,
|
|
||||||
github,
|
|
||||||
createGithubReleases,
|
|
||||||
pushGitTags,
|
|
||||||
cwd,
|
|
||||||
fromPackDir,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (result.published) {
|
|
||||||
core.setOutput("published", "true");
|
|
||||||
core.setOutput(
|
|
||||||
"published-packages",
|
|
||||||
JSON.stringify(result.publishedPackages),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
core.setOutput("published", "false");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.exitCode !== 0) {
|
|
||||||
throw new Error(
|
|
||||||
`Publish command exited with code ${result.exitCode}${
|
|
||||||
result.published
|
|
||||||
? `, but some packages were published: ${result.publishedPackages
|
|
||||||
.map((p) => `${p.name}@${p.version}`)
|
|
||||||
.join(", ")}`
|
|
||||||
: ""
|
|
||||||
}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { readPreState } from "@changesets/pre";
|
import { readPreState } from "@changesets/pre";
|
||||||
import { readChangesets } from "@changesets/read";
|
import readChangesets from "@changesets/read";
|
||||||
import type { PreState, NewChangeset } from "@changesets/types";
|
import type { PreState, NewChangeset } from "@changesets/types";
|
||||||
|
|
||||||
export type ChangesetState = {
|
export type ChangesetState = {
|
||||||
|
|||||||
+29
-20
@@ -1,9 +1,10 @@
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import type { Changeset } from "@changesets/types";
|
import type { Changeset } from "@changesets/types";
|
||||||
import { writeChangeset } from "@changesets/write";
|
import writeChangeset from "@changesets/write";
|
||||||
import { createFixture } from "fs-fixture";
|
import { createFixture } from "fs-fixture";
|
||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { GitHub } from "./github.ts";
|
import { Git } from "./git.ts";
|
||||||
|
import { setupOctokit } from "./octokit.ts";
|
||||||
import { runVersion } from "./run.ts";
|
import { runVersion } from "./run.ts";
|
||||||
|
|
||||||
vi.mock("@actions/github", () => ({
|
vi.mock("@actions/github", () => ({
|
||||||
@@ -20,7 +21,8 @@ vi.mock("@actions/github", () => ({
|
|||||||
graphql: mockedGraphql,
|
graphql: mockedGraphql,
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
vi.mock("@changesets/ghcommit");
|
vi.mock("./git.ts");
|
||||||
|
vi.mock("@changesets/ghcommit/git");
|
||||||
|
|
||||||
let mockedGithubMethods = {
|
let mockedGithubMethods = {
|
||||||
pulls: {
|
pulls: {
|
||||||
@@ -56,7 +58,6 @@ function createSimpleProjectFixture() {
|
|||||||
private: true,
|
private: true,
|
||||||
workspaces: ["packages/*"],
|
workspaces: ["packages/*"],
|
||||||
}),
|
}),
|
||||||
"package-lock.json": "",
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +84,6 @@ function createIgnoredPackageFixture() {
|
|||||||
private: true,
|
private: true,
|
||||||
workspaces: ["packages/*"],
|
workspaces: ["packages/*"],
|
||||||
}),
|
}),
|
||||||
"package-lock.json": "",
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,13 +91,6 @@ const writeChangesets = (changesets: Changeset[], cwd: string) => {
|
|||||||
return Promise.all(changesets.map((commit) => writeChangeset(commit, cwd)));
|
return Promise.all(changesets.map((commit) => writeChangeset(commit, cwd)));
|
||||||
};
|
};
|
||||||
|
|
||||||
const createGithub = (cwd: string) =>
|
|
||||||
new GitHub({
|
|
||||||
cwd,
|
|
||||||
githubToken: "@@GITHUB_TOKEN",
|
|
||||||
commitMode: "github-api",
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
});
|
});
|
||||||
@@ -133,7 +126,9 @@ describe("version", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await runVersion({
|
await runVersion({
|
||||||
github: createGithub(cwd),
|
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
||||||
|
githubToken: "@@GITHUB_TOKEN",
|
||||||
|
git: new Git({ cwd }),
|
||||||
cwd,
|
cwd,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -166,7 +161,9 @@ describe("version", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await runVersion({
|
await runVersion({
|
||||||
github: createGithub(cwd),
|
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
||||||
|
githubToken: "@@GITHUB_TOKEN",
|
||||||
|
git: new Git({ cwd }),
|
||||||
cwd,
|
cwd,
|
||||||
prDraft: "create",
|
prDraft: "create",
|
||||||
});
|
});
|
||||||
@@ -200,7 +197,9 @@ describe("version", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await runVersion({
|
await runVersion({
|
||||||
github: createGithub(cwd),
|
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
||||||
|
githubToken: "@@GITHUB_TOKEN",
|
||||||
|
git: new Git({ cwd }),
|
||||||
cwd,
|
cwd,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -233,7 +232,9 @@ describe("version", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await runVersion({
|
await runVersion({
|
||||||
github: createGithub(cwd),
|
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
||||||
|
githubToken: "@@GITHUB_TOKEN",
|
||||||
|
git: new Git({ cwd }),
|
||||||
cwd,
|
cwd,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -286,7 +287,9 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
|||||||
);
|
);
|
||||||
|
|
||||||
await runVersion({
|
await runVersion({
|
||||||
github: createGithub(cwd),
|
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
||||||
|
githubToken: "@@GITHUB_TOKEN",
|
||||||
|
git: new Git({ cwd }),
|
||||||
cwd,
|
cwd,
|
||||||
prBodyMaxCharacters: 1000,
|
prBodyMaxCharacters: 1000,
|
||||||
});
|
});
|
||||||
@@ -343,7 +346,9 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
|||||||
);
|
);
|
||||||
|
|
||||||
await runVersion({
|
await runVersion({
|
||||||
github: createGithub(cwd),
|
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
||||||
|
githubToken: "@@GITHUB_TOKEN",
|
||||||
|
git: new Git({ cwd }),
|
||||||
cwd,
|
cwd,
|
||||||
prBodyMaxCharacters: 500,
|
prBodyMaxCharacters: 500,
|
||||||
});
|
});
|
||||||
@@ -378,7 +383,9 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
|||||||
);
|
);
|
||||||
|
|
||||||
await runVersion({
|
await runVersion({
|
||||||
github: createGithub(cwd),
|
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
||||||
|
githubToken: "@@GITHUB_TOKEN",
|
||||||
|
git: new Git({ cwd }),
|
||||||
cwd,
|
cwd,
|
||||||
prDraft: "create",
|
prDraft: "create",
|
||||||
});
|
});
|
||||||
@@ -410,7 +417,9 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
|||||||
);
|
);
|
||||||
|
|
||||||
await runVersion({
|
await runVersion({
|
||||||
github: createGithub(cwd),
|
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
||||||
|
githubToken: "@@GITHUB_TOKEN",
|
||||||
|
git: new Git({ cwd }),
|
||||||
cwd,
|
cwd,
|
||||||
prDraft: "always",
|
prDraft: "always",
|
||||||
});
|
});
|
||||||
|
|||||||
+121
-156
@@ -1,30 +1,25 @@
|
|||||||
import { randomUUID } from "node:crypto";
|
|
||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import os from "node:os";
|
import { createRequire } from "node:module";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import {
|
import { exec, getExecOutput } from "@actions/exec";
|
||||||
exec,
|
import * as github from "@actions/github";
|
||||||
getExecOutput,
|
|
||||||
type ExecOptions,
|
|
||||||
type ExecOutput,
|
|
||||||
} from "@actions/exec";
|
|
||||||
import { context } from "@actions/github";
|
|
||||||
import type { PreState } from "@changesets/types";
|
import type { PreState } from "@changesets/types";
|
||||||
import { type Package, getPackages } from "@manypkg/get-packages";
|
import { type Package, getPackages } from "@manypkg/get-packages";
|
||||||
import type { GitHub } from "./github.ts";
|
import semverLt from "semver/functions/lt.js";
|
||||||
|
import { Git } from "./git.ts";
|
||||||
import type { Octokit } from "./octokit.ts";
|
import type { Octokit } from "./octokit.ts";
|
||||||
import readChangesetState from "./readChangesetState.ts";
|
import readChangesetState from "./readChangesetState.ts";
|
||||||
import {
|
import {
|
||||||
execChangesetsCli,
|
|
||||||
getChangedPackages,
|
getChangedPackages,
|
||||||
getChangelogEntry,
|
getChangelogEntry,
|
||||||
getExecOutputChangesetsCli,
|
|
||||||
getVersionsByDirectory,
|
getVersionsByDirectory,
|
||||||
isErrorWithCode,
|
isErrorWithCode,
|
||||||
sortTheThings,
|
sortTheThings,
|
||||||
} from "./utils.ts";
|
} from "./utils.ts";
|
||||||
|
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
|
||||||
// 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.
|
||||||
// `body is too long (maximum is 65536 characters)`.
|
// `body is too long (maximum is 65536 characters)`.
|
||||||
@@ -59,25 +54,20 @@ const createRelease = async (
|
|||||||
tag_name: tagName,
|
tag_name: tagName,
|
||||||
body: changelogEntry.content,
|
body: changelogEntry.content,
|
||||||
prerelease: pkg.packageJson.version.includes("-"),
|
prerelease: pkg.packageJson.version.includes("-"),
|
||||||
...context.repo,
|
...github.context.repo,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
type PublishOptions = {
|
type PublishOptions = {
|
||||||
script?: string;
|
script: string;
|
||||||
fromPackDir?: string;
|
githubToken: string;
|
||||||
|
octokit: Octokit;
|
||||||
createGithubReleases: boolean;
|
createGithubReleases: boolean;
|
||||||
pushGitTags: boolean;
|
git: Git;
|
||||||
github: GitHub;
|
|
||||||
cwd: string;
|
cwd: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type PublishedPackage = { name: string; version: string };
|
type PublishedPackage = { name: string; version: string };
|
||||||
type ChangesetsOutputEvent = {
|
|
||||||
type: "git-tag";
|
|
||||||
tag: string;
|
|
||||||
packageName: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type PublishResult =
|
type PublishResult =
|
||||||
| {
|
| {
|
||||||
@@ -90,147 +80,81 @@ type PublishResult =
|
|||||||
exitCode: number;
|
exitCode: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
function isObject(value: unknown) {
|
|
||||||
return typeof value === "object" && value !== null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isChangesetsOutputEvent(
|
|
||||||
value: unknown,
|
|
||||||
): value is ChangesetsOutputEvent {
|
|
||||||
return (
|
|
||||||
isObject(value) &&
|
|
||||||
"type" in value &&
|
|
||||||
value.type === "git-tag" &&
|
|
||||||
"tag" in value &&
|
|
||||||
typeof value.tag === "string" &&
|
|
||||||
"packageName" in value &&
|
|
||||||
typeof value.packageName === "string"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function readChangesetsOutput(outputPath: string) {
|
|
||||||
let rawOutput: string;
|
|
||||||
try {
|
|
||||||
rawOutput = await fs.readFile(outputPath, "utf8");
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Failed to read changesets output at ${outputPath}`, {
|
|
||||||
cause: err,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const events: ChangesetsOutputEvent[] = [];
|
|
||||||
|
|
||||||
let lineStart = 0;
|
|
||||||
while (lineStart <= rawOutput.length) {
|
|
||||||
let lineEnd = rawOutput.indexOf("\n", lineStart);
|
|
||||||
if (lineEnd === -1) {
|
|
||||||
lineEnd = rawOutput.length;
|
|
||||||
}
|
|
||||||
const line = rawOutput.slice(lineStart, lineEnd);
|
|
||||||
lineStart = lineEnd + 1;
|
|
||||||
|
|
||||||
if (/^\s*$/.test(line)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let event: unknown;
|
|
||||||
try {
|
|
||||||
event = JSON.parse(line);
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Failed to parse changesets output event: ${line}`, {
|
|
||||||
cause: err,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isChangesetsOutputEvent(event)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
events.push(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
return events;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function runPublish({
|
export async function runPublish({
|
||||||
script,
|
script,
|
||||||
fromPackDir,
|
githubToken,
|
||||||
github,
|
git,
|
||||||
|
octokit,
|
||||||
createGithubReleases,
|
createGithubReleases,
|
||||||
pushGitTags,
|
|
||||||
cwd,
|
cwd,
|
||||||
}: PublishOptions): Promise<PublishResult> {
|
}: PublishOptions): Promise<PublishResult> {
|
||||||
const { octokit } = github;
|
let changesetPublishOutput = await getExecOutput(script, undefined, {
|
||||||
let changesetPublishOutput: ExecOutput;
|
|
||||||
const outputFile = path.join(
|
|
||||||
process.env.RUNNER_TEMP ?? (await fs.realpath(os.tmpdir())),
|
|
||||||
`changesets-output-${randomUUID()}.ndjson`,
|
|
||||||
);
|
|
||||||
const execOptions: ExecOptions = {
|
|
||||||
cwd,
|
cwd,
|
||||||
ignoreReturnCode: true,
|
ignoreReturnCode: true,
|
||||||
env: {
|
env: { ...process.env, GITHUB_TOKEN: githubToken },
|
||||||
...process.env,
|
});
|
||||||
GITHUB_TOKEN: github.getToken(),
|
|
||||||
CHANGESETS_OUTPUT: outputFile,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
if (script) {
|
|
||||||
changesetPublishOutput = await getExecOutput(
|
|
||||||
script,
|
|
||||||
undefined,
|
|
||||||
execOptions,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
const args = ["publish"];
|
|
||||||
if (fromPackDir) {
|
|
||||||
args.push("--from-pack-dir", fromPackDir);
|
|
||||||
}
|
|
||||||
changesetPublishOutput = await getExecOutputChangesetsCli(
|
|
||||||
args,
|
|
||||||
execOptions,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let { packages, tool } = await getPackages(cwd);
|
let { packages, tool } = await getPackages(cwd);
|
||||||
let packagesByName = new Map(packages.map((x) => [x.packageJson.name, x]));
|
let releasedPackages: Package[] = [];
|
||||||
let output = await readChangesetsOutput(outputFile);
|
|
||||||
let releases = output.map((event) => {
|
if (tool !== "root") {
|
||||||
let pkg = packagesByName.get(event.packageName);
|
let newTagRegex = /New tag:\s+(@[^/]+\/[^@]+|[^/]+)@([^\s]+)/;
|
||||||
if (pkg === undefined) {
|
let packagesByName = new Map(packages.map((x) => [x.packageJson.name, x]));
|
||||||
|
|
||||||
|
for (let line of changesetPublishOutput.stdout.split("\n")) {
|
||||||
|
let match = line.match(newTagRegex);
|
||||||
|
if (match === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let pkgName = match[1];
|
||||||
|
let pkg = packagesByName.get(pkgName);
|
||||||
|
if (pkg === undefined) {
|
||||||
|
throw new Error(
|
||||||
|
`Package "${pkgName}" not found.` +
|
||||||
|
"This is probably a bug in the action, please open an issue",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
releasedPackages.push(pkg);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (createGithubReleases) {
|
||||||
|
await Promise.all(
|
||||||
|
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(
|
throw new Error(
|
||||||
`Package "${event.packageName}" not found.` +
|
`No package found.` +
|
||||||
"This is probably a bug in the action, please open an issue",
|
"This is probably a bug in the action, please open an issue",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return { pkg, tag: event.tag };
|
let pkg = packages[0];
|
||||||
});
|
let newTagRegex = /New tag:/;
|
||||||
|
|
||||||
if (tool.type === "root" && packages.length === 0) {
|
for (let line of changesetPublishOutput.stdout.split("\n")) {
|
||||||
throw new Error(
|
let match = line.match(newTagRegex);
|
||||||
`No package found.` +
|
|
||||||
"This is probably a bug in the action, please open an issue",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (createGithubReleases || pushGitTags) {
|
if (match) {
|
||||||
await Promise.all(
|
releasedPackages.push(pkg);
|
||||||
releases.map(async ({ pkg, tag }) => {
|
|
||||||
if (pushGitTags) {
|
|
||||||
await github.pushTag(tag);
|
|
||||||
}
|
|
||||||
if (createGithubReleases) {
|
if (createGithubReleases) {
|
||||||
await createRelease(octokit, { pkg, tagName: tag });
|
const tagName = `v${pkg.packageJson.version}`;
|
||||||
|
await git.pushTag(tagName);
|
||||||
|
await createRelease(octokit, { pkg, tagName });
|
||||||
}
|
}
|
||||||
}),
|
break;
|
||||||
);
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (releases.length) {
|
if (releasedPackages.length) {
|
||||||
return {
|
return {
|
||||||
published: true,
|
published: true,
|
||||||
publishedPackages: releases.map(({ pkg }) => ({
|
publishedPackages: releasedPackages.map((pkg) => ({
|
||||||
name: pkg.packageJson.name,
|
name: pkg.packageJson.name,
|
||||||
version: pkg.packageJson.version,
|
version: pkg.packageJson.version,
|
||||||
})),
|
})),
|
||||||
@@ -241,6 +165,24 @@ export async function runPublish({
|
|||||||
return { published: false, exitCode: changesetPublishOutput.exitCode };
|
return { published: false, exitCode: changesetPublishOutput.exitCode };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const requireChangesetsCliPkgJson = (cwd: string) => {
|
||||||
|
try {
|
||||||
|
return require(
|
||||||
|
require.resolve("@changesets/cli/package.json", {
|
||||||
|
paths: [cwd],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
if (isErrorWithCode(err, "MODULE_NOT_FOUND")) {
|
||||||
|
throw new Error(
|
||||||
|
`Have you forgotten to install \`@changesets/cli\` in "${cwd}"?`,
|
||||||
|
{ cause: err },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
type GetMessageOptions = {
|
type GetMessageOptions = {
|
||||||
hasPublishScript: boolean;
|
hasPublishScript: boolean;
|
||||||
branch: string;
|
branch: string;
|
||||||
@@ -312,7 +254,9 @@ export async function getVersionPrBody({
|
|||||||
|
|
||||||
type VersionOptions = {
|
type VersionOptions = {
|
||||||
script?: string;
|
script?: string;
|
||||||
github: GitHub;
|
githubToken: string;
|
||||||
|
git: Git;
|
||||||
|
octokit: Octokit;
|
||||||
cwd?: string;
|
cwd?: string;
|
||||||
prTitle?: string;
|
prTitle?: string;
|
||||||
commitMessage?: string;
|
commitMessage?: string;
|
||||||
@@ -328,30 +272,47 @@ type RunVersionResult = {
|
|||||||
|
|
||||||
export async function runVersion({
|
export async function runVersion({
|
||||||
script,
|
script,
|
||||||
github,
|
githubToken,
|
||||||
|
git,
|
||||||
|
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 = context.ref.replace("refs/heads/", ""),
|
branch = github.context.ref.replace("refs/heads/", ""),
|
||||||
prDraft,
|
prDraft,
|
||||||
}: VersionOptions): Promise<RunVersionResult> {
|
}: VersionOptions): Promise<RunVersionResult> {
|
||||||
const { octokit } = github;
|
|
||||||
let versionBranch = `changeset-release/${branch}`;
|
let versionBranch = `changeset-release/${branch}`;
|
||||||
|
|
||||||
let { preState } = await readChangesetState(cwd);
|
let { preState } = await readChangesetState(cwd);
|
||||||
|
|
||||||
await github.prepareBranch(versionBranch);
|
await git.prepareBranch(versionBranch);
|
||||||
|
|
||||||
let versionsByDirectory = await getVersionsByDirectory(cwd);
|
let versionsByDirectory = await getVersionsByDirectory(cwd);
|
||||||
|
|
||||||
const env = { ...process.env, GITHUB_TOKEN: github.getToken() };
|
const env = { ...process.env, GITHUB_TOKEN: githubToken };
|
||||||
|
|
||||||
if (script) {
|
if (script) {
|
||||||
await exec(script, undefined, { cwd, env });
|
await exec(script, undefined, { cwd, env });
|
||||||
} else {
|
} else {
|
||||||
await execChangesetsCli(["version"], { cwd, env });
|
let changesetsCliPkgJson = requireChangesetsCliPkgJson(cwd);
|
||||||
|
let cmd = semverLt(changesetsCliPkgJson.version, "2.0.0")
|
||||||
|
? "bump"
|
||||||
|
: "version";
|
||||||
|
await exec(
|
||||||
|
"node",
|
||||||
|
[
|
||||||
|
require.resolve("@changesets/cli/bin.js", {
|
||||||
|
paths: [cwd],
|
||||||
|
}),
|
||||||
|
cmd,
|
||||||
|
],
|
||||||
|
{
|
||||||
|
cwd,
|
||||||
|
env,
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let changedPackages = await getChangedPackages(cwd, versionsByDirectory);
|
let changedPackages = await getChangedPackages(cwd, versionsByDirectory);
|
||||||
@@ -377,10 +338,17 @@ export async function runVersion({
|
|||||||
!!preState ? ` (${preState.tag})` : ""
|
!!preState ? ` (${preState.tag})` : ""
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch any existing pull requests that are open against the branch,
|
||||||
|
* before we push any changes that may inadvertently close the existing PRs.
|
||||||
|
*
|
||||||
|
* (`@changesets/ghcommit` has to reset the branch to the same commit as the base,
|
||||||
|
* which GitHub will then react to by closing the PRs)
|
||||||
|
*/
|
||||||
const existingPullRequests = await octokit.rest.pulls.list({
|
const existingPullRequests = await octokit.rest.pulls.list({
|
||||||
...context.repo,
|
...github.context.repo,
|
||||||
state: "open",
|
state: "open",
|
||||||
head: `${context.repo.owner}:${versionBranch}`,
|
head: `${github.context.repo.owner}:${versionBranch}`,
|
||||||
base: branch,
|
base: branch,
|
||||||
});
|
});
|
||||||
core.info(
|
core.info(
|
||||||
@@ -391,10 +359,7 @@ export async function runVersion({
|
|||||||
)}`,
|
)}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
await github.pushChanges({
|
await git.pushChanges({ branch: versionBranch, message: finalCommitMessage });
|
||||||
branch: versionBranch,
|
|
||||||
message: finalCommitMessage,
|
|
||||||
});
|
|
||||||
|
|
||||||
const changedPackagesInfo = (await changedPackagesInfoPromises)
|
const changedPackagesInfo = (await changedPackagesInfoPromises)
|
||||||
.filter((x) => x)
|
.filter((x) => x)
|
||||||
@@ -416,7 +381,7 @@ export async function runVersion({
|
|||||||
title: finalPrTitle,
|
title: finalPrTitle,
|
||||||
body: prBody,
|
body: prBody,
|
||||||
draft: prDraft !== undefined,
|
draft: prDraft !== undefined,
|
||||||
...context.repo,
|
...github.context.repo,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,119 +0,0 @@
|
|||||||
import fs from "node:fs/promises";
|
|
||||||
import os from "node:os";
|
|
||||||
import path from "node:path";
|
|
||||||
import artifact from "@actions/artifact";
|
|
||||||
import * as core from "@actions/core";
|
|
||||||
import readChangesetState from "../readChangesetState.ts";
|
|
||||||
import { execChangesetsCli } from "../utils.ts";
|
|
||||||
|
|
||||||
type ModeResult =
|
|
||||||
| {
|
|
||||||
mode: "none";
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
mode: "version";
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
mode: "publish";
|
|
||||||
publishPlanPath: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type PublishPlan = unknown[];
|
|
||||||
|
|
||||||
try {
|
|
||||||
await main();
|
|
||||||
} catch (err) {
|
|
||||||
core.setFailed((err as Error).message);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
const result = await getMode();
|
|
||||||
core.setOutput("mode", result.mode);
|
|
||||||
if (result.mode === "publish") {
|
|
||||||
const publishPlanArtifact = await artifact.uploadArtifact(
|
|
||||||
path.basename(result.publishPlanPath, ".json"),
|
|
||||||
[result.publishPlanPath],
|
|
||||||
path.dirname(result.publishPlanPath),
|
|
||||||
{
|
|
||||||
skipArchive: true,
|
|
||||||
retentionDays: 30,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
if (publishPlanArtifact.id === undefined) {
|
|
||||||
throw new Error(
|
|
||||||
"Publish plan artifact upload did not return an artifact id",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
core.setOutput("publish-plan-artifact-id", String(publishPlanArtifact.id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getMode(): Promise<ModeResult> {
|
|
||||||
const { changesets } = await readChangesetState();
|
|
||||||
|
|
||||||
if (changesets.length > 0) {
|
|
||||||
const hasNonEmptyChangesets = changesets.some(
|
|
||||||
(changeset) => changeset.releases.length > 0,
|
|
||||||
);
|
|
||||||
if (hasNonEmptyChangesets) {
|
|
||||||
return { mode: "version" };
|
|
||||||
}
|
|
||||||
return { mode: "none" };
|
|
||||||
}
|
|
||||||
|
|
||||||
const cwd = process.cwd();
|
|
||||||
const publishPlanPath = path.join(
|
|
||||||
process.env.RUNNER_TEMP ?? (await fs.realpath(os.tmpdir())),
|
|
||||||
`changeset-publish-plan-${Date.now()}`,
|
|
||||||
// we need a stable filename here (in a unique dirname) so the artifact download can find this cleanly
|
|
||||||
"publish-plan.json",
|
|
||||||
);
|
|
||||||
await execChangesetsCli(["publish-plan", "--output", publishPlanPath], {
|
|
||||||
cwd,
|
|
||||||
env: process.env,
|
|
||||||
});
|
|
||||||
|
|
||||||
const publishPlan = await readPublishPlan(publishPlanPath);
|
|
||||||
if (publishPlan.length === 0) {
|
|
||||||
return { mode: "none" };
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
mode: "publish",
|
|
||||||
publishPlanPath,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async function readPublishPlan(publishPlanPath: string): Promise<PublishPlan> {
|
|
||||||
let rawPlan: string;
|
|
||||||
try {
|
|
||||||
rawPlan = await fs.readFile(publishPlanPath, "utf8");
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Failed to read publish plan at ${publishPlanPath}`, {
|
|
||||||
cause: err,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let plan: unknown;
|
|
||||||
try {
|
|
||||||
plan = JSON.parse(rawPlan);
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Failed to parse publish plan at ${publishPlanPath}`, {
|
|
||||||
cause: err,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
typeof plan !== "object" ||
|
|
||||||
plan === null ||
|
|
||||||
!("version" in plan) ||
|
|
||||||
typeof plan.version !== "number" ||
|
|
||||||
!("plan" in plan) ||
|
|
||||||
!Array.isArray(plan.plan)
|
|
||||||
) {
|
|
||||||
throw new Error(
|
|
||||||
`Invalid publish plan at ${publishPlanPath}: expected { version: number; plan: unknown[] }`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return plan.plan;
|
|
||||||
}
|
|
||||||
@@ -1,18 +1,6 @@
|
|||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import { createRequire } from "node:module";
|
|
||||||
import path from "node:path";
|
|
||||||
import artifact from "@actions/artifact";
|
|
||||||
import * as core from "@actions/core";
|
|
||||||
import {
|
|
||||||
exec,
|
|
||||||
getExecOutput,
|
|
||||||
type ExecOptions as ActionsExecOptions,
|
|
||||||
type ExecOutput,
|
|
||||||
} from "@actions/exec";
|
|
||||||
import { getPackages, type Package } from "@manypkg/get-packages";
|
import { getPackages, type Package } from "@manypkg/get-packages";
|
||||||
|
|
||||||
const require = createRequire(import.meta.url);
|
|
||||||
|
|
||||||
export const BumpLevels = {
|
export const BumpLevels = {
|
||||||
dep: 0,
|
dep: 0,
|
||||||
patch: 1,
|
patch: 1,
|
||||||
@@ -123,87 +111,3 @@ export function fileExists(filePath: string) {
|
|||||||
() => false,
|
() => false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getOptionalInput(name: string) {
|
|
||||||
// normalize empty string default return value of `core.getInput` to undefined
|
|
||||||
return core.getInput(name) || undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getRequiredInput(name: string) {
|
|
||||||
// it's just a small utility wrapper, mainly introduced for usage parity with our custom `getOptionalInput`
|
|
||||||
// note: `core.getBooleanInput` gets used directly as it already normalizes the return value nicely
|
|
||||||
return core.getInput(name, { required: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
export function throwOnRenamedInputs(renames: Record<string, string>) {
|
|
||||||
const references: Record<string, string> = {};
|
|
||||||
|
|
||||||
for (const [oldInput, newInput] of Object.entries(renames)) {
|
|
||||||
if (core.getInput(oldInput)) {
|
|
||||||
references[oldInput] = newInput;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Object.keys(references).length > 0) {
|
|
||||||
const list = Object.entries(references)
|
|
||||||
.map(([oldInput, newInput]) => `- "${oldInput}" -> "${newInput}"`)
|
|
||||||
.join("\n");
|
|
||||||
throw new Error(
|
|
||||||
`The following inputs have been renamed:\n${list}\nPlease update your workflow file.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveChangesetsCli(cwd: string) {
|
|
||||||
return require.resolve("@changesets/cli/bin.js", {
|
|
||||||
paths: [cwd],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ExecOptions extends Omit<ActionsExecOptions, "env"> {
|
|
||||||
env?: Record<string, string | undefined>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function execChangesetsCli(args: string[], options?: ExecOptions) {
|
|
||||||
return exec(
|
|
||||||
"node",
|
|
||||||
[resolveChangesetsCli(options?.cwd ?? process.cwd()), ...args],
|
|
||||||
options as ActionsExecOptions,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getExecOutputChangesetsCli(
|
|
||||||
args: string[],
|
|
||||||
options?: ExecOptions,
|
|
||||||
): Promise<ExecOutput> {
|
|
||||||
return getExecOutput(
|
|
||||||
"node",
|
|
||||||
[resolveChangesetsCli(options?.cwd ?? process.cwd()), ...args],
|
|
||||||
options as ActionsExecOptions,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function downloadArtifact(
|
|
||||||
tmpDir: string,
|
|
||||||
artifactId: number,
|
|
||||||
name: string,
|
|
||||||
) {
|
|
||||||
if (!Number.isInteger(artifactId) || artifactId <= 0) {
|
|
||||||
throw new Error(
|
|
||||||
`Invalid ${JSON.stringify(name)} artifact id: ${artifactId}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const downloadPath = path.join(tmpDir, `${name}-${artifactId}-${Date.now()}`);
|
|
||||||
const result = await artifact.downloadArtifact(artifactId, {
|
|
||||||
path: downloadPath,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!result.downloadPath) {
|
|
||||||
throw new Error(
|
|
||||||
`${JSON.stringify(name)} artifact download did not return a path for artifact ${artifactId}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.downloadPath;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
import * as core from "@actions/core";
|
|
||||||
import { GitHub } from "../github.ts";
|
|
||||||
import { runVersion } from "../run.ts";
|
|
||||||
import { getOptionalInput, getRequiredInput } from "../utils.ts";
|
|
||||||
|
|
||||||
try {
|
|
||||||
await main();
|
|
||||||
} catch (err) {
|
|
||||||
core.setFailed((err as Error).message);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
const githubToken = getRequiredInput("github-token");
|
|
||||||
const script = getOptionalInput("script");
|
|
||||||
const commitMessage = getRequiredInput("commit-message");
|
|
||||||
const prTitle = getRequiredInput("pr-title");
|
|
||||||
const prDraft = getOptionalInput("pr-draft");
|
|
||||||
const prBaseBranch = getOptionalInput("pr-base-branch");
|
|
||||||
const commitMode = getOptionalInput("commit-mode") ?? "git-cli";
|
|
||||||
const setupGitUser = core.getBooleanInput("setup-git-user");
|
|
||||||
|
|
||||||
// Validations
|
|
||||||
if (prDraft !== undefined && prDraft !== "always" && prDraft !== "create") {
|
|
||||||
throw new Error(`Invalid pr-draft input: ${prDraft}`);
|
|
||||||
}
|
|
||||||
if (commitMode !== "git-cli" && commitMode !== "github-api") {
|
|
||||||
throw new Error(`Invalid commit-mode input: ${commitMode}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the user needs to change the cwd, set `working-directory` in the step instead
|
|
||||||
const cwd = process.cwd();
|
|
||||||
|
|
||||||
const github = new GitHub({
|
|
||||||
cwd,
|
|
||||||
githubToken,
|
|
||||||
commitMode,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (setupGitUser) {
|
|
||||||
core.info("setting git user");
|
|
||||||
await github.setupUser();
|
|
||||||
}
|
|
||||||
|
|
||||||
const { pullRequestNumber } = await runVersion({
|
|
||||||
script,
|
|
||||||
github,
|
|
||||||
cwd,
|
|
||||||
prTitle,
|
|
||||||
commitMessage,
|
|
||||||
// TODO: Use neutral message for PR description
|
|
||||||
hasPublishScript: true,
|
|
||||||
prDraft,
|
|
||||||
branch: prBaseBranch,
|
|
||||||
});
|
|
||||||
|
|
||||||
core.setOutput("pr-number", String(pullRequestNumber));
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
# changesets/action/version
|
|
||||||
|
|
||||||
TODO
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
name: Changesets - Version
|
|
||||||
description: Version packages
|
|
||||||
runs:
|
|
||||||
using: node24
|
|
||||||
main: ../dist/version.js
|
|
||||||
inputs:
|
|
||||||
github-token:
|
|
||||||
description: "The GitHub token to use for authentication. Defaults to the GitHub-provided token."
|
|
||||||
required: false
|
|
||||||
default: ${{ github.token }}
|
|
||||||
script:
|
|
||||||
description: "The command to use to version packages"
|
|
||||||
required: false
|
|
||||||
commit-message:
|
|
||||||
description: "The commit message. Default to `Version Packages`"
|
|
||||||
required: false
|
|
||||||
default: "Version Packages"
|
|
||||||
pr-title:
|
|
||||||
description: "The pull request title. Default to `Version Packages`"
|
|
||||||
required: false
|
|
||||||
default: "Version Packages"
|
|
||||||
pr-draft:
|
|
||||||
description: "Controls draft PR behavior. Use 'create' to create new version PRs as draft, or 'always' to also convert existing version PRs back to draft when updating them."
|
|
||||||
required: false
|
|
||||||
pr-base-branch:
|
|
||||||
description: "Sets the base branch of the PR. Defaults to `github.ref_name`."
|
|
||||||
required: false
|
|
||||||
commit-mode:
|
|
||||||
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"
|
|
||||||
setup-git-user:
|
|
||||||
description: Sets up the git user for commits as `"github-actions[bot]"`. Default to `true`
|
|
||||||
required: false
|
|
||||||
default: true
|
|
||||||
outputs:
|
|
||||||
pr-number:
|
|
||||||
description: The pull request number that was created or updated
|
|
||||||
branding:
|
|
||||||
icon: package
|
|
||||||
color: blue
|
|
||||||
Reference in New Issue
Block a user