Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.

Commit 2c68a25

Browse files
authored
feat!: refactor action to be CLI based (#348)
1 parent ae6207b commit 2c68a25

22 files changed

+1158
-24934
lines changed

.eslintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 95 deletions
This file was deleted.

.github/workflows/test-action.yml

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
name: PR testing of CLI action
2+
3+
on:
4+
pull_request:
5+
types: [ opened, synchronize, reopened, ready_for_review ]
6+
7+
jobs:
8+
test-defaults:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- name: Test GitHub Action
13+
uses: ./
14+
with:
15+
filepath: test/asyncapi.yml
16+
- name: Assert GitHub Action
17+
run: |
18+
echo "Listing all files"
19+
ls -R
20+
echo "Asserting GitHub Action"
21+
if [ -f "./output/asyncapi.md" ]; then
22+
echo "Files exist"
23+
else
24+
echo "Files do not exist:- ./output/asyncapi.md"
25+
echo "Action failed"
26+
exit 1
27+
fi
28+
29+
test-validate-success:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
- name: Test GitHub Action
34+
uses: ./
35+
with:
36+
filepath: test/asyncapi.yml
37+
command: validate
38+
39+
test-custom-command:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v4
43+
- name: Test GitHub Action
44+
uses: ./
45+
with:
46+
# Custom command to generate models
47+
# Note: You can use command itself to generate models, but this is just an example for testing custom commands
48+
custom_command: "generate models typescript ./test/asyncapi.yml -o ./output"
49+
- name: Assert GitHub Action
50+
run: |
51+
echo "Listing all files"
52+
ls -R
53+
echo "Asserting GitHub Action"
54+
if [ -f "./output/AnonymousSchema_1.ts" ]; then
55+
echo "Models have been generated"
56+
else
57+
echo "Models have not been generated"
58+
echo "Action failed"
59+
exit 1
60+
fi
61+
62+
test-custom-output:
63+
runs-on: ubuntu-latest
64+
steps:
65+
- uses: actions/checkout@v4
66+
- name: Test GitHub Action
67+
uses: ./
68+
with:
69+
filepath: test/asyncapi.yml
70+
output: custom-output
71+
- name: Assert GitHub Action
72+
run: |
73+
echo "Listing all files"
74+
ls -R
75+
echo "Asserting GitHub Action"
76+
if [ -f "./custom-output/asyncapi.md" ]; then
77+
echo "Files exist"
78+
else
79+
echo "Files do not exist:- ./custom-output/asyncapi.md"
80+
echo "Action failed"
81+
exit 1
82+
fi
83+
84+
test-file-not-found:
85+
runs-on: ubuntu-latest
86+
steps:
87+
- uses: actions/checkout@v4
88+
- name: Test GitHub Action
89+
id: test
90+
uses: ./
91+
with:
92+
filepath: non_existent_file.yml
93+
continue-on-error: true
94+
- name: Check for failure
95+
run: |
96+
if [ "${{ steps.test.outcome }}" == "success" ]; then
97+
echo "Test Failure: non_existent_file.yml should throw an error but did not"
98+
exit 1
99+
else
100+
echo "Test Success: non_existent_file.yml threw an error as expected"
101+
fi
102+
103+
test-invalid-input:
104+
runs-on: ubuntu-latest
105+
steps:
106+
- uses: actions/checkout@v4
107+
- name: Test GitHub Action
108+
id: test
109+
uses: ./
110+
with:
111+
filepath: test/asyncapi.yml
112+
command: generate # No template or language specified
113+
template: '' # Empty string
114+
continue-on-error: true
115+
- name: Check for failure
116+
run: |
117+
if [ "${{ steps.test.outcome }}" == "success" ]; then
118+
echo "Test Failure: generate command should throw an error as no template or language specified but did not"
119+
exit 1
120+
else
121+
echo "Test Success: generate command threw an error as expected"
122+
fi
123+
124+
test-optimize:
125+
runs-on: ubuntu-latest
126+
steps:
127+
- uses: actions/checkout@v4
128+
- name: Test GitHub Action
129+
uses: ./
130+
with:
131+
filepath: test/unoptimized.yml
132+
command: optimize
133+
parameters: '-o new-file --no-tty'
134+
- name: Assert GitHub Action
135+
run: |
136+
echo "Listing all files"
137+
ls -R
138+
echo "Asserting GitHub Action"
139+
if [ -f "./test/unoptimized_optimized.yml" ]; then
140+
echo "The specified file has been optimized"
141+
else
142+
echo "The specified file has not been optimized"
143+
echo "Action failed"
144+
exit 1
145+
fi
146+
147+
test-bundle:
148+
runs-on: ubuntu-latest
149+
steps:
150+
- uses: actions/checkout@v4
151+
- name: Make output directory
152+
run: mkdir -p ./output/bundle
153+
- name: Test GitHub Action
154+
uses: ./
155+
with:
156+
custom_command: 'bundle ./test/bundle/asyncapi.yaml ./test/bundle/features.yaml --base ./test/bundle/asyncapi.yaml --reference-into-components -o ./output/bundle/asyncapi.yaml'
157+
- name: Assert GitHub Action
158+
run: |
159+
echo "Listing all files"
160+
ls -R
161+
echo "Asserting GitHub Action"
162+
if [ -f "./output/bundle/asyncapi.yaml" ]; then
163+
echo "The specified files have been bundled"
164+
else
165+
echo "The specified files have not been bundled"
166+
echo "Action failed"
167+
exit 1
168+
fi
169+
170+
test-convert:
171+
runs-on: ubuntu-latest
172+
steps:
173+
- uses: actions/checkout@v4
174+
- name: Test GitHub Action
175+
uses: ./
176+
with:
177+
command: convert
178+
filepath: test/asyncapi.yml
179+
output: output/convert/asyncapi.yaml
180+
- name: Assert GitHub Action
181+
run: |
182+
echo "Listing all files"
183+
ls -R
184+
echo "Asserting GitHub Action"
185+
if [ -f "./output/convert/asyncapi.yaml" ]; then
186+
echo "The specified file has been converted"
187+
else
188+
echo "The specified file has not been converted"
189+
echo "Action failed"
190+
exit 1
191+
fi

.releaserc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ plugins:
1818
- preset: conventionalcommits
1919
- - "@semantic-release/release-notes-generator"
2020
- preset: conventionalcommits
21-
- "@semantic-release/npm"
2221
- "@semantic-release/github"

.sonarcloud.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# The dockerfile has been excluded from the SonarCloud as this container is meant to be run on GitHub Actions, hence running with security violation is ok
2+
sonar.exclusions=Dockerfile

CODEOWNER

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
# The default owners are automatically added as reviewers when you open a pull request unless different owners are specified in the file.
88

9-
* @derberg @magicmatatjahu @asyncapi-bot-eve
9+
* @derberg @magicmatatjahu @asyncapi-bot-eve @Shurtu-gal

Dockerfile

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
FROM node:16 as builder
1+
FROM node:18-alpine
22

3-
COPY ./ /app
4-
WORKDIR /app
3+
# Create a non-root user
4+
RUN addgroup -S myuser && adduser -S myuser -G myuser
55

6-
RUN npm install
6+
RUN apk add --no-cache bash>5.1.16 git>2.42.0 chromium
77

8-
FROM node:16-alpine
8+
# Environment variables for Puppeteer for PDF generation by HTML Template
9+
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
10+
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
911

10-
COPY --from=builder /app ./
12+
# Installing latest released npm package
13+
RUN npm install --ignore-scripts -g @asyncapi/cli
1114

12-
ENTRYPOINT [ "node", "/lib/index.js" ]
15+
COPY entrypoint.sh /entrypoint.sh
16+
17+
# Make the bash file executable
18+
RUN chmod +x /entrypoint.sh
19+
20+
ENTRYPOINT ["/entrypoint.sh"]

Makefile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
DEFAULT_VERSION = 'latest'
2+
DEFAULT_COMMAND = 'generate'
3+
TEST_FILEPATH = 'test/asyncapi.yml'
4+
DEFAULT_TEMPLATE = '@asyncapi/markdown-template@0.10.0'
5+
DEFAULT_LANGUAGE = ''
6+
DEFAULT_OUTPUT = 'output'
7+
DEFAULT_PARAMETERS = ''
8+
DEFAULT_CUSTOM_COMMANDS = ''
9+
CUSTOM_COMMANDS = 'validate test/asyncapi.yml'
10+
11+
# Add env variables to the shell
12+
export GITHUB_WORKSPACE = $(shell pwd)
13+
14+
run:
15+
@bash ./entrypoint.sh $(DEFAULT_VERSION) $(DEFAULT_COMMAND) $(TEST_FILEPATH) $(DEFAULT_TEMPLATE) $(DEFAULT_LANGUAGE) $(DEFAULT_OUTPUT) $(DEFAULT_PARAMETERS) $(DEFAULT_CUSTOM_COMMANDS)
16+
17+
test: test-default test-validate-success test-validate-fail test-custom-output test-custom-commands test-optimize test-bundle test-convert
18+
19+
# Test cases
20+
21+
# Tests the default configuration without any inputs
22+
test-default:
23+
@bash ./entrypoint.sh $(DEFAULT_VERSION) $(DEFAULT_COMMAND) $(TEST_FILEPATH) $(DEFAULT_TEMPLATE) $(DEFAULT_LANGUAGE) $(DEFAULT_OUTPUT) $(DEFAULT_PARAMETERS) $(DEFAULT_CUSTOM_COMMANDS)
24+
25+
# Tests the validate command with a valid specification
26+
test-validate-success:
27+
@bash ./entrypoint.sh $(DEFAULT_VERSION) 'validate' $(TEST_FILEPATH) $(DEFAULT_TEMPLATE) $(DEFAULT_LANGUAGE) $(DEFAULT_OUTPUT) $(DEFAULT_PARAMETERS) $(DEFAULT_CUSTOM_COMMANDS)
28+
29+
# Tests the validate command with an invalid specification
30+
test-validate-fail:
31+
@bash ./entrypoint.sh $(DEFAULT_VERSION) 'validate' './test/specification-invalid.yml' $(DEFAULT_TEMPLATE) $(DEFAULT_LANGUAGE) $(DEFAULT_OUTPUT) $(DEFAULT_PARAMETERS) $(DEFAULT_CUSTOM_COMMANDS)
32+
33+
# Tests if the generator can output to a custom directory
34+
test-custom-output:
35+
@bash ./entrypoint.sh $(DEFAULT_VERSION) $(DEFAULT_COMMAND) $(TEST_FILEPATH) $(DEFAULT_TEMPLATE) 'typescript' './output/custom-output' $(DEFAULT_PARAMETERS) $(DEFAULT_CUSTOM_COMMANDS)
36+
37+
# Tests if the action prefers custom commands over the default command
38+
test-custom-commands:
39+
@bash ./entrypoint.sh $(DEFAULT_VERSION) $(DEFAULT_COMMAND) $(TEST_FILEPATH) $(DEFAULT_TEMPLATE) 'typescript' './output/custom-output' $(DEFAULT_PARAMETERS) $(CUSTOM_COMMANDS)
40+
41+
# Tests if the action fails when the input is invalid (e.g. invalid template as is the case here)
42+
fail-test:
43+
@bash ./entrypoint.sh $(DEFAULT_VERSION) $(DEFAULT_COMMAND) $(TEST_FILEPATH) '' $(DEFAULT_LANGUAGE) $(DEFAULT_OUTPUT) $(DEFAULT_PARAMETERS) $(DEFAULT_CUSTOM_COMMANDS)
44+
45+
# Tests if the action optimizes the specification
46+
test-optimize:
47+
@bash ./entrypoint.sh $(DEFAULT_VERSION) 'optimize' 'test/unoptimized.yml' $(DEFAULT_TEMPLATE) $(DEFAULT_LANGUAGE) $(DEFAULT_OUTPUT) '-o new-file --no-tty' $(DEFAULT_CUSTOM_COMMANDS)
48+
49+
# Tests if the action can bundle the specification with custom commands
50+
BUNDLE_COMMAND='bundle ./test/bundle/asyncapi.yaml ./test/bundle/features.yaml --base ./test/bundle/asyncapi.yaml --reference-into-components -o ./output/bundle/asyncapi.yaml'
51+
test-bundle:
52+
mkdir -p ./output/bundle
53+
@bash ./entrypoint.sh $(DEFAULT_VERSION) 'bundle' 'test/bundle/asyncapi.yaml' $(DEFAULT_TEMPLATE) $(DEFAULT_LANGUAGE) $(DEFAULT_OUTPUT) '-o output/bundle/asyncapi.yaml' $(BUNDLE_COMMAND)
54+
55+
# Tests if the action can convert the specification with custom commands
56+
test-convert:
57+
@bash ./entrypoint.sh $(DEFAULT_VERSION) 'convert' 'test/asyncapi.yml' $(DEFAULT_TEMPLATE) $(DEFAULT_LANGUAGE) 'output/convert/asyncapi.yaml' '' $(DEFAULT_CUSTOM_COMMANDS)

0 commit comments

Comments
 (0)