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

Add support for publishing a package that isn't at repo root #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ you'll need to configure that workflow yourself. You can look to the
* All other changes will increment the patch version.
* Publish to npm using the configured token.
* Push a tag for the new version to GitHub.

### Additional Configuration

* If your `package.json` is not in the repo's root directory, set `PACKAGE_PATH` env variable and the publish commands will be run from that package directory.
```
- name: Publish
uses: mikeal/merge-release@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
PACKAGE_PATH: ./packages/my-package
```
4 changes: 3 additions & 1 deletion merge-release-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const get = bent('json', process.env.NPM_REGISTRY_URL || 'https://registry.npmjs

const event = JSON.parse(fs.readFileSync('/github/workflow/event.json').toString())

let pkg = require(path.join(process.cwd(), 'package.json'))
let packagePath = process.env.PACKAGE_PATH || process.cwd()
let pkg = require(path.join(packagePath, 'package.json'))

const run = async () => {
if (!process.env.NPM_AUTH_TOKEN) throw new Error('Merge-release requires NPM_AUTH_TOKEN')
Expand Down Expand Up @@ -52,6 +53,7 @@ const run = async () => {

const exec = str => process.stdout.write(execSync(str))

exec(`cd ${packagePath}`)
let current = execSync(`npm view ${pkg.name} version`).toString()
exec(`npm version --allow-same-version=true --git-tag-version=false ${current} `)
console.log('current:', current, '/', 'version:', version)
Expand Down