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

Commit 01993be

Browse files
authored
feat: add docker support to action directly (#375)
1 parent e050f87 commit 01993be

File tree

8 files changed

+164
-21
lines changed

8 files changed

+164
-21
lines changed

.github/workflows/test-action.yml

Lines changed: 121 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,51 @@ jobs:
2828
outputs:
2929
shouldrun: ${{ steps.should_run.outputs.shouldrun }}
3030

31+
build-docker:
32+
needs: should-workflow-run
33+
name: Build Docker image
34+
if: ${{ needs.should-workflow-run.outputs.shouldrun == 'true' }}
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v4
38+
- name: Get docker version
39+
id: docker_version
40+
run: >
41+
ls -la;
42+
action=$(cat action.yml);
43+
regex='docker:\/\/asyncapi\/github-action-for-cli:([0-9.]+)';
44+
[[ $action =~ $regex ]];
45+
action_version=${BASH_REMATCH[1]};
46+
echo "action_version=$action_version" >> $GITHUB_OUTPUT
47+
- name: Set up Docker Buildx
48+
uses: docker/setup-buildx-action@v3
49+
- name: Build Docker image and export
50+
uses: docker/build-push-action@v5
51+
with:
52+
context: .
53+
tags: asyncapi/github-action-for-cli:${{ steps.docker_version.outputs.action_version }}
54+
outputs: type=docker,dest=/tmp/asyncapi.tar
55+
- name: Upload artifact
56+
uses: actions/upload-artifact@v3
57+
with:
58+
name: asyncapi
59+
path: /tmp/asyncapi.tar
60+
61+
3162
test-defaults:
3263
if: ${{ needs.should-workflow-run.outputs.shouldrun == 'true' }}
3364
runs-on: ubuntu-latest
34-
needs: should-workflow-run
65+
needs: [should-workflow-run, build-docker]
3566
steps:
67+
- name: Download artifact
68+
uses: actions/download-artifact@v3
69+
with:
70+
name: asyncapi
71+
path: /tmp
72+
- name: Load Docker image
73+
run: |
74+
docker load --input /tmp/asyncapi.tar
75+
docker image ls -a
3676
- uses: actions/checkout@v4
3777
- name: Test GitHub Action
3878
uses: ./
@@ -54,8 +94,17 @@ jobs:
5494
test-validate-success:
5595
if: ${{ needs.should-workflow-run.outputs.shouldrun == 'true' }}
5696
runs-on: ubuntu-latest
57-
needs: should-workflow-run
97+
needs: [should-workflow-run, build-docker]
5898
steps:
99+
- name: Download artifact
100+
uses: actions/download-artifact@v3
101+
with:
102+
name: asyncapi
103+
path: /tmp
104+
- name: Load Docker image
105+
run: |
106+
docker load --input /tmp/asyncapi.tar
107+
docker image ls -a
59108
- uses: actions/checkout@v4
60109
- name: Test GitHub Action
61110
uses: ./
@@ -66,8 +115,17 @@ jobs:
66115
test-custom-command:
67116
if: ${{ needs.should-workflow-run.outputs.shouldrun == 'true' }}
68117
runs-on: ubuntu-latest
69-
needs: should-workflow-run
118+
needs: [should-workflow-run, build-docker]
70119
steps:
120+
- name: Download artifact
121+
uses: actions/download-artifact@v3
122+
with:
123+
name: asyncapi
124+
path: /tmp
125+
- name: Load Docker image
126+
run: |
127+
docker load --input /tmp/asyncapi.tar
128+
docker image ls -a
71129
- uses: actions/checkout@v4
72130
- name: Test GitHub Action
73131
uses: ./
@@ -91,8 +149,17 @@ jobs:
91149
test-custom-output:
92150
if: ${{ needs.should-workflow-run.outputs.shouldrun == 'true' }}
93151
runs-on: ubuntu-latest
94-
needs: should-workflow-run
152+
needs: [should-workflow-run, build-docker]
95153
steps:
154+
- name: Download artifact
155+
uses: actions/download-artifact@v3
156+
with:
157+
name: asyncapi
158+
path: /tmp
159+
- name: Load Docker image
160+
run: |
161+
docker load --input /tmp/asyncapi.tar
162+
docker image ls -a
96163
- uses: actions/checkout@v4
97164
- name: Test GitHub Action
98165
uses: ./
@@ -115,8 +182,17 @@ jobs:
115182
test-file-not-found:
116183
if: ${{ needs.should-workflow-run.outputs.shouldrun == 'true' }}
117184
runs-on: ubuntu-latest
118-
needs: should-workflow-run
185+
needs: [should-workflow-run, build-docker]
119186
steps:
187+
- name: Download artifact
188+
uses: actions/download-artifact@v3
189+
with:
190+
name: asyncapi
191+
path: /tmp
192+
- name: Load Docker image
193+
run: |
194+
docker load --input /tmp/asyncapi.tar
195+
docker image ls -a
120196
- uses: actions/checkout@v4
121197
- name: Test GitHub Action
122198
id: test
@@ -136,8 +212,17 @@ jobs:
136212
test-invalid-input:
137213
if: ${{ needs.should-workflow-run.outputs.shouldrun == 'true' }}
138214
runs-on: ubuntu-latest
139-
needs: should-workflow-run
215+
needs: [should-workflow-run, build-docker]
140216
steps:
217+
- name: Download artifact
218+
uses: actions/download-artifact@v3
219+
with:
220+
name: asyncapi
221+
path: /tmp
222+
- name: Load Docker image
223+
run: |
224+
docker load --input /tmp/asyncapi.tar
225+
docker image ls -a
141226
- uses: actions/checkout@v4
142227
- name: Test GitHub Action
143228
id: test
@@ -159,8 +244,17 @@ jobs:
159244
test-optimize:
160245
if: ${{ needs.should-workflow-run.outputs.shouldrun == 'true' }}
161246
runs-on: ubuntu-latest
162-
needs: should-workflow-run
247+
needs: [should-workflow-run, build-docker]
163248
steps:
249+
- name: Download artifact
250+
uses: actions/download-artifact@v3
251+
with:
252+
name: asyncapi
253+
path: /tmp
254+
- name: Load Docker image
255+
run: |
256+
docker load --input /tmp/asyncapi.tar
257+
docker image ls -a
164258
- uses: actions/checkout@v4
165259
- name: Test GitHub Action
166260
uses: ./
@@ -184,8 +278,17 @@ jobs:
184278
test-bundle:
185279
if: ${{ needs.should-workflow-run.outputs.shouldrun == 'true' }}
186280
runs-on: ubuntu-latest
187-
needs: should-workflow-run
281+
needs: [should-workflow-run, build-docker]
188282
steps:
283+
- name: Download artifact
284+
uses: actions/download-artifact@v3
285+
with:
286+
name: asyncapi
287+
path: /tmp
288+
- name: Load Docker image
289+
run: |
290+
docker load --input /tmp/asyncapi.tar
291+
docker image ls -a
189292
- uses: actions/checkout@v4
190293
- name: Make output directory
191294
run: mkdir -p ./output/bundle
@@ -209,8 +312,17 @@ jobs:
209312
test-convert:
210313
if: ${{ needs.should-workflow-run.outputs.shouldrun == 'true' }}
211314
runs-on: ubuntu-latest
212-
needs: should-workflow-run
315+
needs: [should-workflow-run, build-docker]
213316
steps:
317+
- name: Download artifact
318+
uses: actions/download-artifact@v3
319+
with:
320+
name: asyncapi
321+
path: /tmp
322+
- name: Load Docker image
323+
run: |
324+
docker load --input /tmp/asyncapi.tar
325+
docker image ls -a
214326
- uses: actions/checkout@v4
215327
- name: Test GitHub Action
216328
uses: ./

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ coverage
22
.DS_Store
33
output
44
node_modules
5-
dist
5+
dist
6+
test/unoptimized_optimized.yml

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ export GITHUB_WORKSPACE = $(shell pwd)
1414
run:
1515
@bash ./entrypoint.sh $(DEFAULT_VERSION) $(DEFAULT_COMMAND) $(TEST_FILEPATH) $(DEFAULT_TEMPLATE) $(DEFAULT_LANGUAGE) $(DEFAULT_OUTPUT) $(DEFAULT_PARAMETERS) $(DEFAULT_CUSTOM_COMMANDS)
1616

17-
test: test-default test-validate-success test-validate-fail test-custom-output test-custom-commands test-optimize test-bundle test-convert
17+
test: test-default test-validate-success test-validate-fail test-custom-output test-custom-commands test-optimize test-bundle test-convert test-action-bump
1818

1919
# Test cases
2020

21+
# Tests if the action has been bumped greater than the latest release
22+
test-action-bump:
23+
@bash bump-test.sh
24+
2125
# Tests the default configuration without any inputs
2226
test-default:
2327
@bash ./entrypoint.sh $(DEFAULT_VERSION) $(DEFAULT_COMMAND) $(TEST_FILEPATH) $(DEFAULT_TEMPLATE) $(DEFAULT_LANGUAGE) $(DEFAULT_OUTPUT) $(DEFAULT_PARAMETERS) $(DEFAULT_CUSTOM_COMMANDS)

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Sample usage:
4141

4242
```yaml
4343
- name: Generating HTML from my AsyncAPI document
44-
uses: docker://asyncapi/github-action-for-cli:2.0.0
44+
uses: asyncapi/github-action-for-cli@v3.0.2 # You can use any version you want
4545
with:
4646
custom_command: bundle ./asyncapi.yaml --output final-asyncapi.yaml
4747
```
@@ -91,15 +91,20 @@ The command that you use might support and even require specific parameters to b
9191
> [!NOTE]
9292
> For template parameters, you need to pass them as `-p <template_parameters>` as can be seen in CLI documentation.
9393

94+
9495
## Example usage
9596

97+
> [!WARNING]
98+
> Using `docker://asyncapi/github-action-for-cli` will not work as expected. This is because the GitHub Actions runner does not pass params to the docker image correctly. This is why we recommend to use `asyncapi/github-action-for-cli` instead.
99+
> However, you don't need to worry as it won't build the image every time. It will pull it from Docker Hub as it is already built there.
100+
96101
### Basic
97102

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

100105
```yaml
101106
- name: Generating Markdown from my AsyncAPI document
102-
uses: docker://asyncapi/github-action-for-cli:3.0.0
107+
uses: asyncapi/github-action-for-cli@v3.0.2 # You can use any version you want
103108
```
104109

105110
### Using all possible inputs
@@ -108,7 +113,7 @@ In case you do not want to use defaults, you for example want to use different t
108113

109114
```yaml
110115
- name: Generating HTML from my AsyncAPI document
111-
uses: docker://asyncapi/github-action-for-cli:3.0.0
116+
uses: asyncapi/github-action-for-cli@v3.0.2 # You can use any version you want
112117
with:
113118
command: generate
114119
filepath: ./docs/api/asyncapi.yaml
@@ -140,7 +145,7 @@ jobs:
140145
141146
#In case you do not want to use defaults, you for example want to use different template
142147
- name: Generating HTML from my AsyncAPI document
143-
uses: docker://asyncapi/github-action-for-cli:3.0.0
148+
uses: asyncapi/github-action-for-cli@v3.0.2 # You can use any version you want
144149
with:
145150
template: '@asyncapi/html-template@0.9.0' #In case of template from npm, because of @ it must be in quotes
146151
filepath: docs/api/my-asyncapi.yml
@@ -177,7 +182,7 @@ jobs:
177182
uses: actions/checkout@v2
178183
179184
- name: Generating models from my AsyncAPI document
180-
uses: docker://asyncapi/github-action-for-cli:3.0.0
185+
uses: asyncapi/github-action-for-cli@v3.0.2 # You can use any version you want
181186
with:
182187
command: generate
183188
filepath: docs/api/my-asyncapi.yml
@@ -205,7 +210,7 @@ jobs:
205210
uses: actions/checkout@v2
206211
207212
- name: Validating AsyncAPI document
208-
uses: docker://asyncapi/github-action-for-cli:3.0.0
213+
uses: asyncapi/github-action-for-cli@v3.0.2 # You can use any version you want
209214
with:
210215
command: validate
211216
filepath: docs/api/my-asyncapi.yml

action.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ inputs:
3636

3737
runs:
3838
using: 'docker'
39-
image: 'Dockerfile'
39+
# This is the image that will be used to run the action.
40+
# IMPORTANT: The version has to be changed manually in your PRs.
41+
image: 'docker://asyncapi/github-action-for-cli:3.0.2'
4042
args:
4143
- ${{ inputs.cli_version }}
4244
- ${{ inputs.command }}

bump-test.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
version=$(cat package.json | jq -r '.version');
4+
action=$(cat action.yml);
5+
regex='docker:\/\/asyncapi\/github-action-for-cli:([0-9.]+)'
6+
7+
[[ $action =~ $regex ]]
8+
9+
action_version=${BASH_REMATCH[1]};
10+
11+
echo "Action version: $action_version";
12+
echo "Package version: $version";
13+
14+
if [[ $action_version > $version ]]; then
15+
echo "Action version is greater than package version";
16+
else \
17+
echo "Action version has not been bumped. Please bump the action version to the semantically correct version after $$version"; \
18+
exit 1; \
19+
fi

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "github-action-for-cli",
33
"description": "This is to be used for running tests for the GitHub Action using the MakeFile",
4-
"version": "3.0.0",
4+
"version": "3.0.1",
55
"scripts": {
66
"test": "make test",
77
"generate:assets": "echo 'No additional assets need to be generated at the moment'",

0 commit comments

Comments
 (0)