Skip to content

Commit

Permalink
Add a workflow that validates PR title for Jira ticket reference (#47)
Browse files Browse the repository at this point in the history
* Add a workflow that validates PR title for Jira ticket reference

* Fix path to .node-version

* Use correct dependency cache path

* ..

* Cleanup
  • Loading branch information
nirinchev authored Mar 5, 2024
1 parent 6418e15 commit 4dfaee0
Show file tree
Hide file tree
Showing 24 changed files with 39,683 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .github/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ group:
dest: .github/advanced-issue-labeler.yml
- source: synced-files/.github/workflows/issue-labeler.yml
dest: .github/workflows/issue-labeler.yml
- source: synced-files/.github/workflows/check-pr-title.yml
dest: .github/workflows/check-pr-title.yml
repos: |
realm/realm-js
realm/realm-java
Expand Down Expand Up @@ -79,4 +81,4 @@ group:
realm/realm-dotnet
realm/realm-swift
realm/realm-dart
95 changes: 95 additions & 0 deletions .github/workflows/title-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Title Checker CI

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
check-dist:
name: Check dist/
runs-on: ubuntu-latest

steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4

- name: Setup Node.js
id: setup-node
uses: actions/setup-node@v4
with:
node-version-file: ./title-checker/.node-version
cache: npm
cache-dependency-path: ./title-checker/package-lock.json

- name: Install Dependencies
id: install
run: npm ci
working-directory: title-checker

- name: Build dist/ Directory
id: build
run: npm run bundle
working-directory: title-checker

# This will fail the workflow if the PR wasn't created by Dependabot.
- name: Compare Directories
id: diff
run: |
if [ "$(git diff --ignore-space-at-eol --text dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff --ignore-space-at-eol --text dist/
exit 1
fi
working-directory: title-checker

# If `dist/` was different than expected, and this was not a Dependabot
# PR, upload the expected version as a workflow artifact.
- if: ${{ failure() && steps.diff.outcome == 'failure' }}
name: Upload Artifact
id: upload
uses: actions/upload-artifact@v4
with:
name: dist
path: title-checker/dist/

test-typescript:
name: TypeScript Tests
runs-on: ubuntu-latest

steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4

- name: Setup Node.js
id: setup-node
uses: actions/setup-node@v4
with:
node-version-file: ./title-checker/.node-version
cache: npm
cache-dependency-path: ./title-checker/package-lock.json

- name: Install Dependencies
id: npm-ci
run: npm ci
working-directory: title-checker

- name: Check Format
id: npm-format-check
run: npm run format:check
working-directory: title-checker

- name: Lint
id: npm-lint
run: npm run lint
working-directory: title-checker

- name: Test
id: npm-ci-test
run: npm run ci-test
working-directory: title-checker
21 changes: 21 additions & 0 deletions synced-files/.github/workflows/check-pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# NOTE: This is a common file that is overwritten by realm/ci-actions sync service
# and should only be modified in that repository.

name: "Check Changelog"
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled, converted_to_draft, edited]

jobs:
check-pr-title:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: false
- name: Enforce PR title
uses: realm/ci-actions/title-checker@master
with:
regex: R[A-Z]{2,5}-[0-9]{1,6}
error-hint: Invalid PR title. Make sure it's prefixed with the JIRA ticket the PR addresses or add the no-jira-ticket label.
ignore-labels: 'no-jira-ticket'
4 changes: 4 additions & 0 deletions title-checker/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lib/
dist/
node_modules/
coverage/
83 changes: 83 additions & 0 deletions title-checker/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
env:
node: true
es6: true
jest: true

globals:
Atomics: readonly
SharedArrayBuffer: readonly

ignorePatterns:
- '!.*'
- '**/node_modules/.*'
- '**/dist/.*'
- '**/coverage/.*'
- '*.json'

parser: '@typescript-eslint/parser'

parserOptions:
ecmaVersion: 2023
sourceType: module
project:
- './tsconfig-lint.json'
- './tsconfig.json'

plugins:
- jest
- '@typescript-eslint'

extends:
- eslint:recommended
- plugin:@typescript-eslint/eslint-recommended
- plugin:@typescript-eslint/recommended
- plugin:github/recommended
- plugin:jest/recommended

rules:
{
'camelcase': 'off',
'eslint-comments/no-use': 'off',
'eslint-comments/no-unused-disable': 'off',
'i18n-text/no-en': 'off',
'import/no-namespace': 'off',
'no-console': 'off',
'no-unused-vars': 'off',
'prettier/prettier': 'error',
'semi': 'off',
'@typescript-eslint/array-type': 'error',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/ban-ts-comment': 'error',
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/explicit-member-accessibility':
['error', { 'accessibility': 'no-public' }],
'@typescript-eslint/explicit-function-return-type':
['error', { 'allowExpressions': true }],
'@typescript-eslint/func-call-spacing': ['error', 'never'],
'@typescript-eslint/no-array-constructor': 'error',
'@typescript-eslint/no-empty-interface': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-extraneous-class': 'error',
'@typescript-eslint/no-for-in-array': 'error',
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/no-non-null-assertion': 'warn',
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-unnecessary-qualifier': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/prefer-for-of': 'warn',
'@typescript-eslint/prefer-function-type': 'warn',
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
'@typescript-eslint/promise-function-async': 'error',
'@typescript-eslint/require-array-sort-compare': 'error',
'@typescript-eslint/restrict-plus-operands': 'error',
'@typescript-eslint/semi': ['error', 'never'],
'@typescript-eslint/space-before-function-paren': 'off',
'@typescript-eslint/type-annotation-spacing': 'error',
'@typescript-eslint/unbound-method': 'error'
}
3 changes: 3 additions & 0 deletions title-checker/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto eol=lf

dist/** -diff linguist-generated=true
103 changes: 103 additions & 0 deletions title-checker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Dependency directory
node_modules

# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# OS metadata
.DS_Store
Thumbs.db

# Ignore built ts files
__tests__/runner/*

# IDE files
.idea
.vscode
*.code-workspace
1 change: 1 addition & 0 deletions title-checker/.node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.6.0
3 changes: 3 additions & 0 deletions title-checker/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/
node_modules/
coverage/
16 changes: 16 additions & 0 deletions title-checker/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"quoteProps": "as-needed",
"jsxSingleQuote": false,
"trailingComma": "none",
"bracketSpacing": true,
"bracketSameLine": true,
"arrowParens": "avoid",
"proseWrap": "always",
"htmlWhitespaceSensitivity": "css",
"endOfLine": "lf"
}
3 changes: 3 additions & 0 deletions title-checker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# PR title checker

A simple github action that validates that a PR title matches a supplied regex.
17 changes: 17 additions & 0 deletions title-checker/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Unit tests for the action's entrypoint, src/index.ts
*/

import * as main from '../src/main'

// Mock the action's entrypoint
const runMock = jest.spyOn(main, 'run').mockImplementation()

describe('index', () => {
it('calls run when imported', async () => {
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('../src/index')

expect(runMock).toHaveBeenCalled()
})
})
Loading

0 comments on commit 4dfaee0

Please sign in to comment.