Skip to content

Commit

Permalink
test: release package workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
buqiyuan committed Feb 1, 2024
1 parent da04b10 commit d3ee0dd
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/release-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ jobs:
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile
run: |
pnpm install --frozen-lockfile
result=$(npx tsx scripts/filterPackages.mts)
echo filters=$result >> $GITHUB_ENV
# run: pnpm run --filter \"./packages/**\" build

- name: Publish 🚀
shell: bash
run: pnpm publish packages/* --access public --no-git-checks
run: pnpm publish packages/{${{ env.filters }}} --access public --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"gen:changelog": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md",
"reinstall": "rimraf pnpm-lock.yaml && rimraf package.lock.json && rimraf node_modules && npm run bootstrap",
"test:gzip": "npx http-server dist --cors --gzip -c-1",
"test:br": "npx http-server dist --cors --brotli -c-1"
"test:br": "npx http-server dist --cors --brotli -c-1",
"p": "pnpm publish --filter \"./packages/{test,vite-plugin-msw}\" --access public --no-git-checks"
},
"dependencies": {
"@admin-pkg/vite-plugin-msw": "workspace:*",
Expand Down
Empty file added packages/test/index.js
Empty file.
11 changes: 11 additions & 0 deletions packages/test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@admin-pkg/test",
"version": "1.0.2",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
39 changes: 39 additions & 0 deletions scripts/filterPackages.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import fs from 'node:fs';
import { exec } from 'child_process';

const folderPath = 'packages';

const items = fs.readdirSync(folderPath);

async function filterPackages() {
const promises = items.map(async (name) => {
const localPkgInfo = await runCommand(`npm view ./packages/${name} name version --json`);
const remoteVersion = await runCommand(`npm view ${localPkgInfo.name} version`);

if (localPkgInfo.version !== remoteVersion) {
return name;
}
return null;
});

const packages = await Promise.all(promises);
return packages.filter(Boolean).join(',');
}

function runCommand(command) {
return new Promise<any>((resolve, reject) => {
exec(command, (error, stdout) => {
if (error) {
reject(error);
} else {
try {
resolve(JSON.parse(stdout.trim()));
} catch (error) {
resolve(stdout.trim());
}
}
});
});
}

console.log(await filterPackages());

0 comments on commit d3ee0dd

Please sign in to comment.