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 6 commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ asyncapi.yml
test/fixtures/minimaltemplate/__transpiled
.vscode

/action/
/github-action/output/

oclif.manifest.json
spec-examples.zip

Expand Down
54 changes: 54 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: 'Generator, Validator, Converter and others - all in one for your AsyncAPI docs'
description: 'Use this action to generate docs or code from your AsyncAPI document. Use default templates or provide your custom ones.'
inputs:
cli_version:
description: 'Version of AsyncAPI CLI to be used. This is only needed if you want to test with a specific version of AsyncAPI CLI. Default is latest which is also the recommended option.'
required: false
default: ''
command:
description: 'Command to run. Available commands in action :- generate, validate, convert, optimize and custom. Default is generate. For custom command, provide the whole command as input. List of available commands can be found in https://www.asyncapi.com/docs/tools/cli/usage.'
required: false
default: 'generate'
filepath:
description: 'Path to AsyncAPI document. This input is required if command is set to generate, validate, convert or optimize. Default is ./asyncapi.yaml'
required: false
default: 'asyncapi.yml'
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/markdown-template@0.10.0'
required: false
language:
description: 'Language of the generated code. This input is required if you want to generate models. List of available languages can be found in https://www.asyncapi.com/docs/tools/cli/usage#asyncapi-generate-models-language-file'
required: false
default: ''
output:
description: 'Directory where to put the generated files. Can be used only with generate or convert commands. Default is output.'
required: false
default: 'output'
parameters:
description: 'The command that you use might support and even require specific parameters to be passed to the CLI for the generation. Template parameters should be preceded by -p'
required: false
default: ''
custom_command:
description: 'Custom command to be run. This input is required if command is set to custom.'
required: false
default: ''

runs:
using: 'docker'
# This is the image that will be used to run the action.
# IMPORTANT: The version has to be changed manually in your PRs.
image: 'docker://asyncapi/github-action-for-cli:3.1.2'
args:
- ${{ inputs.cli_version }}
- ${{ inputs.command }}
- ${{ inputs.filepath }}
- ${{ inputs.template }}
- ${{ inputs.language }}
- ${{ inputs.output }}
- ${{ inputs.parameters }}
- ${{ inputs.custom_command }}

branding:
icon: 'file-text'
color: purple
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
38 changes: 38 additions & 0 deletions github-action/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM node:18-alpine

# Create a non-root user
RUN addgroup -S myuser && adduser -S myuser -G myuser

# Install necessary packages
RUN apk add --no-cache bash git chromium

Check notice

Code scanning / SonarCloud

Arguments in long RUN instructions should be sorted Low

Sort these package names alphanumerically. See more on SonarCloud

# Environment variables for Puppeteer
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser

FROM ubuntu:latest

# Copy the asyncapi directory
COPY tmp/asyncapi/ /asyncapi

# Create a script that runs the desired command
RUN echo "#!/bin/bash\n/asyncapi/bin/run" > /usr/local/bin/asyncapi

# Make the script executable
RUN chmod +x /usr/local/bin/asyncapi

RUN ls -l /usr/local/bin/asyncapi

# Change ownership to non-root user
RUN chown -R myuser:myuser /asyncapi /usr/local/bin/asyncapi || echo "Failed to change ownership"

# Copy the entrypoint script
COPY github-action/entrypoint.sh /entrypoint.sh

# Make the entrypoint script executable
RUN chmod +x /entrypoint.sh

FROM node:18-alpine

# Set the entrypoint
ENTRYPOINT ["/entrypoint.sh"]
61 changes: 61 additions & 0 deletions github-action/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
DEFAULT_VERSION = 'latest'
DEFAULT_COMMAND = 'generate'
TEST_FILEPATH = 'test/asyncapi.yml'
DEFAULT_TEMPLATE = '@asyncapi/markdown-template@0.10.0'
DEFAULT_LANGUAGE = ''
DEFAULT_OUTPUT = 'output'
DEFAULT_PARAMETERS = ''
DEFAULT_CUSTOM_COMMANDS = ''
CUSTOM_COMMANDS = 'validate test/asyncapi.yml'

# Add env variables to the shell
export GITHUB_WORKSPACE = $(shell pwd)

run:
@bash ./entrypoint.sh $(DEFAULT_VERSION) $(DEFAULT_COMMAND) $(TEST_FILEPATH) $(DEFAULT_TEMPLATE) $(DEFAULT_LANGUAGE) $(DEFAULT_OUTPUT) $(DEFAULT_PARAMETERS) $(DEFAULT_CUSTOM_COMMANDS)

test: test-default test-validate-success test-custom-output test-custom-commands test-optimize test-bundle test-convert test-action-bump

# Test cases

# Tests if the action has been bumped greater than the latest release
test-action-bump:
@bash bump-test.sh

# Tests the default configuration without any inputs
test-default:
@bash ./entrypoint.sh $(DEFAULT_VERSION) $(DEFAULT_COMMAND) $(TEST_FILEPATH) $(DEFAULT_TEMPLATE) $(DEFAULT_LANGUAGE) $(DEFAULT_OUTPUT) $(DEFAULT_PARAMETERS) $(DEFAULT_CUSTOM_COMMANDS)

# Tests the validate command with a valid specification
test-validate-success:
@bash ./entrypoint.sh $(DEFAULT_VERSION) 'validate' $(TEST_FILEPATH) $(DEFAULT_TEMPLATE) $(DEFAULT_LANGUAGE) $(DEFAULT_OUTPUT) $(DEFAULT_PARAMETERS) $(DEFAULT_CUSTOM_COMMANDS)

# Tests the validate command with an invalid specification
test-validate-fail:
@bash ./entrypoint.sh $(DEFAULT_VERSION) 'validate' './test/specification-invalid.yml' $(DEFAULT_TEMPLATE) $(DEFAULT_LANGUAGE) $(DEFAULT_OUTPUT) $(DEFAULT_PARAMETERS) $(DEFAULT_CUSTOM_COMMANDS)

# Tests if the generator can output to a custom directory
test-custom-output:
@bash ./entrypoint.sh $(DEFAULT_VERSION) $(DEFAULT_COMMAND) $(TEST_FILEPATH) $(DEFAULT_TEMPLATE) 'typescript' './output/custom-output' $(DEFAULT_PARAMETERS) $(DEFAULT_CUSTOM_COMMANDS)

# Tests if the action prefers custom commands over the default command
test-custom-commands:
@bash ./entrypoint.sh $(DEFAULT_VERSION) $(DEFAULT_COMMAND) $(TEST_FILEPATH) $(DEFAULT_TEMPLATE) 'typescript' './output/custom-output' $(DEFAULT_PARAMETERS) $(CUSTOM_COMMANDS)

# Tests if the action fails when the input is invalid (e.g. invalid template as is the case here)
fail-test:
@bash ./entrypoint.sh $(DEFAULT_VERSION) $(DEFAULT_COMMAND) $(TEST_FILEPATH) '' $(DEFAULT_LANGUAGE) $(DEFAULT_OUTPUT) $(DEFAULT_PARAMETERS) $(DEFAULT_CUSTOM_COMMANDS)

# Tests if the action optimizes the specification
test-optimize:
@bash ./entrypoint.sh $(DEFAULT_VERSION) 'optimize' 'test/unoptimized.yml' $(DEFAULT_TEMPLATE) $(DEFAULT_LANGUAGE) $(DEFAULT_OUTPUT) '-o new-file --no-tty' $(DEFAULT_CUSTOM_COMMANDS)

# Tests if the action can bundle the specification with custom commands
BUNDLE_COMMAND='bundle ./test/bundle/asyncapi.yaml ./test/bundle/features.yaml --base ./test/bundle/asyncapi.yaml -o ./output/bundle/asyncapi.yaml'
test-bundle:
mkdir -p ./output/bundle
@bash ./entrypoint.sh $(DEFAULT_VERSION) 'bundle' 'test/bundle/asyncapi.yaml' $(DEFAULT_TEMPLATE) $(DEFAULT_LANGUAGE) $(DEFAULT_OUTPUT) '-o output/bundle/asyncapi.yaml' $(BUNDLE_COMMAND)

# Tests if the action can convert the specification with custom commands
test-convert:
@bash ./entrypoint.sh $(DEFAULT_VERSION) 'convert' 'test/asyncapi.yml' $(DEFAULT_TEMPLATE) $(DEFAULT_LANGUAGE) 'output/convert/asyncapi.yaml' '' $(DEFAULT_CUSTOM_COMMANDS)
Loading
Loading