-
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.
* Prepare version 1.5.19 * move npm publish to GitHub Action
- Loading branch information
Showing
7 changed files
with
68 additions
and
115 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,41 @@ | ||
const fs = require('fs').promises; | ||
const path = require('path'); | ||
|
||
module.exports = async ({ github, context, core, exec }) => { | ||
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`); | ||
if ((await exec.exec('npm publish')) != 0) { | ||
core.info('npm publish failed.'); | ||
return; | ||
} | ||
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), | ||
}); | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.