Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate github-action to cli #1487

Merged
merged 25 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b37bbbc
New Github action added for cli
akshatnema Jul 28, 2024
1ddf001
Added new files in the github-action
akshatnema Aug 17, 2024
1877382
Merge branch 'master' into gh-action-for-cli
asyncapi-bot Sep 14, 2024
5fe96e3
removed monorepo style for github action
akshatnema Sep 28, 2024
31ba171
Updated github action with Dockerfile changes
akshatnema Sep 29, 2024
362652a
added command to pack cli for linux, docker build command
akshatnema Sep 29, 2024
e7829a8
Merge branch 'master' into gh-action-for-cli
asyncapi-bot Oct 4, 2024
95cfe27
added test-workflow for github-action
akshatnema Oct 5, 2024
215b477
chore: fix docker context
Shurtu-gal Oct 5, 2024
778dcb2
chore: change docker context
Shurtu-gal Oct 5, 2024
07f1647
fix: dockerfile
Shurtu-gal Oct 5, 2024
7dfd122
changed dockerfile
akshatnema Oct 5, 2024
bc8f651
fix: dockerfile
Shurtu-gal Oct 5, 2024
12ff5b9
Converted Dockerfile into multi stages
akshatnema Oct 5, 2024
e33cc64
added github-action folder
akshatnema Oct 5, 2024
b8e694c
added assets folder to github action image
akshatnema Oct 5, 2024
116d025
deleted act file script
akshatnema Oct 5, 2024
04a2ed5
removed asyncapi.yaml file from .gitignore
akshatnema Oct 5, 2024
3d01213
corrected output file for workflow
akshatnema Oct 5, 2024
eee73a5
Merge branch 'master' into gh-action-for-cli
Shurtu-gal Oct 6, 2024
b33dc47
updated Dockerfile
akshatnema Oct 6, 2024
cc6425d
added bundle file
akshatnema Oct 6, 2024
4de437a
changed bundle files
akshatnema Oct 6, 2024
6934b22
Updated README
akshatnema Oct 6, 2024
16388bb
updated output bundle directory
akshatnema Oct 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Shurtu-gal marked this conversation as resolved.
Show resolved Hide resolved
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
Loading