-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
59 additions
and
110 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
This file was deleted.
Oops, something went wrong.
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,48 @@ | ||
const child_process = require('child_process'); | ||
const fs = require('fs').promises; | ||
const path = require('path'); | ||
|
||
module.exports = async ({ github, context, core }) => { | ||
core.info('Preparing npm publish'); | ||
const hash = context.sha.substring(0, 8); | ||
const packageJson = JSON.parse(await fs.readFile('package.json')); | ||
const version = packageJson.version; | ||
const tag = `v${version}`; | ||
packageJson.version += `+${hash}`; | ||
await fs.writeFile('package.json', `${JSON.stringify(packageJson, null, 2)}\n`); | ||
await fs.writeFile('.npmrc', '//registry.npmjs.org/:_authToken=' + process.env.NPM_TOKEN); | ||
core.info(`Publish ${packageJson.version} to npm`); | ||
try { | ||
await new Promise((resolve, reject) => { | ||
child_process.exec('npm publish', async (err) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
core.info(`Creating release ${tag}`); | ||
const release = await github.rest.repos.createRelease({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
name: tag, | ||
tag_name: tag, | ||
body: `[Changelog](https://github.com/FredrikNoren/ungit/blob/master/CHANGELOG.md#${version.replace(/\./g, '')})` | ||
}); | ||
const filePaths = await fs.readdir('dist'); | ||
for (let i = 0; i < filePaths.length; i++) { | ||
const filePath = path.join('dist', filePaths[i]); | ||
core.info(`Uploading release asset ${filePath}`); | ||
await github.rest.repos.uploadReleaseAsset({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
release_id: release.data.id, | ||
name: path.basename(filePath).replace('ungit', `ungit-${version}`), | ||
data: await fs.readFile(filePath) | ||
}); | ||
} | ||
} catch (e) { | ||
core.info(`npm publish failed: ${e}`); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.