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

feat: add docker support to action directly #375

Merged
merged 15 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
130 changes: 121 additions & 9 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,51 @@ jobs:
outputs:
shouldrun: ${{ steps.should_run.outputs.shouldrun }}

build-docker:
needs: should-workflow-run
name: Build Docker image
if: ${{ needs.should-workflow-run.outputs.shouldrun == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get docker version
id: docker_version
run: >
ls -la;
action=$(cat action.yml);
regex='docker:\/\/asyncapi\/github-action-for-cli:([0-9.]+)';
[[ $action =~ $regex ]];
action_version=${BASH_REMATCH[1]};
echo "action_version=$action_version" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image and export
uses: docker/build-push-action@v5
with:
context: .
tags: asyncapi/github-action-for-cli:${{ steps.docker_version.outputs.action_version }}
outputs: type=docker,dest=/tmp/asyncapi.tar
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: asyncapi
path: /tmp/asyncapi.tar


test-defaults:
if: ${{ needs.should-workflow-run.outputs.shouldrun == 'true' }}
runs-on: ubuntu-latest
needs: should-workflow-run
needs: [should-workflow-run, build-docker]
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: asyncapi
path: /tmp
- name: Load Docker image
run: |
docker load --input /tmp/asyncapi.tar
docker image ls -a
- uses: actions/checkout@v4
- name: Test GitHub Action
uses: ./
Expand All @@ -54,8 +94,17 @@ jobs:
test-validate-success:
if: ${{ needs.should-workflow-run.outputs.shouldrun == 'true' }}
runs-on: ubuntu-latest
needs: should-workflow-run
needs: [should-workflow-run, build-docker]
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: asyncapi
path: /tmp
- name: Load Docker image
run: |
docker load --input /tmp/asyncapi.tar
docker image ls -a
- uses: actions/checkout@v4
- name: Test GitHub Action
uses: ./
Expand All @@ -66,8 +115,17 @@ jobs:
test-custom-command:
if: ${{ needs.should-workflow-run.outputs.shouldrun == 'true' }}
runs-on: ubuntu-latest
needs: should-workflow-run
needs: [should-workflow-run, build-docker]
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: asyncapi
path: /tmp
- name: Load Docker image
run: |
docker load --input /tmp/asyncapi.tar
docker image ls -a
- uses: actions/checkout@v4
- name: Test GitHub Action
uses: ./
Expand All @@ -91,8 +149,17 @@ jobs:
test-custom-output:
if: ${{ needs.should-workflow-run.outputs.shouldrun == 'true' }}
runs-on: ubuntu-latest
needs: should-workflow-run
needs: [should-workflow-run, build-docker]
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: asyncapi
path: /tmp
- name: Load Docker image
run: |
docker load --input /tmp/asyncapi.tar
docker image ls -a
- uses: actions/checkout@v4
- name: Test GitHub Action
uses: ./
Expand All @@ -115,8 +182,17 @@ jobs:
test-file-not-found:
if: ${{ needs.should-workflow-run.outputs.shouldrun == 'true' }}
runs-on: ubuntu-latest
needs: should-workflow-run
needs: [should-workflow-run, build-docker]
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: asyncapi
path: /tmp
- name: Load Docker image
run: |
docker load --input /tmp/asyncapi.tar
docker image ls -a
- uses: actions/checkout@v4
- name: Test GitHub Action
id: test
Expand All @@ -136,8 +212,17 @@ jobs:
test-invalid-input:
if: ${{ needs.should-workflow-run.outputs.shouldrun == 'true' }}
runs-on: ubuntu-latest
needs: should-workflow-run
needs: [should-workflow-run, build-docker]
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: asyncapi
path: /tmp
- name: Load Docker image
run: |
docker load --input /tmp/asyncapi.tar
docker image ls -a
- uses: actions/checkout@v4
- name: Test GitHub Action
id: test
Expand All @@ -159,8 +244,17 @@ jobs:
test-optimize:
if: ${{ needs.should-workflow-run.outputs.shouldrun == 'true' }}
runs-on: ubuntu-latest
needs: should-workflow-run
needs: [should-workflow-run, build-docker]
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: asyncapi
path: /tmp
- name: Load Docker image
run: |
docker load --input /tmp/asyncapi.tar
docker image ls -a
- uses: actions/checkout@v4
- name: Test GitHub Action
uses: ./
Expand All @@ -184,8 +278,17 @@ jobs:
test-bundle:
if: ${{ needs.should-workflow-run.outputs.shouldrun == 'true' }}
runs-on: ubuntu-latest
needs: should-workflow-run
needs: [should-workflow-run, build-docker]
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: asyncapi
path: /tmp
- name: Load Docker image
run: |
docker load --input /tmp/asyncapi.tar
docker image ls -a
- uses: actions/checkout@v4
- name: Make output directory
run: mkdir -p ./output/bundle
Expand All @@ -209,8 +312,17 @@ jobs:
test-convert:
if: ${{ needs.should-workflow-run.outputs.shouldrun == 'true' }}
runs-on: ubuntu-latest
needs: should-workflow-run
needs: [should-workflow-run, build-docker]
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: asyncapi
path: /tmp
- name: Load Docker image
run: |
docker load --input /tmp/asyncapi.tar
docker image ls -a
- uses: actions/checkout@v4
- name: Test GitHub Action
uses: ./
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ coverage
.DS_Store
output
node_modules
dist
dist
test/unoptimized_optimized.yml
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ 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-validate-fail test-custom-output test-custom-commands test-optimize test-bundle test-convert
test: test-default test-validate-success test-validate-fail 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)
Expand Down
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Sample usage:

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


## Example usage

> [!WARNING]
> 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.
> 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.

### 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-cli:3.0.0
uses: asyncapi/github-action-for-cli@v3.0.2 # You can use any version you want
```

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

```yaml
- name: Generating HTML from my AsyncAPI document
uses: docker://asyncapi/github-action-for-cli:3.0.0
uses: asyncapi/github-action-for-cli@v3.0.2 # You can use any version you want
with:
command: generate
filepath: ./docs/api/asyncapi.yaml
Expand Down Expand Up @@ -140,7 +145,7 @@ jobs:

#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-cli:3.0.0
uses: asyncapi/github-action-for-cli@v3.0.2 # You can use any version you want
with:
template: '@asyncapi/[email protected]' #In case of template from npm, because of @ it must be in quotes
filepath: docs/api/my-asyncapi.yml
Expand Down Expand Up @@ -177,7 +182,7 @@ jobs:
uses: actions/checkout@v2

- name: Generating models from my AsyncAPI document
uses: docker://asyncapi/github-action-for-cli:3.0.0
uses: asyncapi/github-action-for-cli@v3.0.2 # You can use any version you want
with:
command: generate
filepath: docs/api/my-asyncapi.yml
Expand Down Expand Up @@ -205,7 +210,7 @@ jobs:
uses: actions/checkout@v2

- name: Validating AsyncAPI document
uses: docker://asyncapi/github-action-for-cli:3.0.0
uses: asyncapi/github-action-for-cli@v3.0.2 # You can use any version you want
with:
command: validate
filepath: docs/api/my-asyncapi.yml
Expand Down
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ inputs:

runs:
using: 'docker'
image: 'Dockerfile'
# 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.0.2'
args:
- ${{ inputs.cli_version }}
- ${{ inputs.command }}
Expand Down
19 changes: 19 additions & 0 deletions bump-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

version=$(cat package.json | jq -r '.version');
action=$(cat action.yml);
regex='docker:\/\/asyncapi\/github-action-for-cli:([0-9.]+)'

[[ $action =~ $regex ]]

action_version=${BASH_REMATCH[1]};

echo "Action version: $action_version";
echo "Package version: $version";

if [[ $action_version > $version ]]; then
echo "Action version is greater than package version";
else \
echo "Action version has not been bumped. Please bump the action version to the semantically correct version after $$version"; \
exit 1; \
fi
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "github-action-for-cli",
"description": "This is to be used for running tests for the GitHub Action using the MakeFile",
"version": "3.0.0",
"version": "3.0.1",
"scripts": {
"test": "make test",
"generate:assets": "echo 'No additional assets need to be generated at the moment'",
Expand Down
Loading