Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add pkg.pr.new #2167

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
65 changes: 65 additions & 0 deletions .github/workflows/pkg.pr.new.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Publish any Pull Requests

on:
workflow_run:
workflows: ["Preview Build"]
types:
- completed

jobs:
on-success:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Print a message
run: echo 'The triggering workflow passed'

- name: Checkout code
uses: actions/checkout@v4

- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: 18
registry-url: "https://registry.npmjs.org/"

- name: Install rust toolchain
uses: actions-rs/toolchain@v1
with:
target: wasm32-wasi

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
# ref: <root>/package.packageManager
version: 8.4.0

# cv: ./ci.yml
- name: Setup cargo cache
uses: actions/cache@v3
with:
# ref: https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci
path: |
~/.cargo/.crates.toml
~/.cargo/.crates2.json
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ubuntu-latest-cargo-store-node18.x-${{ hashFiles('**/Cargo.lock') }} # cv: ./ci.yml

- name: Install dependencies
run: pnpm install

- name: Build
run: pnpm build

- name: Prepare examples
run: npx esno scripts/prepare-examples.ts

- name: Publish
run: npx -p @wuxh/[email protected] \
Wxh16144 marked this conversation as resolved.
Show resolved Hide resolved
pkg-pr-new publish '.' './suites/theme-mobile' \
--template './examples/*' \
--pnpm
52 changes: 52 additions & 0 deletions scripts/prepare-examples.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import fg from 'fast-glob';
import fs from 'fs';
import path from 'path';

const examples = fg.sync(['examples/**/package.json'], {
cwd: process.cwd(),
onlyFiles: true,
ignore: ['**/node_modules/**', '.git'],
});

function modifyPackageJson(pkgJson: any) {
return Object.assign({}, pkgJson, {
scripts: {
// ...pkgJson.scripts, // ignore original scripts
dev: 'dumi dev',
start: 'npm run dev',
build: 'dumi build',
preview: 'dumi preview',
setup: 'dumi setup',
},
dependencies: {
...pkgJson.dependencies,
dumi: 'workspace:*',
},
});
}

function main() {
for (const example of examples) {
const pkgJson = require(example);
const newPkgJson = modifyPackageJson(pkgJson);

const rewritePath = process.env.CI
? example
: path.join(
path.dirname(example),
'.dumi/tmp', // ignore .dumi/tmp
path.basename(example, '.json') + '_rewrite.json',
);

if (!fs.existsSync(path.dirname(rewritePath))) {
fs.mkdirSync(path.dirname(rewritePath), { recursive: true });
}

fs.writeFileSync(rewritePath, JSON.stringify(newPkgJson, null, 2));
}
}

// \\\\\\\\\\\
// \\\ main \\
// \\\\\\\\\\\
main();
Loading