Skip to content

Commit 7d38383

Browse files
fix!: pushing changes to github
1 parent af4b09b commit 7d38383

File tree

6 files changed

+57
-46
lines changed

6 files changed

+57
-46
lines changed

action.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ inputs:
1212
description: Enable or disable publishing to package registries. When set to false, releases are only created on GitHub.
1313
default: true
1414
required: false
15-
commit:
16-
description: Enable or disable commiting and pushing changes made by the action.
15+
push:
16+
description: Enable or disable pushing changes made by the action.
1717
default: true
1818
required: false
19-
commit_name:
19+
name:
2020
description: User name to use when pushing to GitHub.
2121
default: github-actions[bot]
2222
required: false
23-
commit_email:
23+
email:
2424
description: Email to use when pushing to GitHub.
2525
default: github-actions[bot]@users.noreply.github.com
2626
required: false
27-
commit_message:
28-
description: Commit message to use when pushing to GitHub.
29-
default: 'ci: release'
27+
message:
28+
description: Commit message to use when bumping package.json.
29+
default: 'ci(release): %s'
3030
required: false
3131
runs:
3232
using: node12

dist/index.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6947,7 +6947,7 @@ function wrappy (fn, cb) {
69476947

69486948
/***/ }),
69496949

6950-
/***/ 648:
6950+
/***/ 986:
69516951
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
69526952

69536953
"use strict";
@@ -6966,18 +6966,18 @@ var external_fs_ = __webpack_require__(747);
69666966
var external_path_ = __webpack_require__(622);
69676967
var external_path_default = /*#__PURE__*/__webpack_require__.n(external_path_);
69686968

6969-
// CONCATENATED MODULE: ./src/config.ts
6969+
// CONCATENATED MODULE: ./src/npm-config.ts
69706970

69716971

69726972

69736973
const npmrc = external_path_default().resolve(process.env['RUNNER_TEMP'] || process.cwd(), '.npmrc');
6974-
async function npmConfigRegistry(registryUrl, token) {
6974+
async function npmConfig(registryUrl, token, message) {
69756975
if (!registryUrl.endsWith('/')) {
69766976
registryUrl += '/';
69776977
}
69786978
core.info(`Setup NPM registry URL: ${registryUrl} on ${npmrc}`);
6979-
registryUrl = registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}';
6980-
await external_fs_.promises.writeFile(npmrc, registryUrl, 'utf-8');
6979+
await external_fs_.promises.writeFile(npmrc, (`${registryUrl.replace(/(^\w+:|^)/, '')}:_authToken=\${NODE_AUTH_TOKEN}\n` +
6980+
`message=${message}\n`), 'utf-8');
69816981
return {
69826982
NPM_CONFIG_USERCONFIG: npmrc,
69836983
NODE_AUTH_TOKEN: token
@@ -6998,8 +6998,9 @@ async function npmConfigRegistry(registryUrl, token) {
69986998
const githubToken = core.getInput('github_token', { required: true });
69996999
const publish = core.getInput('publish') !== 'false';
70007000
const push = core.getInput('push') !== 'false';
7001-
const gitUserName = core.getInput('git_user_name');
7002-
const gitUserEmail = core.getInput('git_user_email');
7001+
const name = core.getInput('name');
7002+
const email = core.getInput('email');
7003+
const message = core.getInput('message');
70037004
let publishToGithub;
70047005
let publishToNPM;
70057006
let privatePackage;
@@ -7057,8 +7058,10 @@ async function npmConfigRegistry(registryUrl, token) {
70577058
cliPath = `node_modules/${cli}/${JSON
70587059
.parse((await external_fs_.promises.readFile(`node_modules/${cli}/package.json`)).toString())
70597060
.bin[cli]}`;
7061+
await exec.exec('git', ['config', '--global', 'user.name', name]);
7062+
await exec.exec('git', ['config', '--global', 'user.email', email]);
70607063
core.info(`Creating release on GitHub${publishToGithub ? ' and publishing to GitHub registry' : ''}...`);
7061-
await release(cliPath, true, publishToGithub, {
7064+
await release(cliPath, true, publishToGithub, message, {
70627065
...process.env,
70637066
NPM_CONFIG_REGISTRY: `https://npm.pkg.github.com`,
70647067
NPM_TOKEN: githubToken,
@@ -7067,7 +7070,7 @@ async function npmConfigRegistry(registryUrl, token) {
70677070
core.info('Release available on GitHub');
70687071
publishToGithub && core.info('Package available on GitHub registry');
70697072
publishToNPM && core.info('Publishing to NPM registry...');
7070-
await release(cliPath, false, publishToNPM, {
7073+
await release(cliPath, false, publishToNPM, message, {
70717074
...process.env,
70727075
NPM_CONFIG_REGISTRY: 'https://registry.npmjs.org',
70737076
NPM_TOKEN: npmToken,
@@ -7076,8 +7079,6 @@ async function npmConfigRegistry(registryUrl, token) {
70767079
publishToNPM && core.info('Package available on NPM registry');
70777080
if (push) {
70787081
core.info('Pushing changes to GitHub repository...');
7079-
await exec.exec('git', ['config', '--global', 'user.name', gitUserName]);
7080-
await exec.exec('git', ['config', '--global', 'user.email', gitUserEmail]);
70817082
await exec.exec('git', ['push']);
70827083
core.info('GitHub repository up to date');
70837084
}
@@ -7086,7 +7087,7 @@ async function npmConfigRegistry(registryUrl, token) {
70867087
core.setFailed(error.message);
70877088
}
70887089
})();
7089-
async function lernaRelease(path, release, publish, env = {}) {
7090+
async function lernaRelease(path, release, publish, message, env = {}) {
70907091
if (release) {
70917092
await exec.exec('node', [
70927093
path,
@@ -7097,7 +7098,7 @@ async function lernaRelease(path, release, publish, env = {}) {
70977098
], { env });
70987099
}
70997100
if (publish) {
7100-
const npmEnv = await npmConfigRegistry(env.NPM_CONFIG_REGISTRY, env.NPM_TOKEN);
7101+
const npmEnv = await npmConfig(env.NPM_CONFIG_REGISTRY, env.NPM_TOKEN, message);
71017102
await exec.exec('node', [
71027103
path,
71037104
'publish',
@@ -7110,7 +7111,7 @@ async function lernaRelease(path, release, publish, env = {}) {
71107111
});
71117112
}
71127113
}
7113-
async function semanticRelease(path, release, publish, env = {}) {
7114+
async function semanticRelease(path, release, publish, message, env = {}) {
71147115
if (release) {
71157116
await exec.exec('node', [
71167117
path,
@@ -7120,7 +7121,7 @@ async function semanticRelease(path, release, publish, env = {}) {
71207121
], { env });
71217122
}
71227123
if (publish) {
7123-
const npmEnv = await npmConfigRegistry(env.NPM_CONFIG_REGISTRY, env.NPM_TOKEN);
7124+
const npmEnv = await npmConfig(env.NPM_CONFIG_REGISTRY, env.NPM_TOKEN, message);
71247125
await exec.exec('yarn', [
71257126
'publish',
71267127
'--non-interactive',
@@ -7331,6 +7332,6 @@ module.exports = require("zlib");;
73317332
/******/ // module exports must be returned from runtime so entry inlining is disabled
73327333
/******/ // startup
73337334
/******/ // Load entry module and return exports
7334-
/******/ return __webpack_require__(648);
7335+
/******/ return __webpack_require__(986);
73357336
/******/ })()
73367337
;

readme.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,26 @@ jobs:
5858

5959
Enable or disable publishing to package registries. When set to false, only releases are created on GitHub.
6060

61-
### `commit`
61+
### `push`
6262

6363
`boolean` *(optional, default `true`)*
6464

65-
Enable or disable commiting and pushing changes made by the action.
65+
Enable or disable pushing changes made by the action.
6666

67-
## `commit_name`
67+
## `name`
6868

6969
`string` *(optional, default: `'github-actions[bot]'`)*
7070

7171
User name to use when pushing to GitHub.
7272

73-
## `commit_email`
73+
## `email`
7474

7575
`string` *(optional, default: `'github-actions[bot]@users.noreply.github.com'`)*
7676

7777
Email to use when pushing to GitHub.
7878

79-
## `commit_message`
79+
## `message`
8080

8181
`string` *(optional, default: `'ci: release'`)*
8282

83-
Commit message to use when pushing to GitHub.
83+
Commit message to use when bumping package.json.

release.commit.js

Whitespace-only changes.

src/index.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as core from '@actions/core'
22
import * as exec from '@actions/exec'
33
import * as github from '@actions/github'
44
import { promises as fs } from 'fs'
5-
import { npmConfigRegistry } from './config'
5+
import { npmConfig } from './npm-config'
66

77
(async () => {
88
try {
@@ -12,8 +12,9 @@ import { npmConfigRegistry } from './config'
1212
const githubToken: string = core.getInput('github_token', { required: true })
1313
const publish: boolean = core.getInput('publish') !== 'false'
1414
const push: boolean = core.getInput('push') !== 'false'
15-
const gitUserName: string = core.getInput('git_user_name')
16-
const gitUserEmail: string = core.getInput('git_user_email')
15+
const name: string = core.getInput('name')
16+
const email: string = core.getInput('email')
17+
const message: string = core.getInput('message')
1718

1819
let publishToGithub: boolean
1920
let publishToNPM: boolean
@@ -25,6 +26,7 @@ import { npmConfigRegistry } from './config'
2526
path: string,
2627
release: boolean,
2728
publish: boolean,
29+
message: string,
2830
env?: { [variable: string]: string }
2931
) => Promise<void>
3032

@@ -100,11 +102,14 @@ import { npmConfigRegistry } from './config'
100102
.bin[cli]
101103
}`
102104

105+
await exec.exec('git', ['config', '--global', 'user.name', name])
106+
await exec.exec('git', ['config', '--global', 'user.email', email])
107+
103108
core.info(
104109
`Creating release on GitHub${publishToGithub ? ' and publishing to GitHub registry' : ''}...`
105110
)
106111

107-
await release(cliPath, true, publishToGithub, {
112+
await release(cliPath, true, publishToGithub, message, {
108113
...process.env,
109114
NPM_CONFIG_REGISTRY: `https://npm.pkg.github.com`,
110115
NPM_TOKEN: githubToken,
@@ -123,7 +128,7 @@ import { npmConfigRegistry } from './config'
123128
'Publishing to NPM registry...'
124129
)
125130

126-
await release(cliPath, false, publishToNPM, {
131+
await release(cliPath, false, publishToNPM, message, {
127132
...process.env,
128133
NPM_CONFIG_REGISTRY: 'https://registry.npmjs.org',
129134
NPM_TOKEN: npmToken,
@@ -139,8 +144,6 @@ import { npmConfigRegistry } from './config'
139144
'Pushing changes to GitHub repository...'
140145
)
141146

142-
await exec.exec('git', ['config', '--global', 'user.name', gitUserName])
143-
await exec.exec('git', ['config', '--global', 'user.email', gitUserEmail])
144147
await exec.exec('git', ['push'])
145148

146149
core.info(
@@ -156,6 +159,7 @@ async function lernaRelease(
156159
path: string,
157160
release: boolean,
158161
publish: boolean,
162+
message: string,
159163
env: { [variable: string]: string } = {}
160164
): Promise<void> {
161165
if (release) {
@@ -169,9 +173,10 @@ async function lernaRelease(
169173
}
170174

171175
if (publish) {
172-
const npmEnv = await npmConfigRegistry(
176+
const npmEnv = await npmConfig(
173177
env.NPM_CONFIG_REGISTRY,
174-
env.NPM_TOKEN
178+
env.NPM_TOKEN,
179+
message
175180
)
176181

177182
await exec.exec('node', [
@@ -191,6 +196,7 @@ async function semanticRelease(
191196
path: string,
192197
release: boolean,
193198
publish: boolean,
199+
message: string,
194200
env: { [variable: string]: string } = {}
195201
): Promise<void> {
196202
if (release) {
@@ -203,9 +209,10 @@ async function semanticRelease(
203209
}
204210

205211
if (publish) {
206-
const npmEnv = await npmConfigRegistry(
212+
const npmEnv = await npmConfig(
207213
env.NPM_CONFIG_REGISTRY,
208-
env.NPM_TOKEN
214+
env.NPM_TOKEN,
215+
message
209216
)
210217

211218
await exec.exec('yarn', [

src/config.ts renamed to src/npm-config.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,24 @@ const npmrc = path.resolve(
77
'.npmrc'
88
)
99

10-
export async function npmConfigRegistry(
11-
registryUrl: string,
12-
token: string
10+
export async function npmConfig(
11+
registryUrl: string,
12+
token: string,
13+
message: string
1314
): Promise<NodeJS.ProcessEnv> {
1415
if (!registryUrl.endsWith('/')) {
1516
registryUrl += '/'
1617
}
1718

1819
core.info(`Setup NPM registry URL: ${registryUrl} on ${npmrc}`)
1920

20-
registryUrl = registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}'
21-
await fs.writeFile(npmrc, registryUrl, 'utf-8')
21+
await fs.writeFile(npmrc, (
22+
`${registryUrl.replace(/(^\w+:|^)/, '')}:_authToken=\${NODE_AUTH_TOKEN}\n` +
23+
`message=${message}\n`
24+
), 'utf-8')
2225

2326
return {
2427
NPM_CONFIG_USERCONFIG: npmrc,
2528
NODE_AUTH_TOKEN: token
2629
}
27-
}
30+
}

0 commit comments

Comments
 (0)