diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml index bf72fbc2b..fbd19aa79 100644 --- a/.github/workflows/test-action.yml +++ b/.github/workflows/test-action.yml @@ -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: ./ @@ -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: ./ @@ -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: ./ @@ -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: ./ @@ -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 @@ -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 @@ -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: ./ @@ -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 @@ -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: ./ diff --git a/.gitignore b/.gitignore index daaf8510a..e61b8a6c5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ coverage .DS_Store output node_modules -dist \ No newline at end of file +dist +test/unoptimized_optimized.yml \ No newline at end of file diff --git a/Makefile b/Makefile index 2952cc53a..ad852f13b 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/README.md b/README.md index 7e47730e8..aad0bbcd1 100644 --- a/README.md +++ b/README.md @@ -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 ``` @@ -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 ` 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 @@ -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 @@ -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/html-template@0.9.0' #In case of template from npm, because of @ it must be in quotes filepath: docs/api/my-asyncapi.yml @@ -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 @@ -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 diff --git a/action.yml b/action.yml index c95a4e584..3c1f8ef94 100644 --- a/action.yml +++ b/action.yml @@ -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 }} diff --git a/bump-test.sh b/bump-test.sh new file mode 100755 index 000000000..a36f5a541 --- /dev/null +++ b/bump-test.sh @@ -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 \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 23ff997ff..9c625b276 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "github-action-for-cli", - "version": "3.0.0", + "version": "3.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "github-action-for-cli", - "version": "3.0.0", + "version": "3.0.1", "license": "Apache-2.0" } } diff --git a/package.json b/package.json index 0645b35e9..e67cbe082 100644 --- a/package.json +++ b/package.json @@ -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'",