Skip to content

Commit

Permalink
Merge pull request #380 from hey-api/package/upload-openapi-spec
Browse files Browse the repository at this point in the history
chore: add upload-openapi-spec package
  • Loading branch information
mrlubos authored Apr 13, 2024
2 parents 030bab7 + 135541e commit 0ae5343
Show file tree
Hide file tree
Showing 20 changed files with 2,821 additions and 31 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"test:e2e": "pnpm --recursive test:e2e",
"test:update": "pnpm --recursive test:update",
"test": "pnpm --recursive test",
"typecheck": "pnpm --recursive typecheck"
"typecheck": "pnpm --recursive typecheck",
"upload-openapi-spec": "pnpm --filter @hey-api/upload-openapi-spec --"
},
"engines": {
"node": "^18.0.0 || >=20.0.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/upload-openapi-spec/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lib/
dist/
node_modules/
coverage/
3 changes: 3 additions & 0 deletions packages/upload-openapi-spec/.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 packages/upload-openapi-spec/.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 packages/upload-openapi-spec/.node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.6.0
3 changes: 3 additions & 0 deletions packages/upload-openapi-spec/.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 packages/upload-openapi-spec/.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 packages/upload-openapi-spec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Upload OpenAPI Specification Action

This action will upload your OpenAPI specification to Hey API.
17 changes: 17 additions & 0 deletions packages/upload-openapi-spec/__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()
// })
// })
89 changes: 89 additions & 0 deletions packages/upload-openapi-spec/__tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* Unit tests for the action's main functionality, src/main.ts
*
* These should be run as if the action was called from a workflow.
* Specifically, the inputs listed in `action.yml` should be set as environment
* variables following the pattern `INPUT_<INPUT_NAME>`.
*/

// import * as core from '@actions/core'
// import * as main from '../src/main'

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

// // Other utilities
// const timeRegex = /^\d{2}:\d{2}:\d{2}/

// // Mock the GitHub Actions core library
// let debugMock: jest.SpiedFunction<typeof core.debug>
// let errorMock: jest.SpiedFunction<typeof core.error>
// let getInputMock: jest.SpiedFunction<typeof core.getInput>
// let setFailedMock: jest.SpiedFunction<typeof core.setFailed>
// let setOutputMock: jest.SpiedFunction<typeof core.setOutput>

// describe('action', () => {
// beforeEach(() => {
// jest.clearAllMocks()

// debugMock = jest.spyOn(core, 'debug').mockImplementation()
// errorMock = jest.spyOn(core, 'error').mockImplementation()
// getInputMock = jest.spyOn(core, 'getInput').mockImplementation()
// setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation()
// setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation()
// })

// it('sets the time output', async () => {
// // Set the action's inputs as return values from core.getInput()
// getInputMock.mockImplementation(name => {
// switch (name) {
// case 'milliseconds':
// return '500'
// default:
// return ''
// }
// })

// await main.run()
// expect(runMock).toHaveReturned()

// // Verify that all of the core library functions were called correctly
// expect(debugMock).toHaveBeenNthCalledWith(1, 'Waiting 500 milliseconds ...')
// expect(debugMock).toHaveBeenNthCalledWith(
// 2,
// expect.stringMatching(timeRegex)
// )
// expect(debugMock).toHaveBeenNthCalledWith(
// 3,
// expect.stringMatching(timeRegex)
// )
// expect(setOutputMock).toHaveBeenNthCalledWith(
// 1,
// 'time',
// expect.stringMatching(timeRegex)
// )
// expect(errorMock).not.toHaveBeenCalled()
// })

// it('sets a failed status', async () => {
// // Set the action's inputs as return values from core.getInput()
// getInputMock.mockImplementation(name => {
// switch (name) {
// case 'milliseconds':
// return 'this is not a number'
// default:
// return ''
// }
// })

// await main.run()
// expect(runMock).toHaveReturned()

// // Verify that all of the core library functions were called correctly
// expect(setFailedMock).toHaveBeenNthCalledWith(
// 1,
// 'milliseconds not a number'
// )
// expect(errorMock).not.toHaveBeenCalled()
// })
// })
25 changes: 25 additions & 0 deletions packages/upload-openapi-spec/__tests__/wait.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Unit tests for src/wait.ts
*/

// import { wait } from '../src/wait'
// import { expect } from '@jest/globals'

// describe('wait.ts', () => {
// it('throws an invalid number', async () => {
// const input = parseInt('foo', 10)
// expect(isNaN(input)).toBe(true)

// await expect(wait(input)).rejects.toThrow('milliseconds not a number')
// })

// it('waits with a valid number', async () => {
// const start = new Date()
// await wait(500)
// const end = new Date()

// const delta = Math.abs(end.getTime() - start.getTime())

// expect(delta).toBeGreaterThan(450)
// })
// })
20 changes: 20 additions & 0 deletions packages/upload-openapi-spec/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Upload OpenAPI spec
description: Upload your OpenAPI specification to Hey API
author: Hey API

branding:
icon: heart
color: red

inputs:
# TOOD: add token support
# hey-api-token:
# description: Hey API service token
# required: true
path-to-openapi:
description: Input path to your OpenAPI specification file
required: true

runs:
using: node20
main: dist/index.js
1 change: 1 addition & 0 deletions packages/upload-openapi-spec/badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0ae5343

Please sign in to comment.