Skip to content
Open

aa #1

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: OneCommit
on: [pull_request]
jobs:
oneCommit:
runs-on: ubuntu-latest
name: restrict commit messages
steps:
- uses: actions/checkout@v1
- uses: Gaurang033/OneCommit@v1
with:
max_commits: 1
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "build-test"
on: # rebuild any PRs and main branch changes
pull_request:
push:
branches:
- master
- 'releases/*'

jobs:
build: # make sure build/ci work properly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: |
npm install
npm run all
test: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
steps:
- uses: Gaurang033/OneCommit@v1
112 changes: 16 additions & 96 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,101 +1,21 @@
<p align="center">
<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>
</p>
# OneCommit Github Action

# Create a JavaScript Action using TypeScript
Validates pull request for maximum allowed commits

Use this template to bootstrap the creation of a JavaScript action.:rocket:
## Usage

This template includes compilication support, tests, a validation workflow, publishing, and versioning guidance.

If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action)

## Create an action from this template

Click the `Use this Template` and provide the new repo details for your action

## Code in Master

Install the dependencies
```bash
$ npm install
```

Build the typescript and package it for distribution
```bash
$ npm run build && npm run pack
```

Run the tests :heavy_check_mark:
```bash
$ npm test

PASS ./index.test.js
✓ throws invalid number (3ms)
✓ wait 500 ms (504ms)
✓ test runs (95ms)

...
```

## Change action.yml

The action.yml contains defines the inputs and output for your action.

Update the action.yml with your name, description, inputs and outputs for your action.

See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions)

## Change the Code

Most toolkit and CI/CD operations involve async operations so the action is run in an async function.

```javascript
import * as core from '@actions/core';
...

async function run() {
try {
...
}
catch (error) {
core.setFailed(error.message);
}
}

run()
```

See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages.

## Publish to a distribution branch

Actions are run from GitHub repos so we will checkin the packed dist folder.

Then run [ncc](https://github.com/zeit/ncc) and push the results:
```bash
$ npm run pack
$ git add dist
$ git commit -a -m "prod dependencies"
$ git push origin releases/v1
```

Your action is now published! :rocket:

See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)

## Validate

You can now validate the action by referencing `./` in a workflow in your repo (see [test.yml](.github/workflows/test.yml)])
Create a github workflow in the `.github` folder, e.g. `.github/workflows/onecommit.yml`:

```yaml
uses: ./
with:
milliseconds: 1000
```

See the [actions tab](https://github.com/actions/javascript-action/actions) for runs of this action! :rocket:

## Usage:

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
name: OneCommit
on: [pull_request]
jobs:
oneCommit:
runs-on: ubuntu-latest
name: restrict commit messages
steps:
- uses: actions/checkout@v1
- uses: Gaurang033/OneCommit@v1
with:
max_commits: 2
```
2 changes: 2 additions & 0 deletions a
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
iaaa
aaa
8 changes: 4 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3516,11 +3516,11 @@ function run() {
// const token = core.getInput('github-token', {required: true})
const { pull_request: pr } = github.context.payload;
if (!pr) {
throw new Error("Event payload missing `pull_request`");
throw new Error('Event payload missing `pull_request`');
}
core.info(`total number of commits are: ${pr["commits"]}`);
if (pr["commits"] > 1) {
core.setFailed("total number of commits are greater than 1, please squash your commits");
core.info(`total number of commits are: ${pr['commits']}`);
if (pr['commits'] > 1) {
core.setFailed('total number of commits are greater than 1, please squash your commits');
}
// const client = new github.GitHub(token)
}
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "actiondemo",
"version": "0.0.1",
"name": "onecommit",
"version": "1.0.0",
"private": true,
"description": "Validates that your pull request should have max 1 commit",
"description": "Validates that your pull request for maximum allowed commits",
"main": "lib/main.js",
"scripts": {
"build": "tsc",
Expand Down
5 changes: 3 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import * as github from '@actions/github'
async function run(): Promise<void> {
try {
// const token = core.getInput('github-token', {required: true})
const maxCommits: number = parseInt(core.getInput('max_commits'))

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

core.info(`total number of commits are: ${pr['commits']}`)
if (pr['commits'] > 1) {
if (pr['commits'] > maxCommits) {
core.setFailed(
'total number of commits are greater than 1, please squash your commits'
`total number of commits are greater than ${maxCommits}, please squash your commits`
)
}
// const client = new github.GitHub(token)
Expand Down