diff --git a/action.yml b/action.yml index d56202f..c384c55 100644 --- a/action.yml +++ b/action.yml @@ -12,21 +12,21 @@ inputs: description: Enable or disable publishing to package registries. When set to false, releases are only created on GitHub. default: true required: false - commit: - description: Enable or disable commiting and pushing changes made by the action. + push: + description: Enable or disable pushing changes made by the action. default: true required: false - commit_name: + name: description: User name to use when pushing to GitHub. default: github-actions[bot] required: false - commit_email: + email: description: Email to use when pushing to GitHub. default: github-actions[bot]@users.noreply.github.com required: false - commit_message: - description: Commit message to use when pushing to GitHub. - default: 'ci: release' + message: + description: Commit message to use when bumping package.json. + default: 'ci(release): %s' required: false runs: using: node12 diff --git a/dist/index.js b/dist/index.js index 05f63bf..9d466c3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6947,7 +6947,7 @@ function wrappy (fn, cb) { /***/ }), -/***/ 648: +/***/ 986: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; @@ -6966,18 +6966,18 @@ var external_fs_ = __webpack_require__(747); var external_path_ = __webpack_require__(622); var external_path_default = /*#__PURE__*/__webpack_require__.n(external_path_); -// CONCATENATED MODULE: ./src/config.ts +// CONCATENATED MODULE: ./src/npm-config.ts const npmrc = external_path_default().resolve(process.env['RUNNER_TEMP'] || process.cwd(), '.npmrc'); -async function npmConfigRegistry(registryUrl, token) { +async function npmConfig(registryUrl, token, message) { if (!registryUrl.endsWith('/')) { registryUrl += '/'; } core.info(`Setup NPM registry URL: ${registryUrl} on ${npmrc}`); - registryUrl = registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}'; - await external_fs_.promises.writeFile(npmrc, registryUrl, 'utf-8'); + await external_fs_.promises.writeFile(npmrc, (`${registryUrl.replace(/(^\w+:|^)/, '')}:_authToken=\${NODE_AUTH_TOKEN}\n` + + `message=${message}\n`), 'utf-8'); return { NPM_CONFIG_USERCONFIG: npmrc, NODE_AUTH_TOKEN: token @@ -6998,8 +6998,9 @@ async function npmConfigRegistry(registryUrl, token) { const githubToken = core.getInput('github_token', { required: true }); const publish = core.getInput('publish') !== 'false'; const push = core.getInput('push') !== 'false'; - const gitUserName = core.getInput('git_user_name'); - const gitUserEmail = core.getInput('git_user_email'); + const name = core.getInput('name'); + const email = core.getInput('email'); + const message = core.getInput('message'); let publishToGithub; let publishToNPM; let privatePackage; @@ -7057,8 +7058,10 @@ async function npmConfigRegistry(registryUrl, token) { cliPath = `node_modules/${cli}/${JSON .parse((await external_fs_.promises.readFile(`node_modules/${cli}/package.json`)).toString()) .bin[cli]}`; + await exec.exec('git', ['config', '--global', 'user.name', name]); + await exec.exec('git', ['config', '--global', 'user.email', email]); core.info(`Creating release on GitHub${publishToGithub ? ' and publishing to GitHub registry' : ''}...`); - await release(cliPath, true, publishToGithub, { + await release(cliPath, true, publishToGithub, message, { ...process.env, NPM_CONFIG_REGISTRY: `https://npm.pkg.github.com`, NPM_TOKEN: githubToken, @@ -7067,7 +7070,7 @@ async function npmConfigRegistry(registryUrl, token) { core.info('Release available on GitHub'); publishToGithub && core.info('Package available on GitHub registry'); publishToNPM && core.info('Publishing to NPM registry...'); - await release(cliPath, false, publishToNPM, { + await release(cliPath, false, publishToNPM, message, { ...process.env, NPM_CONFIG_REGISTRY: 'https://registry.npmjs.org', NPM_TOKEN: npmToken, @@ -7076,8 +7079,6 @@ async function npmConfigRegistry(registryUrl, token) { publishToNPM && core.info('Package available on NPM registry'); if (push) { core.info('Pushing changes to GitHub repository...'); - await exec.exec('git', ['config', '--global', 'user.name', gitUserName]); - await exec.exec('git', ['config', '--global', 'user.email', gitUserEmail]); await exec.exec('git', ['push']); core.info('GitHub repository up to date'); } @@ -7086,7 +7087,7 @@ async function npmConfigRegistry(registryUrl, token) { core.setFailed(error.message); } })(); -async function lernaRelease(path, release, publish, env = {}) { +async function lernaRelease(path, release, publish, message, env = {}) { if (release) { await exec.exec('node', [ path, @@ -7097,7 +7098,7 @@ async function lernaRelease(path, release, publish, env = {}) { ], { env }); } if (publish) { - const npmEnv = await npmConfigRegistry(env.NPM_CONFIG_REGISTRY, env.NPM_TOKEN); + const npmEnv = await npmConfig(env.NPM_CONFIG_REGISTRY, env.NPM_TOKEN, message); await exec.exec('node', [ path, 'publish', @@ -7110,7 +7111,7 @@ async function lernaRelease(path, release, publish, env = {}) { }); } } -async function semanticRelease(path, release, publish, env = {}) { +async function semanticRelease(path, release, publish, message, env = {}) { if (release) { await exec.exec('node', [ path, @@ -7120,7 +7121,7 @@ async function semanticRelease(path, release, publish, env = {}) { ], { env }); } if (publish) { - const npmEnv = await npmConfigRegistry(env.NPM_CONFIG_REGISTRY, env.NPM_TOKEN); + const npmEnv = await npmConfig(env.NPM_CONFIG_REGISTRY, env.NPM_TOKEN, message); await exec.exec('yarn', [ 'publish', '--non-interactive', @@ -7331,6 +7332,6 @@ module.exports = require("zlib");; /******/ // module exports must be returned from runtime so entry inlining is disabled /******/ // startup /******/ // Load entry module and return exports -/******/ return __webpack_require__(648); +/******/ return __webpack_require__(986); /******/ })() ; \ No newline at end of file diff --git a/readme.md b/readme.md index a7564f9..0ff8381 100644 --- a/readme.md +++ b/readme.md @@ -58,26 +58,26 @@ jobs: Enable or disable publishing to package registries. When set to false, only releases are created on GitHub. -### `commit` +### `push` `boolean` *(optional, default `true`)* -Enable or disable commiting and pushing changes made by the action. +Enable or disable pushing changes made by the action. -## `commit_name` +## `name` `string` *(optional, default: `'github-actions[bot]'`)* User name to use when pushing to GitHub. -## `commit_email` +## `email` `string` *(optional, default: `'github-actions[bot]@users.noreply.github.com'`)* Email to use when pushing to GitHub. -## `commit_message` +## `message` `string` *(optional, default: `'ci: release'`)* -Commit message to use when pushing to GitHub. +Commit message to use when bumping package.json. diff --git a/release.commit.js b/release.commit.js deleted file mode 100644 index e69de29..0000000 diff --git a/src/index.ts b/src/index.ts index 3e26839..06f66dc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ import * as core from '@actions/core' import * as exec from '@actions/exec' import * as github from '@actions/github' import { promises as fs } from 'fs' -import { npmConfigRegistry } from './config' +import { npmConfig } from './npm-config' (async () => { try { @@ -12,8 +12,9 @@ import { npmConfigRegistry } from './config' const githubToken: string = core.getInput('github_token', { required: true }) const publish: boolean = core.getInput('publish') !== 'false' const push: boolean = core.getInput('push') !== 'false' - const gitUserName: string = core.getInput('git_user_name') - const gitUserEmail: string = core.getInput('git_user_email') + const name: string = core.getInput('name') + const email: string = core.getInput('email') + const message: string = core.getInput('message') let publishToGithub: boolean let publishToNPM: boolean @@ -25,6 +26,7 @@ import { npmConfigRegistry } from './config' path: string, release: boolean, publish: boolean, + message: string, env?: { [variable: string]: string } ) => Promise @@ -100,11 +102,14 @@ import { npmConfigRegistry } from './config' .bin[cli] }` + await exec.exec('git', ['config', '--global', 'user.name', name]) + await exec.exec('git', ['config', '--global', 'user.email', email]) + core.info( `Creating release on GitHub${publishToGithub ? ' and publishing to GitHub registry' : ''}...` ) - await release(cliPath, true, publishToGithub, { + await release(cliPath, true, publishToGithub, message, { ...process.env, NPM_CONFIG_REGISTRY: `https://npm.pkg.github.com`, NPM_TOKEN: githubToken, @@ -123,7 +128,7 @@ import { npmConfigRegistry } from './config' 'Publishing to NPM registry...' ) - await release(cliPath, false, publishToNPM, { + await release(cliPath, false, publishToNPM, message, { ...process.env, NPM_CONFIG_REGISTRY: 'https://registry.npmjs.org', NPM_TOKEN: npmToken, @@ -139,8 +144,6 @@ import { npmConfigRegistry } from './config' 'Pushing changes to GitHub repository...' ) - await exec.exec('git', ['config', '--global', 'user.name', gitUserName]) - await exec.exec('git', ['config', '--global', 'user.email', gitUserEmail]) await exec.exec('git', ['push']) core.info( @@ -156,6 +159,7 @@ async function lernaRelease( path: string, release: boolean, publish: boolean, + message: string, env: { [variable: string]: string } = {} ): Promise { if (release) { @@ -169,9 +173,10 @@ async function lernaRelease( } if (publish) { - const npmEnv = await npmConfigRegistry( + const npmEnv = await npmConfig( env.NPM_CONFIG_REGISTRY, - env.NPM_TOKEN + env.NPM_TOKEN, + message ) await exec.exec('node', [ @@ -191,6 +196,7 @@ async function semanticRelease( path: string, release: boolean, publish: boolean, + message: string, env: { [variable: string]: string } = {} ): Promise { if (release) { @@ -203,9 +209,10 @@ async function semanticRelease( } if (publish) { - const npmEnv = await npmConfigRegistry( + const npmEnv = await npmConfig( env.NPM_CONFIG_REGISTRY, - env.NPM_TOKEN + env.NPM_TOKEN, + message ) await exec.exec('yarn', [ diff --git a/src/config.ts b/src/npm-config.ts similarity index 63% rename from src/config.ts rename to src/npm-config.ts index 6fc861b..5078cd3 100644 --- a/src/config.ts +++ b/src/npm-config.ts @@ -7,9 +7,10 @@ const npmrc = path.resolve( '.npmrc' ) -export async function npmConfigRegistry( - registryUrl: string, - token: string +export async function npmConfig( + registryUrl: string, + token: string, + message: string ): Promise { if (!registryUrl.endsWith('/')) { registryUrl += '/' @@ -17,11 +18,13 @@ export async function npmConfigRegistry( core.info(`Setup NPM registry URL: ${registryUrl} on ${npmrc}`) - registryUrl = registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}' - await fs.writeFile(npmrc, registryUrl, 'utf-8') + await fs.writeFile(npmrc, ( + `${registryUrl.replace(/(^\w+:|^)/, '')}:_authToken=\${NODE_AUTH_TOKEN}\n` + + `message=${message}\n` + ), 'utf-8') return { NPM_CONFIG_USERCONFIG: npmrc, NODE_AUTH_TOKEN: token } -} \ No newline at end of file +}