-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ci): integrate changeset & add github action to publish (#7)
- Loading branch information
Showing
26 changed files
with
1,829 additions
and
133 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,8 @@ | ||
# Changesets | ||
|
||
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works | ||
with multi-package repos, or single-package repos to help you version and publish your code. You can | ||
find the full documentation for it [in our repository](https://github.com/changesets/changesets) | ||
|
||
We have a quick list of common questions to get you started engaging with this project in | ||
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) |
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,14 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": [ | ||
"@modelscope-studio/changelog", | ||
{ "repo": "modelscope/modelscope-studio" } | ||
], | ||
"commit": false, | ||
"fixed": [], | ||
"linked": [], | ||
"access": "restricted", | ||
"baseBranch": "main", | ||
"updateInternalDependencies": "patch", | ||
"ignore": [] | ||
} |
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
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,53 @@ | ||
name: publish | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
env: | ||
CI: true | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }}-publish | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build-n-publish: | ||
timeout-minutes: 15 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Code Repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.9' | ||
- name: Install Python Dependencies | ||
run: pip install gradio twine build | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
- name: Install Pnpm | ||
run: npm i pnpm@latest -g | ||
- name: Install Node Dependencies | ||
run: pnpm install | ||
- name: Create Release Pull Request to Update Versions | ||
id: changesets | ||
uses: changesets/action@v1 | ||
with: | ||
version: pnpm run ci:version | ||
title: 'chore: update versions' | ||
commit: 'chore: update versions' | ||
publish: pnpm run ci:create-tag-n-release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
REPO: ${{ github.event.repository.name }} | ||
OWNER: ${{ github.repository_owner }} | ||
- name: Build Packages and Publish to PyPI | ||
if: steps.changesets.outputs.hasChangesets != 'true' | ||
run: pnpm run ci:publish | ||
env: | ||
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} |
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,31 @@ | ||
{ | ||
"name": "@modelscope-studio/changelog", | ||
"version": "0.1.0", | ||
"private": false, | ||
"description": "ModelScope Studio Changelog", | ||
"repository": "[email protected]:modelscope/modelscope-studio.git", | ||
"license": "Apache-2.0", | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.cjs", | ||
"types": "./dist/index.d.ts" | ||
} | ||
}, | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsup" | ||
}, | ||
"dependencies": { | ||
"@changesets/get-github-info": "^0.6.0", | ||
"@manypkg/get-packages": "^2.2.0", | ||
"detect-indent": "^7.0.1" | ||
}, | ||
"devDependencies": { | ||
"@changesets/types": "^6.0.0", | ||
"@types/node": "^20.11.24", | ||
"tsup": "^8.0.2" | ||
} | ||
} |
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,118 @@ | ||
import { getPackagesSync, type Package } from '@manypkg/get-packages'; | ||
import detectIndent from 'detect-indent'; | ||
import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'fs'; | ||
import { join } from 'path'; | ||
|
||
import { ChangesetMeta, ChangesetMetaCollection } from './type'; | ||
|
||
const pkg_meta = getPackagesSync(process.cwd()); | ||
|
||
function updatePackageJson(pkgJsonPath: string, pkgJson: any) { | ||
const pkgRaw = readFileSync(pkgJsonPath, 'utf-8'); | ||
const indent = detectIndent(pkgRaw).indent || ' '; | ||
const stringified = | ||
JSON.stringify(pkgJson, null, indent) + (pkgRaw.endsWith('\n') ? '\n' : ''); | ||
|
||
writeFileSync(pkgJsonPath, stringified); | ||
} | ||
|
||
function run() { | ||
if (!existsSync(join(pkg_meta.rootDir, '.changeset', '_changelog.json'))) { | ||
console.warn('No changesets to process'); | ||
return; | ||
} | ||
|
||
const { _handled, ...packages } = JSON.parse( | ||
readFileSync( | ||
join(pkg_meta.rootDir, '.changeset', '_changelog.json'), | ||
'utf-8' | ||
) | ||
) as ChangesetMetaCollection; | ||
|
||
const all_packages = pkg_meta.packages.reduce( | ||
(acc, pkg) => { | ||
acc[pkg.packageJson.name] = pkg; | ||
return acc; | ||
}, | ||
{} as Record<string, Package> | ||
); | ||
|
||
const version = pkg_meta.rootPackage?.packageJson.version; | ||
if (!version) { | ||
throw new Error('No root package version found'); | ||
} | ||
|
||
for (const pkg_name in packages) { | ||
const { dir, chore, feat, fix, current_changelog } = packages[ | ||
pkg_name | ||
] as ChangesetMeta; | ||
|
||
const features = feat.map((f) => `- ${f.summary}`); | ||
const fixes = fix.map((f) => `- ${f.summary}`); | ||
const others = chore.map((f) => `- ${f.summary}`); | ||
|
||
const release_notes = ( | ||
[ | ||
[features, '### Features'], | ||
[fixes, '### Fixes'], | ||
[others, '### Misc Changes'], | ||
] as const | ||
) | ||
.filter(([s]) => s.length > 0) | ||
.map(([lines, title]) => { | ||
return `${title}\n\n${lines.join('\n')}`; | ||
}) | ||
.join('\n\n'); | ||
|
||
const new_changelog = `# ${pkg_name} | ||
## ${version} | ||
${release_notes} | ||
${current_changelog.replace(`# ${pkg_name}`, '').trim()} | ||
`.trim(); | ||
writeFileSync(join(dir, 'CHANGELOG.md'), new_changelog); | ||
} | ||
|
||
bump_packages(version); | ||
|
||
unlinkSync(join(pkg_meta.rootDir, '.changeset', '_changelog.json')); | ||
|
||
function bump_packages(newVersion: string) { | ||
for (const pkg_name in all_packages) { | ||
const { dir, packageJson } = all_packages[pkg_name]; | ||
const newPackageJson = { | ||
...packageJson, | ||
}; | ||
newPackageJson.version = newVersion; | ||
updatePackageJson(join(dir, 'package.json'), newPackageJson); | ||
if (packages[pkg_name]) { | ||
continue; | ||
} | ||
const current_changelog_path = join(dir, 'CHANGELOG.md'); | ||
const current_changelog = existsSync(current_changelog_path) | ||
? readFileSync(current_changelog_path, 'utf-8') | ||
: ''; | ||
|
||
const new_changelog = `# ${pkg_name} | ||
## ${version} | ||
No significant changes to this package were made in this release. | ||
${current_changelog.replace(`# ${pkg_name}`, '').trim()} | ||
`.trim(); | ||
writeFileSync(join(dir, 'CHANGELOG.md'), new_changelog); | ||
} | ||
|
||
const pyproject_path = join(pkg_meta.rootDir, 'pyproject.toml'); | ||
const pyproject = readFileSync(pyproject_path, 'utf-8'); | ||
writeFileSync( | ||
pyproject_path, | ||
pyproject.replace(/version = ".+"/, `version = "${newVersion}"`) | ||
); | ||
} | ||
} | ||
|
||
run(); |
Oops, something went wrong.