Skip to content

Commit

Permalink
Auto commit action
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaaz committed Nov 17, 2019
1 parent bc21bfd commit 1859d40
Show file tree
Hide file tree
Showing 8 changed files with 1,048 additions and 1 deletion.
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,37 @@
# action-autocommit
Commit changes made to a repo within a CI (example: run a script, then commit and push)

This action will commit and push all changes made to the current repo.
With this action you can make changes within a CI and automatically push it to the current branch.

Example of usage:

```yaml
name: Docgen

on:
push:
branches:
- master

jobs:
docgen:
name: Docgen
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@master

- name: Install Node v12
uses: actions/setup-node@master
with:
node-version: 12

- name: Install dependencies
run: yarn install

- name: Build docs
run: yarn install

- name: Commit and push
uses: khaazz/action-autocommit@master
```
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: 'auto-commit'
description: 'Commit and push current changes in the repo to the current branch.'
runs:
using: 'node12'
main: 'dist/index.js'
1 change: 1 addition & 0 deletions dist/index.js

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "action-autocommit",
"version": "1.0.0",
"description": "Action to commit and push changes to the current branch",
"main": "dist/index.js",
"author": "Khaazz <khaaz.dev@gmail.com>",
"license": "MIT",
"scripts": {
"prebuild": "yarn lint",
"build": "ncc build src/main.ts --minify",
"lint": "eslint src --ext .ts"
},
"dependencies": {
"@actions/core": "^1.0.0",
"@actions/exec": "^1.0.0",
"@actions/io": "^1.0.0"
},
"devDependencies": {
"@axonteam/eslint-config": "^2.2.0",
"@types/node": "^12.7.2",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"@zeit/ncc": "^0.20.4",
"eslint": "^6.2.1",
"typescript": "^3.7.2"
},
"eslintConfig": {
"extends": "@axonteam/eslint-config"
}
}
24 changes: 24 additions & 0 deletions src/commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -eo pipefail

cd $GITHUB_WORKSPACE

BRANCH_OR_TAG=`awk -F/ '{print $2}' <<< $GITHUB_REF`
CURRENT_BRANCH=`awk -F/ '{print $NF}' <<< $GITHUB_REF`

if [ "$BRANCH_OR_TAG" == "heads" ]; then
SOURCE_TYPE="branch"
else
SOURCE_TYPE="tag"
fi

echo "::[notice] # Pull"
git pull origin $CURRENT_BRANCH
echo "::[notice] # Commit"
git add .
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git commit -m "Auto-Commit for ${SOURCE_TYPE} ${CURRENT_BRANCH}: ${GITHUB_SHA}" || true
echo "::[notice] # Push"
git push origin HEAD:${CURRENT_BRANCH}
14 changes: 14 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { resolve } from 'path';
import { exec } from '@actions/exec';
import { which } from '@actions/io';
import { setFailed } from '@actions/core';

async function run() {
try {
await exec(await which('bash', true), ['src/commit.sh'], { cwd: resolve(__dirname, '..') } );
} catch (error) {
setFailed(error.message);
}
}

run();
25 changes: 25 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"strict": true,
"moduleResolution": "node",
"module": "esnext",
"target": "es2019",
"lib": [
"esnext",
"esnext.array",
"esnext.asynciterable",
"esnext.intl",
"esnext.symbol"
],
"sourceMap": false,
"inlineSourceMap": true,
"inlineSources": true,
"sourceRoot": "/",
"outDir": "dist",
"declaration": false,
"removeComments": false,
"alwaysStrict": true,
"allowSyntheticDefaultImports": true,
"pretty": true
}
}
Loading

0 comments on commit 1859d40

Please sign in to comment.