Skip to content

Commit

Permalink
New Github action added for cli
Browse files Browse the repository at this point in the history
  • Loading branch information
akshatnema committed Jul 28, 2024
1 parent 283de0f commit b37bbbc
Show file tree
Hide file tree
Showing 13 changed files with 15,985 additions and 0 deletions.
63 changes: 63 additions & 0 deletions github-action/.all-contributorsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"files": [
"README.md"
],
"imageSize": 100,
"commit": false,
"contributors": [
{
"login": "derberg",
"name": "Lukasz Gornicki",
"avatar_url": "https://avatars.githubusercontent.com/u/6995927?v=4",
"profile": "https://www.brainfart.dev/",
"contributions": [
"code",
"maintenance",
"infra",
"review"
]
},
{
"login": "magicmatatjahu",
"name": "Maciej Urbańczyk",
"avatar_url": "https://avatars.githubusercontent.com/u/20404945?v=4",
"profile": "https://github.com/magicmatatjahu",
"contributions": [
"review"
]
},
{
"login": "victormartingarcia",
"name": "Victor",
"avatar_url": "https://avatars.githubusercontent.com/u/659832?v=4",
"profile": "https://www.victormartingarcia.com",
"contributions": [
"code"
]
},
{
"login": "HUTCHHUTCHHUTCH",
"name": "HUTCHHUTCHHUTCH",
"avatar_url": "https://avatars.githubusercontent.com/u/55915170?v=4",
"profile": "https://github.com/HUTCHHUTCHHUTCH",
"contributions": [
"infra"
]
},
{
"login": "pioneer2k",
"name": "Thomas Heyer",
"avatar_url": "https://avatars.githubusercontent.com/u/32297829?v=4",
"profile": "https://github.com/pioneer2k",
"contributions": [
"infra"
]
}
],
"contributorsPerLine": 7,
"projectName": "github-action-for-generator",
"projectOwner": "asyncapi",
"repoType": "github",
"repoHost": "https://github.com",
"commitConvention": "none"
}
6 changes: 6 additions & 0 deletions github-action/.asyncapi-tool
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
title: GitHub Action for Generator
filters:
technology:
- AsyncAPI Generator
categories:
- github-actions
2 changes: 2 additions & 0 deletions github-action/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
output
node_modules
95 changes: 95 additions & 0 deletions github-action/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
env:
node: true
es6: true

plugins:
- sonarjs

extends:
- plugin:sonarjs/recommended

parserOptions:
ecmaVersion: 2018

rules:
# Ignore Rules
strict: 0
no-underscore-dangle: 0
no-mixed-requires: 0
no-process-exit: 0
no-warning-comments: 0
curly: 0
no-multi-spaces: 0
no-alert: 0
consistent-return: 0
consistent-this: [0, self]
func-style: 0
max-nested-callbacks: 0

# Warnings
no-debugger: 1
no-empty: 1
no-invalid-regexp: 1
no-unused-expressions: 1
no-native-reassign: 1
no-fallthrough: 1
camelcase: 0

# Errors
eqeqeq: 2
no-undef: 2
no-dupe-keys: 2
no-empty-character-class: 2
no-self-compare: 2
valid-typeof: 2
no-unused-vars: [2, { "args": "none" }]
handle-callback-err: 2
no-shadow-restricted-names: 2
no-new-require: 2
no-mixed-spaces-and-tabs: 2
block-scoped-var: 2
no-else-return: 2
no-throw-literal: 2
no-void: 2
radix: 2
wrap-iife: [2, outside]
no-shadow: 0
no-use-before-define: [2, nofunc]
no-path-concat: 2
valid-jsdoc: [0, {requireReturn: false, requireParamDescription: false, requireReturnDescription: false}]

# stylistic errors
no-spaced-func: 2
semi-spacing: 2
quotes: [2, 'single']
key-spacing: [2, { beforeColon: false, afterColon: true }]
indent: [2, 2]
no-lonely-if: 2
no-floating-decimal: 2
brace-style: [2, 1tbs, { allowSingleLine: true }]
comma-style: [2, last]
no-multiple-empty-lines: [2, {max: 1}]
no-nested-ternary: 2
operator-assignment: [2, always]
padded-blocks: [2, never]
quote-props: [2, as-needed]
keyword-spacing: [2, {'before': true, 'after': true, 'overrides': {}}]
space-before-blocks: [2, always]
array-bracket-spacing: [2, never]
computed-property-spacing: [2, never]
space-in-parens: [2, never]
space-unary-ops: [2, {words: true, nonwords: false}]
wrap-regex: 2
linebreak-style: 0
semi: [2, always]
arrow-spacing: [2, {before: true, after: true}]
no-class-assign: 2
no-const-assign: 2
no-dupe-class-members: 2
no-this-before-super: 2
no-var: 2
object-shorthand: [2, always]
prefer-arrow-callback: 2
prefer-const: 2
prefer-spread: 2
prefer-template: 2
5 changes: 5 additions & 0 deletions github-action/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
coverage
.DS_Store
output
node_modules
dist
15 changes: 15 additions & 0 deletions github-action/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:14 as builder

COPY ./ /app
WORKDIR /app

RUN npm install && npm run package

FROM node:14-alpine

# We need to copy entire node modules as some dependencies (@npmcli/run-script) cannot be packaged
# and need to be used by dist as external dependency
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist

ENTRYPOINT [ "node", "/dist/index.js" ]
127 changes: 127 additions & 0 deletions github-action/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# GitHub Action for Generator
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-5-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

This action generates whatever you want using your AsyncAPI document. It uses [AsyncAPI Generator](https://github.com/asyncapi/generator/).

## Inputs

### `template`

Template for the generator. Official templates are listed here https://github.com/asyncapi/generator#list-of-official-generator-templates. You can pass template as npm package, url to git repository, link to tar file or local template.

**Default** points to `@asyncapi/[email protected]` template.

> We recommend to always specify the version of the template to not encounter any issues with the action in case of release of the template that is not compatible with given version of the generator.
### `filepath`

Location of the AsyncAPI document.

**Default** expects `asyncapi.yml` in the root of the working directory.

### `parameters`

The template that you use might support and even require specific parameters to be passed to the template for the generation.

### `output`

Directory where to put the generated files.

**Default** points to `output` directory in the working directory.

## Example usage

### Basic

In case all defaults are fine for you, just add such step:

```yaml
- name: Generating Markdown from my AsyncAPI document
uses: docker://asyncapi/github-action-for-generator:2.0.0
```
### Using all possible inputs
In case you do not want to use defaults, you for example want to use different template:
```yaml
- name: Generating HTML from my AsyncAPI document
uses: docker://asyncapi/github-action-for-generator:2.0.0
with:
template: '@asyncapi/[email protected]' #In case of template from npm, because of @ it must be in quotes
filepath: docs/api/my-asyncapi.yml
parameters: baseHref=/test-experiment/ sidebarOrganization=byTags #space separated list of key/values
output: generated-html
```
### Example workflow with publishing generated HTML to GitHub Pages
In case you want to validate your asyncapi file first, and also send generated HTML to GitHub Pages this is how full workflow could look like:
```yaml
name: AsyncAPI documents processing

on:
push:
branches: [ master ]

jobs:
generate:
runs-on: ubuntu-latest
steps:
#"standard step" where repo needs to be checked-out first
- name: Checkout repo
uses: actions/checkout@v2

#Using another action for AsyncAPI for validation
- name: Validating AsyncAPI document
uses: WaleedAshraf/[email protected]
with:
filepath: docs/api/my-asyncapi.yml

#In case you do not want to use defaults, you for example want to use different template
- name: Generating HTML from my AsyncAPI document
uses: docker://asyncapi/github-action-for-generator:2.0.0
with:
template: '@asyncapi/[email protected]' #In case of template from npm, because of @ it must be in quotes
filepath: docs/api/my-asyncapi.yml
parameters: baseHref=/test-experiment/ sidebarOrganization=byTags #space separated list of key/values
output: generated-html

#Using another action that takes generated HTML and pushes it to GH Pages
- name: Deploy GH page
uses: JamesIves/[email protected]
with:
ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: generated-html
```
## Troubleshooting
You can enable more log information in GitHub Action by adding `ACTIONS_STEP_DEBUG` secret to repository where you want to use this action. Set the value of this secret to `true` and you''ll notice more debug logs from this action.
## Contributors

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://www.brainfart.dev/"><img src="https://avatars.githubusercontent.com/u/6995927?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lukasz Gornicki</b></sub></a><br /><a href="https://github.com/asyncapi/github-action-for-generator/commits?author=derberg" title="Code">💻</a> <a href="#maintenance-derberg" title="Maintenance">🚧</a> <a href="#infra-derberg" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/asyncapi/github-action-for-generator/pulls?q=is%3Apr+reviewed-by%3Aderberg" title="Reviewed Pull Requests">👀</a></td>
<td align="center"><a href="https://github.com/magicmatatjahu"><img src="https://avatars.githubusercontent.com/u/20404945?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Maciej Urbańczyk</b></sub></a><br /><a href="https://github.com/asyncapi/github-action-for-generator/pulls?q=is%3Apr+reviewed-by%3Amagicmatatjahu" title="Reviewed Pull Requests">👀</a></td>
<td align="center"><a href="https://www.victormartingarcia.com"><img src="https://avatars.githubusercontent.com/u/659832?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Victor</b></sub></a><br /><a href="https://github.com/asyncapi/github-action-for-generator/commits?author=victormartingarcia" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/HUTCHHUTCHHUTCH"><img src="https://avatars.githubusercontent.com/u/55915170?v=4?s=100" width="100px;" alt=""/><br /><sub><b>HUTCHHUTCHHUTCH</b></sub></a><br /><a href="#infra-HUTCHHUTCHHUTCH" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
<td align="center"><a href="https://github.com/pioneer2k"><img src="https://avatars.githubusercontent.com/u/32297829?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Thomas Heyer</b></sub></a><br /><a href="#infra-pioneer2k" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
</tr>
</table>

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
24 changes: 24 additions & 0 deletions github-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 'Generator for AsyncAPI documents'
description: 'Use this action to generate docs or code from your AsyncAPI document. Use default templates or provide your custom ones.'
inputs:
template:
description: 'Template for the generator. Official templates are listed here https://github.com/search?q=topic%3Aasyncapi+topic%3Agenerator+topic%3Atemplate. You can pass template as npm package, url to git repository, link to tar file or local template.'
default: '@asyncapi/[email protected]'
required: false
filepath:
description: 'Location of the AsyncAPI document.'
default: 'asyncapi.yml'
required: false
parameters:
description: 'The template that you use might support and even require specific parameters to be passed to the template for the generation.'
required: false
output:
description: 'Directory where to put the generated files.'
required: false
default: 'output'
runs:
using: 'node12'
main: 'dist/index.js'
branding:
icon: 'file-text'
color: purple
44 changes: 44 additions & 0 deletions github-action/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const core = require('@actions/core');
const Generator = require('@asyncapi/generator');
const path = require('path');
const fs = require('fs');
const { paramParser, createOutputDir } = require('./utils');

const DEFAULT_TEMPLATE = '@asyncapi/[email protected]';
const DEFAULT_FILEPATH = 'asyncapi.yml';
const DEFAULT_OUTPUT = 'output';

async function run() {
try {
const template = core.getInput('template') || DEFAULT_TEMPLATE;
const filepath = core.getInput('filepath') || DEFAULT_FILEPATH;
const parameters = paramParser(core.getInput('parameters'));
const output = core.getInput('output') || DEFAULT_OUTPUT;
const workdir = process.env.GITHUB_WORKSPACE || __dirname;
const absoluteOutputPath = path.resolve(workdir, output);
const pathToAsyncapiFile = path.resolve(workdir, filepath);

//Below additional log information is visible only if you add ACTIONS_STEP_DEBUG secret to your repository where you run your action.
//The value of this secret must be "true"
core.debug(`Template: ${template}`);
core.debug(`Filepath: ${filepath}`);
core.debug(`Parameters: ${JSON.stringify(parameters)}`);
core.debug(`Output: ${output}`);
core.debug(`Workdir: ${workdir}`);
core.debug(`Workdir contents: ${fs.readdirSync(workdir)}`);
core.debug(`AbsoluteOutputPath: ${absoluteOutputPath}`);
core.debug(`PathToAsyncapiFile: ${pathToAsyncapiFile}`);

createOutputDir(absoluteOutputPath);

const generator = new Generator(template, absoluteOutputPath, {
templateParams: parameters,
forceWrite: true
});
await generator.generateFromFile(pathToAsyncapiFile);
} catch (e) {
core.setFailed(e.message);
}
}

run();
Loading

0 comments on commit b37bbbc

Please sign in to comment.