Add script to publish tarballs to npm (#86)

* Add script to publish tarballs

* Add CI check for the release:npm script

* Move release script first

* Remove console.log

* Create dist folder

* Fix resolve in npm script

* Cleanup dist after test publish

* debug

* git checkout

* Test in separate job for simplicity

* Fix deps

* Publish npm in dry run mode

* mkdir pkgs

* Remove sha256 files from dist

* Remove skip_existing

* Remove --dry-run
This commit is contained in:
Jeremy Tuloup 2021-01-22 16:57:20 +01:00 committed by GitHub
parent 46270509e9
commit 1414c011c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 89 additions and 11 deletions

View File

@ -84,17 +84,25 @@ jobs:
python setup.py sdist bdist_wheel
- name: Build npm distributions
run: |
mkdir pkgs
jlpm lerna exec -- npm pack
cp packages/*/*.tgz dist
cp packages/*/*.tgz pkgs
- name: Build checksum file
run: |
cd dist
sha256sum * | tee SHA256SUMS
cd ../pkgs
sha256sum * | tee SHA256SUMS
- name: Upload distributions
uses: actions/upload-artifact@v2
with:
name: dist ${{ github.run_number }}
path: ./dist
- name: Upload distributions
uses: actions/upload-artifact@v2
with:
name: pkgs ${{ github.run_number }}
path: ./pkgs
install:
runs-on: ${{ matrix.os }}-latest

View File

@ -11,7 +11,7 @@ defaults:
shell: bash -l {0}
jobs:
scripts:
versioning:
runs-on: ubuntu-latest
steps:
- name: Checkout
@ -59,3 +59,25 @@ jobs:
- name: Major Release
run: |
jlpm release:bump major --force
npm:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
architecture: 'x64'
- name: Install dependencies
run: |
python -m pip install -U jupyterlab~=3.0 jupyter_packaging~=0.7.9 pip
jlpm
jlpm run build
- name: Publish to npm in dry-run mode
run: |
mkdir dist
jlpm lerna exec -- npm pack
cp packages/*/*.tgz dist
jlpm release:npm --dist ./dist --dry-run

View File

@ -84,17 +84,25 @@ jobs:
python setup.py sdist bdist_wheel
- name: Build npm distributions
run: |
mkdir pkgs
jlpm lerna exec -- npm pack
cp packages/*/*.tgz dist
cp packages/*/*.tgz pkgs
- name: Build checksum file
run: |
cd dist
sha256sum * | tee SHA256SUMS
cd ../pkgs
sha256sum * | tee SHA256SUMS
- name: Upload distributions
uses: actions/upload-artifact@v2
with:
name: dist ${{ github.run_number }}
path: ./dist
- name: Upload distributions
uses: actions/upload-artifact@v2
with:
name: pkgs ${{ github.run_number }}
path: ./pkgs
install:
runs-on: ${{ matrix.os }}-latest
@ -156,29 +164,39 @@ jobs:
- uses: actions/download-artifact@v2
with:
name: dist ${{ github.run_number }}
path: ./tmp
- name: Copy to ./dist
path: ./dist
- name: Cleanup dist
run: |
mkdir dist/
cp ./tmp/jupyterlab-classic*.tar.gz ./tmp/jupyterlab_classic*.whl dist
ls dist
rm dist/SHA256SUMS
- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip_existing: true
- name: Install Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
architecture: 'x64'
- name: Install dependencies
run: |
python -m pip install -U jupyterlab~=3.0 jupyter_packaging~=0.7.9 pip
jlpm
jlpm run build
- uses: actions/setup-node@v2
with:
node-version: '14.x'
registry-url: 'https://registry.npmjs.org'
- uses: actions/download-artifact@v2
with:
name: pkgs ${{ github.run_number }}
path: ./pkgs
- name: Publish to npm
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
# jlpm
# jlpm run lerna publish from-package --yes --registry "//registry.npmjs.org/:_authToken=${NPM_TOKEN}"
jlpm release:npm --dist ./pkgs
- name: Get the current tag
id: current_tag
run: |

View File

@ -0,0 +1,29 @@
import { readdirSync } from 'fs';
import { resolve } from 'path';
import { run } from '@jupyterlab/buildutils';
import commander from 'commander';
commander
.description('Publish packages to npm')
.option(
'--dist <path>',
'The path to the directory with the package tarballs'
)
.option('--dry-run', 'Run in dry-run mode')
.action((options: any) => {
const dryRun = options.dryRun ?? false;
const distDir = resolve(options.dist);
const files = readdirSync(distDir);
files.forEach(file => {
if (!file.endsWith('.tgz')) {
return;
}
const tarball = resolve(distDir, file);
run(`npm publish ${tarball} ${dryRun ? '--dry-run' : ''}`);
});
});
commander.parse(process.argv);

View File

@ -29,6 +29,7 @@
"prettier:check": "prettier --list-different \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"",
"publish": "yarn run clean && yarn run build && lerna publish",
"release:bump": "node ./buildutils/lib/release-bump.js",
"release:npm": "node ./buildutils/lib/release-npm.js",
"release:patch": "node ./buildutils/lib/release-patch.js",
"test": "lerna run test",
"update:dependency": "node ./node_modules/@jupyterlab/buildutils/lib/update-dependency.js --lerna"