Skip to content

Commit beb10bb

Browse files
committed
modified readme and package.json
1 parent b163c50 commit beb10bb

7 files changed

Lines changed: 60 additions & 105 deletions

File tree

.github/workflows/main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: OneCommit
2+
on: [pull_request]
3+
jobs:
4+
oneCommit:
5+
runs-on: ubuntu-latest
6+
name: restrict commit messages
7+
steps:
8+
- uses: actions/checkout@v1
9+
- uses: Gaurang033/OneCommit@v1
10+
with:
11+
max_commits: 1

.github/workflows/test.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: "build-test"
2+
on: # rebuild any PRs and main branch changes
3+
pull_request:
4+
push:
5+
branches:
6+
- master
7+
- 'releases/*'
8+
9+
jobs:
10+
build: # make sure build/ci work properly
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v1
14+
- run: |
15+
npm install
16+
npm run all
17+
test: # make sure the action works on a clean machine without building
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: Gaurang033/OneCommit@v1

README.md

Lines changed: 16 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,21 @@
1-
<p align="center">
2-
<a href="https://github.com/actions/typescript-action/actions"><img alt="typescript-action status" src="https://github.com/actions/typescript-action/workflows/build-test/badge.svg"></a>
3-
</p>
1+
# OneCommit Github Action
42

5-
# Create a JavaScript Action using TypeScript
3+
Validates pull request for maximum allowed commits
64

7-
Use this template to bootstrap the creation of a JavaScript action.:rocket:
5+
## Usage
86

9-
This template includes compilication support, tests, a validation workflow, publishing, and versioning guidance.
10-
11-
If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action)
12-
13-
## Create an action from this template
14-
15-
Click the `Use this Template` and provide the new repo details for your action
16-
17-
## Code in Master
18-
19-
Install the dependencies
20-
```bash
21-
$ npm install
22-
```
23-
24-
Build the typescript and package it for distribution
25-
```bash
26-
$ npm run build && npm run pack
27-
```
28-
29-
Run the tests :heavy_check_mark:
30-
```bash
31-
$ npm test
32-
33-
PASS ./index.test.js
34-
✓ throws invalid number (3ms)
35-
wait 500 ms (504ms)
36-
test runs (95ms)
37-
38-
...
39-
```
40-
41-
## Change action.yml
42-
43-
The action.yml contains defines the inputs and output for your action.
44-
45-
Update the action.yml with your name, description, inputs and outputs for your action.
46-
47-
See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions)
48-
49-
## Change the Code
50-
51-
Most toolkit and CI/CD operations involve async operations so the action is run in an async function.
52-
53-
```javascript
54-
import * as core from '@actions/core';
55-
...
56-
57-
async function run() {
58-
try {
59-
...
60-
}
61-
catch (error) {
62-
core.setFailed(error.message);
63-
}
64-
}
65-
66-
run()
67-
```
68-
69-
See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages.
70-
71-
## Publish to a distribution branch
72-
73-
Actions are run from GitHub repos so we will checkin the packed dist folder.
74-
75-
Then run [ncc](https://github.com/zeit/ncc) and push the results:
76-
```bash
77-
$ npm run pack
78-
$ git add dist
79-
$ git commit -a -m "prod dependencies"
80-
$ git push origin releases/v1
81-
```
82-
83-
Your action is now published! :rocket:
84-
85-
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
86-
87-
## Validate
88-
89-
You can now validate the action by referencing `./` in a workflow in your repo (see [test.yml](.github/workflows/test.yml)])
7+
Create a github workflow in the `.github` folder, e.g. `.github/workflows/onecommit.yml`:
908

919
```yaml
92-
uses: ./
93-
with:
94-
milliseconds: 1000
95-
```
96-
97-
See the [actions tab](https://github.com/actions/javascript-action/actions) for runs of this action! :rocket:
98-
99-
## Usage:
100-
101-
After testing you can [create a v1 tag](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) to reference the stable and latest V1 action
10+
name: OneCommit
11+
on: [pull_request]
12+
jobs:
13+
oneCommit:
14+
runs-on: ubuntu-latest
15+
name: restrict commit messages
16+
steps:
17+
- uses: actions/checkout@v1
18+
- uses: Gaurang033/OneCommit@v1
19+
with:
20+
max_commits: 2
21+
```

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ author: 'Gaurang Shah'
44
runs:
55
using: 'node12'
66
main: 'dist/index.js'
7+
branding:
8+
icon: 'git-pull-request'
9+
color: 'green'

dist/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3516,11 +3516,11 @@ function run() {
35163516
// const token = core.getInput('github-token', {required: true})
35173517
const { pull_request: pr } = github.context.payload;
35183518
if (!pr) {
3519-
throw new Error("Event payload missing `pull_request`");
3519+
throw new Error('Event payload missing `pull_request`');
35203520
}
3521-
core.info(`total number of commits are: ${pr["commits"]}`);
3522-
if (pr["commits"] > 1) {
3523-
core.setFailed("total number of commits are greater than 1, please squash your commits");
3521+
core.info(`total number of commits are: ${pr['commits']}`);
3522+
if (pr['commits'] > 1) {
3523+
core.setFailed('total number of commits are greater than 1, please squash your commits');
35243524
}
35253525
// const client = new github.GitHub(token)
35263526
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "actiondemo",
3-
"version": "0.0.1",
2+
"name": "onecommit",
3+
"version": "1.0.0",
44
"private": true,
5-
"description": "Validates that your pull request should have max 1 commit",
5+
"description": "Validates that your pull request for maximum allowed commits",
66
"main": "lib/main.js",
77
"scripts": {
88
"build": "tsc",

src/main.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ import * as github from '@actions/github'
44
async function run(): Promise<void> {
55
try {
66
// const token = core.getInput('github-token', {required: true})
7+
const maxCommits: number = parseInt(core.getInput('max_commits'))
78

89
const {pull_request: pr} = github.context.payload
910
if (!pr) {
1011
throw new Error('Event payload missing `pull_request`')
1112
}
1213

1314
core.info(`total number of commits are: ${pr['commits']}`)
14-
if (pr['commits'] > 1) {
15+
if (pr['commits'] > maxCommits) {
1516
core.setFailed(
16-
'total number of commits are greater than 1, please squash your commits'
17+
`total number of commits are greater than ${maxCommits}, please squash your commits`
1718
)
1819
}
1920
// const client = new github.GitHub(token)

0 commit comments

Comments
 (0)