-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: workflow and script for pkg.pr.new
- Loading branch information
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Publish Preview Release | ||
on: | ||
pull_request: | ||
|
||
jobs: | ||
preview-release: | ||
if: github.repository == 'sveltejs/cli' | ||
timeout-minutes: 30 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: checkout code repository | ||
uses: actions/checkout@v4 | ||
|
||
- uses: pnpm/action-setup@v4 | ||
|
||
- name: setup node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: pnpm | ||
|
||
- name: Run changed-files | ||
id: changed-files | ||
uses: tj-actions/changed-files@v44 | ||
with: | ||
separator: ' ' | ||
dir_names: 'true' | ||
dir_names_max_depth: '2' # truncates the path to adders/X | ||
files: | | ||
packages/** | ||
- name: install dependencies | ||
run: pnpm install | ||
|
||
- name: build | ||
run: pnpm build | ||
|
||
- name: publish preview | ||
if: ${{ steps.changed-files.outputs.all_changed_files_count > 0 }} | ||
env: | ||
CHANGED_DIRS: ${{ steps.changed-files.outputs.all_changed_files }} | ||
run: | | ||
node scripts/get-deps-to-publish.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* This tool is used by the pr ci to determine the packages that need to be published to the pkg-pr-new registry. | ||
* In order to avoid situations where only @svelte-cli/core would be published, because it's the only modified package, | ||
* this tool will also determine the dependent packages and also publish those. | ||
* PR: https://github.com/svelte-add/svelte-add/pull/408 | ||
*/ | ||
|
||
// @ts-check | ||
import { execSync } from 'node:child_process'; | ||
import { relative, join } from 'node:path'; | ||
import { existsSync } from 'node:fs'; | ||
|
||
if (!process.env.CHANGED_DIRS) throw new Error('CHANGED_DIRS is missing'); | ||
|
||
const json = execSync(`pnpm -r list --only-projects --json`).toString('utf8'); | ||
const repoPackages = | ||
/** @type {Array<import("../packages/core/utils/common.ts").Package & { path: string, private: boolean, peerDependencies?: Record<string, string> }>} */ ( | ||
JSON.parse(json) | ||
); | ||
|
||
const modifiedDirs = process.env.CHANGED_DIRS.split(' ') | ||
.map((dir) => (dir.startsWith('packages/adders') ? 'packages/adders' : dir)) | ||
.filter((dir) => existsSync(join(dir, 'package.json'))); | ||
const packagesToPublish = new Set(modifiedDirs); | ||
|
||
// keep looping until we've acquired all dependents | ||
let prev = 0; | ||
while (packagesToPublish.size !== prev) { | ||
prev = packagesToPublish.size; | ||
for (const pkg of packagesToPublish) { | ||
const dependents = getDependents(pkg); | ||
dependents.forEach((dep) => packagesToPublish.add(dep)); | ||
} | ||
} | ||
|
||
// publishes packages to pkg-pr-new | ||
const paths = Array.from(packagesToPublish) | ||
// remove all private packages | ||
.filter((dir) => repoPackages.find((pkg) => pkg.path.endsWith(dir))?.private === false) | ||
.join(' '); | ||
|
||
execSync(`pnpm dlx [email protected] publish --pnpm ${paths}`, { stdio: 'inherit' }); | ||
|
||
/** | ||
* Finds all dependents and returns their relative paths. | ||
* @param {string} path | ||
* @return {string[]} | ||
*/ | ||
function getDependents(path) { | ||
const pkg = repoPackages.find((pkg) => pkg.path.endsWith(path)); | ||
if (!pkg) throw new Error(`package ${path} doesn't exist in this repo`); | ||
|
||
const dependents = repoPackages.filter( | ||
(dep) => | ||
!dep.private && | ||
(dep.dependencies?.[pkg.name] || | ||
dep.devDependencies?.[pkg.name] || | ||
dep.peerDependencies?.[pkg.name]), | ||
); | ||
return dependents.map((dep) => relative('.', dep.path)); | ||
} |