From 525e0056cac5b2c7a93ff04f43a11454e9b92643 Mon Sep 17 00:00:00 2001 From: Gaurang Shah Date: Sat, 28 Mar 2020 23:27:38 -0400 Subject: [PATCH 1/3] modified readme and package.json --- .github/workflows/main.yml | 11 ++++ .github/workflows/test.yml | 20 +++++++ README.md | 112 ++++++------------------------------- dist/index.js | 8 +-- package.json | 6 +- src/main.ts | 5 +- 6 files changed, 57 insertions(+), 105 deletions(-) create mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..8618132 --- /dev/null +++ b/.github/workflows/main.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..8ec44be --- /dev/null +++ b/.github/workflows/test.yml @@ -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 diff --git a/README.md b/README.md index 93ee363..1fc1e91 100644 --- a/README.md +++ b/README.md @@ -1,101 +1,21 @@ -

- typescript-action status -

+# 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 +``` \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index a358b55..2091371 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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) } diff --git a/package.json b/package.json index da1c6c5..990eeb9 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/main.ts b/src/main.ts index 71218bb..10a5595 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,6 +4,7 @@ import * as github from '@actions/github' async function run(): Promise { 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) { @@ -11,9 +12,9 @@ async function run(): Promise { } 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) From 425b636353bd2ffac791de698c1b7764e6834120 Mon Sep 17 00:00:00 2001 From: Gaurang Shah Date: Sun, 29 Mar 2020 00:00:22 -0400 Subject: [PATCH 2/3] aa --- a | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 a diff --git a/a b/a new file mode 100644 index 0000000..e69de29 From bf14e16a166c7e806b0c516f4d1a86238b220128 Mon Sep 17 00:00:00 2001 From: Gaurang Shah Date: Sun, 29 Mar 2020 00:42:51 -0400 Subject: [PATCH 3/3] aa --- a | 2 ++ 1 file changed, 2 insertions(+) diff --git a/a b/a index e69de29..48d4fc1 100644 --- a/a +++ b/a @@ -0,0 +1,2 @@ +iaaa +aaa