Skip to content

Commit

Permalink
Create semver-compare github action (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
chainchad committed Jun 14, 2023
1 parent 2039eb0 commit bc6e3b5
Show file tree
Hide file tree
Showing 20 changed files with 17,268 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/semver-compare-check-dist.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# `dist/index.js` is a special file in Actions.
# When you reference an action with `uses:` in a workflow,
# `index.js` is the code that will run.
# For our project, we generate this file through a build process from other source files.
# We need to make sure the checked-in `index.js` actually matches what we expect it to be.
name: semver-compare-check-dist

on:
push:
branches:
- main
paths:
- '.github/workflows/semver-compare-check-dist.yaml'
- 'semver-compare/**'
pull_request:
paths:
- '.github/workflows/semver-compare-check-dist.yaml'
- 'semver-compare/**'
workflow_dispatch:

defaults:
run:
shell: bash
working-directory: ./semver-compare

jobs:
check-dist:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set Node.js 16.x
uses: actions/setup-node@v3.6.0
with:
node-version: 16.x
- run: npm ci
- name: Rebuild the dist/ directory
run: |
npm run build
npm run package
- name: Compare the expected and actual dist/ directories
run: |
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff
exit 1
fi
id: diff

# If index.js was different than expected, upload the expected version as an artifact
- uses: actions/upload-artifact@v3
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with:
name: dist
path: dist/
35 changes: 35 additions & 0 deletions .github/workflows/semver-compare-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: 'semver-compare-build-ci'
on:
pull_request:
paths:
- '.github/workflows/semver-compare-ci.yaml'
- 'semver-compare/**'
push:
branches:
- main
- 'release/*'
paths:
- '.github/workflows/semver-compare-ci.yaml'
- 'semver-compare/**'

defaults:
run:
shell: bash
working-directory: ./semver-compare

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm ci
- run: npm run all
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./semver-compare/
with:
version1: 2.0.0
operator: gt
version2: 1.0.0
4 changes: 4 additions & 0 deletions semver-compare/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
lib/
node_modules/
jest.config.js
61 changes: 61 additions & 0 deletions semver-compare/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"plugins": ["jest", "@typescript-eslint"],
"extends": ["plugin:github/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
"i18n-text/no-en": "off",
"eslint-comments/no-use": "off",
"import/no-namespace": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-member-accessibility": [
"error",
{"accessibility": "no-public"}
],
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-comment": "error",
"camelcase": "off",
"@typescript-eslint/consistent-type-assertions": "error",
"@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-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "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",
"semi": "off",
"@typescript-eslint/semi": ["error", "never"],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error"
},
"env": {
"node": true,
"es6": true,
"jest/globals": true
}
}
99 changes: 99 additions & 0 deletions semver-compare/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# 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/*
lib/**/*
3 changes: 3 additions & 0 deletions semver-compare/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/
lib/
node_modules/
10 changes: 10 additions & 0 deletions semver-compare/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid"
}
11 changes: 11 additions & 0 deletions semver-compare/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# semver-compare

Very simple wrapper around the [semver](https://www.npmjs.com/package/semver) package.

## build

Make sure you build and commit the built files.

```shell
npm run build
```
37 changes: 37 additions & 0 deletions semver-compare/__tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {versionCompare} from '../src/compare'
import semver from 'semver'

describe('versionCompare', () => {
test('should throw an error when no versions or operator specified', () => {
expect(() => versionCompare('', 'gt', '')).toThrow(
'Required inputs not specified.'
)
expect(() => versionCompare('1.0.0', 'gt', '')).toThrow(
'Required inputs not specified.'
)
expect(() => versionCompare('', 'gt', '1.0.0')).toThrow(
'Required inputs not specified.'
)
})

test('should throw an error when versions are invalid', () => {
expect(() => versionCompare('abc', 'gt', '1.0.0')).toThrow(
'Invalid version(s).'
)
expect(() => versionCompare('1.0.0', 'gt', 'abc')).toThrow(
'Invalid version(s).'
)
})

test('should throw an error when operator is invalid', () => {
expect(() => versionCompare('1.0.0', 'abc' as any, '1.0.0')).toThrow(
'Invalid operator.'
)
})

test('should return the correct result', () => {
expect(versionCompare('1.0.0', 'gt', '0.1.0')).toBe(true)
expect(versionCompare('1.0.0', 'lt', '2.0.0')).toBe(true)
expect(versionCompare('1.0.0', 'eq', '1.0.0')).toBe(true)
})
})
18 changes: 18 additions & 0 deletions semver-compare/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: 'SemVer Compare'
description: 'Compare two semantic versions'
inputs:
version1:
description: 'First semantic version'
required: true
version2:
description: 'Second semantic version'
required: true
operator:
description: 'Comparison operator (gt, lt, eq)'
required: true
outputs:
result:
description: 'Comparison result'
runs:
using: 'node16'
main: 'dist/index.js'

0 comments on commit bc6e3b5

Please sign in to comment.