Skip to content

Commit 8a30a5b

Browse files
committed
initial commit
0 parents  commit 8a30a5b

14 files changed

Lines changed: 3653 additions & 0 deletions

.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
root = true
2+
3+
[*]
4+
5+
# We recommend you to keep these unchanged.
6+
charset = utf-8
7+
end_of_line = lf
8+
indent_size = 2
9+
indent_style = space
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
13+
[*.ts]
14+
indent_size = 4
15+
16+
[*.md]
17+
trim_trailing_whitespace = false

.eslintrc.cjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
root: true,
3+
parser: '@typescript-eslint/parser',
4+
parserOptions: {
5+
project: './tsconfig.json',
6+
ecmaVersion: 2021,
7+
},
8+
plugins: ['@typescript-eslint', 'prettier'],
9+
extends: [
10+
'eslint:recommended',
11+
'plugin:@typescript-eslint/eslint-recommended',
12+
'plugin:@typescript-eslint/recommended',
13+
'prettier',
14+
'plugin:prettier/recommended',
15+
],
16+
env: {
17+
node: true,
18+
},
19+
rules: {
20+
'@typescript-eslint/no-floating-promises': 'error',
21+
'@typescript-eslint/no-unused-vars': ['error'],
22+
},
23+
}

.github/workflows/report_test.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Test Action
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: ['main']
7+
workflow_dispatch:
8+
9+
permissions:
10+
# Give the default GITHUB_TOKEN write permission to commit and push the changed files back to the repository.
11+
contents: write
12+
13+
# Allow only one job per PR or branch
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
16+
cancel-in-progress: true # cancel jobs in progress
17+
18+
jobs:
19+
test:
20+
timeout-minutes: 180
21+
runs-on: ubuntu-latest
22+
name: Build, Test, Action
23+
24+
steps:
25+
# To use this repository's private action,
26+
# you must check out the repository
27+
- uses: actions/checkout@v3
28+
29+
- run: npm ci --no-fund --no-audit --no-progress
30+
- run: npm run checks
31+
- run: npm run build
32+
- name: Make sure dist was commited before push
33+
run: |
34+
git status -s -uno
35+
[ $(git status -s -uno | wc -l | bc ) != "0" ] && exit 1 || echo OK
36+
37+
# - name: Checkout gh-pages
38+
# uses: actions/checkout@v3
39+
# if: always()
40+
# continue-on-error: true
41+
# with:
42+
# ref: gh-pages # branch name
43+
# path: gh-pages-dir # checkout path
44+
45+
# - name: Local Allure Report Action
46+
# uses: ./ # Uses an action in the root directory
47+
# if: always()
48+
# continue-on-error: true
49+
# id: self_test # used in comment to PR
50+
# with:
51+
# report_id: 'self-test'
52+
# gh_pages: 'gh-pages-dir'
53+
# report_dir: 'allure-results'
54+
# list_dirs: ${{ github.ref == 'refs/heads/main' }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.DS_Store
3+
src/report_*.ts

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npm run checks

.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"trailingComma": "es5",
5+
"printWidth": 140
6+
}

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# git-commit-pull-push-action
2+
3+
Runs git add, git commit, git pull and git push.
4+
5+
The action flow:
6+
7+
1. git add .
8+
2. check if there are any changed files
9+
3. git commit
10+
4. git pull (with args)
11+
5. git push
12+
13+
Originally designed to run `git pull --rebase -X ours` or `git pull --rebase -X theirs` after commit to help pushing changed to `gh-pages`.
14+
15+
## Usage
16+
17+
todo
18+

action.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: 'Git commit, pull & push action'
2+
description: 'Runs git add, git commit, git pull and git push'
3+
author: 'mgrybyk'
4+
branding:
5+
icon: 'git-commit'
6+
color: 'gray-dark'
7+
inputs:
8+
repository:
9+
description: Local file path to the git repository. Defaults to the current directory (`.`)
10+
required: true
11+
default: '.'
12+
branch:
13+
description: Git branch name, where changes should be pushed too.
14+
required: true
15+
commit_message:
16+
description: Commit message
17+
required: false
18+
default: Apply automatic changes
19+
pull_args:
20+
description: git pull arguments
21+
required: false
22+
default: --rebase -X ours
23+
runs:
24+
using: 'node16'
25+
main: 'dist/index.js'

index.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import * as core from '@actions/core'
2+
import { isFileExist } from './src/isFileExists.js'
3+
import { spawnProcess } from './src/spawnProcess.js'
4+
5+
try {
6+
// vars
7+
const repository = core.getInput('repository')
8+
const branch = core.getInput('branch')
9+
const commitMessage = core.getInput('commit_message')
10+
const pullArgs = core.getInput('pull_args')
11+
12+
// log
13+
console.log({
14+
repository,
15+
branch,
16+
commitMessage,
17+
pullArgs,
18+
})
19+
20+
if (!(await isFileExist(repository))) {
21+
throw new Error("repository directory doesn't exist: " + repository)
22+
}
23+
24+
await spawnProcess('git', ['add', '.'], repository)
25+
const diff = await spawnProcess('git', ['diff', '--staged', '--name-only'], repository)
26+
if (diff.trim() === '') {
27+
console.log('Working tree is empty. Nothing to commit.')
28+
} else {
29+
await spawnProcess(
30+
'git',
31+
[
32+
'-c',
33+
'user.name="github-actions[bot]"',
34+
'-c',
35+
'user.email="41898282+github-actions[bot]@users.noreply.github.com"',
36+
'commit',
37+
'-m',
38+
commitMessage,
39+
'--author="github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"',
40+
'--no-verify',
41+
],
42+
repository
43+
)
44+
await spawnProcess('git', ['pull', ...pullArgs.split(' ')], repository)
45+
await spawnProcess('git', ['push', '--no-verify', 'origin', branch], repository)
46+
}
47+
} catch (error) {
48+
core.setFailed(error.message)
49+
}

0 commit comments

Comments
 (0)