├── .github └── workflows │ └── checkin.yml ├── .gitignore ├── LICENSE ├── README.md ├── __tests__ └── main.test.ts ├── action.yml ├── docs └── contributors.md ├── jest.config.js ├── lib └── main.js ├── package-lock.json ├── package.json ├── src └── main.ts └── tsconfig.json /.github/workflows/checkin.yml: -------------------------------------------------------------------------------- 1 | name: "PR Checks" 2 | on: [pull_request, push] 3 | 4 | jobs: 5 | check_pr: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v1 9 | 10 | - name: "npm ci" 11 | run: npm ci 12 | 13 | - name: "npm run build" 14 | run: npm run build 15 | 16 | - name: "npm run test" 17 | run: npm run test 18 | 19 | - name: "check for uncommitted changes" 20 | # Ensure no changes, but ignore node_modules dir since dev/fresh ci deps installed. 21 | run: | 22 | git diff --exit-code --stat -- . ':!node_modules' \ 23 | || (echo "##[error] found changed files after build. please 'npm run build && npm run format'" \ 24 | "and check in all changes" \ 25 | && exit 1) 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | __tests__/runner/* 2 | 3 | # Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | lerna-debug.log* 11 | 12 | # Diagnostic reports (https://nodejs.org/api/report.html) 13 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 14 | 15 | # Runtime data 16 | pids 17 | *.pid 18 | *.seed 19 | *.pid.lock 20 | 21 | # Directory for instrumented libs generated by jscoverage/JSCover 22 | lib-cov 23 | 24 | # Coverage directory used by tools like istanbul 25 | coverage 26 | *.lcov 27 | 28 | # nyc test coverage 29 | .nyc_output 30 | 31 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 32 | .grunt 33 | 34 | # Bower dependency directory (https://bower.io/) 35 | bower_components 36 | 37 | # node-waf configuration 38 | .lock-wscript 39 | 40 | # Compiled binary addons (https://nodejs.org/api/addons.html) 41 | build/Release 42 | 43 | # Dependency directories 44 | node_modules/ 45 | jspm_packages/ 46 | 47 | # TypeScript v1 declaration files 48 | typings/ 49 | 50 | # TypeScript cache 51 | *.tsbuildinfo 52 | 53 | # Optional npm cache directory 54 | .npm 55 | 56 | # Optional eslint cache 57 | .eslintcache 58 | 59 | # Optional REPL history 60 | .node_repl_history 61 | 62 | # Output of 'npm pack' 63 | *.tgz 64 | 65 | # Yarn Integrity file 66 | .yarn-integrity 67 | 68 | # dotenv environment variables file 69 | .env 70 | .env.test 71 | 72 | # parcel-bundler cache (https://parceljs.org/) 73 | .cache 74 | 75 | # next.js build output 76 | .next 77 | 78 | # nuxt.js build output 79 | .nuxt 80 | 81 | # vuepress build output 82 | .vuepress/dist 83 | 84 | # Serverless directories 85 | .serverless/ 86 | 87 | # FuseBox cache 88 | .fusebox/ 89 | 90 | # DynamoDB Local files 91 | .dynamodb/ 92 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2018 GitHub, Inc. and contributors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Commit tagger 2 | 3 | Tags the commit with a given text 4 | 5 | ## Getting Started 6 | To use, create a workflow (eg: `.github/workflows/label.yml` see [Creating a Workflow file](https://help.github.com/en/articles/configuring-a-workflow#creating-a-workflow-file)) and add a step like 'Tag commit' on the below sample. A token will be needed so the workflow can make calls to GitHub's rest API. 7 | 8 | ```yaml 9 | name: "My workflow" 10 | 11 | on: [push] 12 | 13 | jobs: 14 | build: 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - name: Tag commit 19 | uses: tvdias/github-tagger@v0.0.1 20 | with: 21 | repo-token: "${{ secrets.GITHUB_TOKEN }}" 22 | tag: "my_tag" 23 | ``` 24 | 25 | An optional commit sha can be specified to override the default 26 | 27 | ```yaml 28 | steps: 29 | - name: Tag commit 30 | uses: tvdias/github-tagger@v0.0.1 31 | with: 32 | repo-token: "${{ secrets.GITHUB_TOKEN }}" 33 | tag: "my_tag" 34 | commit-sha: abc123 35 | ``` 36 | -------------------------------------------------------------------------------- /__tests__/main.test.ts: -------------------------------------------------------------------------------- 1 | describe('TODO - Add a test suite', () => { 2 | it('TODO - Add a test', async () => {}); 3 | }); 4 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Commit tagger' 2 | description: 'Tag commit with a given version' 3 | author: 'Thiago Vaz Dias' 4 | inputs: 5 | repo-token: 6 | description: 'The GITHUB_TOKEN secret' 7 | tag: 8 | description: 'Tag text' 9 | default: '0.1.0' 10 | commit-sha: 11 | description: optional commit sha to apply the tag to 12 | runs: 13 | using: 'node12' 14 | main: 'lib/main.js' 15 | -------------------------------------------------------------------------------- /docs/contributors.md: -------------------------------------------------------------------------------- 1 | # Contributors 2 | 3 | ### Checkin 4 | 5 | - Do checkin source (src) 6 | - Do checkin build output (lib) 7 | - Do checkin runtime node_modules 8 | - Do not checkin devDependency node_modules (husky can help see below) 9 | 10 | ### devDependencies 11 | 12 | In order to handle correctly checking in node_modules without devDependencies, we run [Husky](https://github.com/typicode/husky) before each commit. 13 | This step ensures that formatting and checkin rules are followed and that devDependencies are excluded. To make sure Husky runs correctly, please use the following workflow: 14 | 15 | ``` 16 | npm install # installs all devDependencies including Husky 17 | git add abc.ext # Add the files you've changed. This should include files in src, lib, and node_modules (see above) 18 | git commit -m "Informative commit message" # Commit. This will run Husky 19 | ``` 20 | 21 | During the commit step, Husky will take care of formatting all files with [Prettier](https://github.com/prettier/prettier) as well as pruning out devDependencies using `npm prune --production`. 22 | It will also make sure these changes are appropriately included in your commit (no further work is needed) -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | clearMocks: true, 3 | moduleFileExtensions: ['js', 'ts'], 4 | testEnvironment: 'node', 5 | testMatch: ['**/*.test.ts'], 6 | testRunner: 'jest-circus/runner', 7 | transform: { 8 | '^.+\\.ts$': 'ts-jest' 9 | }, 10 | verbose: true 11 | } -------------------------------------------------------------------------------- /lib/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | var __importStar = (this && this.__importStar) || function (mod) { 12 | if (mod && mod.__esModule) return mod; 13 | var result = {}; 14 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; 15 | result["default"] = mod; 16 | return result; 17 | }; 18 | Object.defineProperty(exports, "__esModule", { value: true }); 19 | const core = __importStar(require("@actions/core")); 20 | const github = __importStar(require("@actions/github")); 21 | function run() { 22 | return __awaiter(this, void 0, void 0, function* () { 23 | try { 24 | const token = core.getInput('repo-token', { required: true }); 25 | const tag = core.getInput('tag', { required: true }); 26 | const sha = core.getInput('commit-sha', { required: false }) || github.context.sha; 27 | const client = new github.GitHub(token); 28 | core.debug(`tagging #${sha} with tag ${tag}`); 29 | yield client.git.createRef({ 30 | owner: github.context.repo.owner, 31 | repo: github.context.repo.repo, 32 | ref: `refs/tags/${tag}`, 33 | sha: sha 34 | }); 35 | } 36 | catch (error) { 37 | core.error(error); 38 | core.setFailed(error.message); 39 | } 40 | }); 41 | } 42 | run(); 43 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "github-tagger", 3 | "version": "0.0.2", 4 | "private": true, 5 | "description": "Tags the commit with a given text", 6 | "main": "lib/main.js", 7 | "scripts": { 8 | "build": "tsc", 9 | "format": "prettier --write **/*.ts", 10 | "format-check": "prettier --check **/*.ts", 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "git+https://github.com/tvdias/github-tagger.git" 16 | }, 17 | "keywords": [ 18 | "actions", 19 | "node", 20 | "setup" 21 | ], 22 | "author": "Thiago Vaz Dias", 23 | "license": "MIT", 24 | "dependencies": { 25 | "@actions/core": "^1.0.0", 26 | "@actions/github": "^1.0.0" 27 | }, 28 | "devDependencies": { 29 | "@types/jest": "^24.0.13", 30 | "@types/node": "^12.0.4", 31 | "husky": "^2.3.0", 32 | "jest": "^24.8.0", 33 | "jest-circus": "^24.7.1", 34 | "prettier": "^1.17.1", 35 | "ts-jest": "^24.0.2", 36 | "typescript": "^3.5.1" 37 | }, 38 | "husky": { 39 | "skipCI": true, 40 | "hooks": { 41 | "pre-commit": "npm run build && npm run format", 42 | "post-commit": "npm prune --production && git add node_modules/* && git commit -m \"Husky commit correct node modules\"" 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import * as core from '@actions/core'; 2 | import * as github from '@actions/github'; 3 | 4 | async function run() { 5 | try { 6 | const token = core.getInput('repo-token', {required: true}); 7 | const tag = core.getInput('tag', {required: true}); 8 | const sha = core.getInput('commit-sha', {required: false}) || github.context.sha; 9 | 10 | const client = new github.GitHub(token); 11 | 12 | core.debug(`tagging #${sha} with tag ${tag}`); 13 | await client.git.createRef({ 14 | owner: github.context.repo.owner, 15 | repo: github.context.repo.repo, 16 | ref: `refs/tags/${tag}`, 17 | sha: sha 18 | }); 19 | 20 | } catch (error) { 21 | core.error(error); 22 | core.setFailed(error.message); 23 | } 24 | } 25 | 26 | run(); 27 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Basic Options */ 4 | // "incremental": true, /* Enable incremental compilation */ 5 | "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ 6 | "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ 7 | // "allowJs": true, /* Allow javascript files to be compiled. */ 8 | // "checkJs": true, /* Report errors in .js files. */ 9 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 10 | // "declaration": true, /* Generates corresponding '.d.ts' file. */ 11 | // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ 12 | // "sourceMap": true, /* Generates corresponding '.map' file. */ 13 | // "outFile": "./", /* Concatenate and emit output to single file. */ 14 | "outDir": "./lib", /* Redirect output structure to the directory. */ 15 | "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 16 | // "composite": true, /* Enable project compilation */ 17 | // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ 18 | // "removeComments": true, /* Do not emit comments to output. */ 19 | // "noEmit": true, /* Do not emit outputs. */ 20 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 21 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 22 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 23 | 24 | /* Strict Type-Checking Options */ 25 | "strict": true, /* Enable all strict type-checking options. */ 26 | "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */ 27 | // "strictNullChecks": true, /* Enable strict null checks. */ 28 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */ 29 | // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ 30 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ 31 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 32 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 33 | 34 | /* Additional Checks */ 35 | // "noUnusedLocals": true, /* Report errors on unused locals. */ 36 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 37 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 38 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 39 | 40 | /* Module Resolution Options */ 41 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 42 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 43 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 44 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 45 | // "typeRoots": [], /* List of folders to include type definitions from. */ 46 | // "types": [], /* Type declaration files to be included in compilation. */ 47 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 48 | "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 49 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 50 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 51 | 52 | /* Source Map Options */ 53 | // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 54 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 55 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 56 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 57 | 58 | /* Experimental Options */ 59 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 60 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 61 | }, 62 | "exclude": ["node_modules", "**/*.test.ts"] 63 | } 64 | --------------------------------------------------------------------------------