Skip to content

Commit 8bf5ab0

Browse files
feat: push changes to github
1 parent 55f352c commit 8bf5ab0

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

action.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ 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+
push:
16+
description: Enable or disable pushing changes made by the action.
17+
default: true
18+
required: false
19+
git_user_name:
20+
description: User name to use when pushing to GitHub.
21+
default: github-actions[bot]
22+
required: false
23+
git_user_email:
24+
description: Email to use when pushing to GitHub.
25+
default: github-actions[bot]@users.noreply.github.com
26+
required: false
1527
runs:
1628
using: node12
1729
main: dist/index.js

dist/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6997,6 +6997,9 @@ async function npmConfigRegistry(registryUrl, token) {
69976997
const npmToken = core.getInput('npm_token');
69986998
const githubToken = core.getInput('github_token', { required: true });
69996999
const publish = core.getInput('publish') !== 'false';
7000+
const push = core.getInput('push') !== 'false';
7001+
const gitUserName = core.getInput('git_user_name');
7002+
const gitUserEmail = core.getInput('git_user_email');
70007003
let publishToGithub;
70017004
let publishToNPM;
70027005
let privatePackage;
@@ -7071,6 +7074,13 @@ async function npmConfigRegistry(registryUrl, token) {
70717074
GITHUB_TOKEN: githubToken
70727075
});
70737076
publishToNPM && core.info('Package available on NPM registry');
7077+
if (push) {
7078+
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]);
7081+
await exec.exec('git', ['push']);
7082+
core.info('GitHub repository up to date');
7083+
}
70747084
}
70757085
catch (error) {
70767086
core.setFailed(error.message);

readme.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,24 @@ jobs:
5454

5555
### `publish`
5656

57-
`string` *(optional, default `true`)*
57+
`boolean` *(optional, default `true`)*
5858

5959
Enable or disable publishing to package registries. When set to false, only releases are created on GitHub.
60+
61+
### `push`
62+
63+
`boolean` *(optional, default `true`)*
64+
65+
Enable or disable pushing changes made by the action.
66+
67+
## `git_user_name`
68+
69+
`string` *(optional, default: `'github-actions[bot]'`)*
70+
71+
User name to use when pushing to GitHub.
72+
73+
## `git_user_email`
74+
75+
`string` *(optional, default: `'github-actions[bot]@users.noreply.github.com'`)*
76+
77+
Email to use when pushing to GitHub.

src/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import { npmConfigRegistry } from './config'
1111
const npmToken: string = core.getInput('npm_token')
1212
const githubToken: string = core.getInput('github_token', { required: true })
1313
const publish: boolean = core.getInput('publish') !== 'false'
14+
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')
1417

1518
let publishToGithub: boolean
1619
let publishToNPM: boolean
@@ -130,6 +133,20 @@ import { npmConfigRegistry } from './config'
130133
publishToNPM && core.info(
131134
'Package available on NPM registry'
132135
)
136+
137+
if (push) {
138+
core.info(
139+
'Pushing changes to GitHub repository...'
140+
)
141+
142+
await exec.exec('git', ['config', '--global', 'user.name', gitUserName])
143+
await exec.exec('git', ['config', '--global', 'user.email', gitUserEmail])
144+
await exec.exec('git', ['push'])
145+
146+
core.info(
147+
'GitHub repository up to date'
148+
)
149+
}
133150
} catch (error) {
134151
core.setFailed(error.message)
135152
}

0 commit comments

Comments
 (0)