diff --git a/hacks-and-check/action.yaml b/hacks-and-check/action.yaml new file mode 100644 index 0000000..9d0f6b8 --- /dev/null +++ b/hacks-and-check/action.yaml @@ -0,0 +1,55 @@ +name: Hack and check +description: patche OpenAPI specification and check for breaking changes + +inputs: + no-date-time: + description: Strip date-time fields + default: "no" + no-date: + description: Strip date fields + default: "no" + no-oneof: + description: Strip oneOf fields + default: "no" + no-properties-array: + description: inflate array's items definition + default: "no" + patch: + description: path to the OpenAPI specification patch + default: "" + input: + description: path to the input OpenAPI specification file + required: true + output: + description: path to the output OpenAPI specification file + required: true + +runs: + using: composite + steps: + - name: Create temporary file + shell: bash + id: temporary + run: echo "temp-file=$(mktemp -p $(pwd) $(basename ${{ inputs.output }}.XXXXXX))" >> $GITHUB_OUTPUT + + - name: Patch OpenAPI specification + uses: outscale/osc-api-deploy/hacks@main + with: + no-date-time: ${{ inputs.no-date-time }} + no-date: ${{ inputs.no-date }} + no-oneof: ${{ inputs.no-oneof }} + no-properties-array: ${{ inputs.no-properties-array }} + patch: ${{ inputs.patch }} + input: ${{ inputs.input }} + output: ${{ outputs.temporary.temp-file }} + + - name: Checking breaking changes + uses: oasdiff/oasdiff-action/breaking@main + with: + base: ${{ inputs.output }} + revision: ${{ outputs.temporary.temp-file }} + fail-on: ERR + + - name: Move temporary file + shell: bash + run: mv ${{ outputs.temporary.temp-file }} ${{ inputs.output }} diff --git a/hacks/Dockerfile b/hacks/Dockerfile index f769907..e6dd127 100644 --- a/hacks/Dockerfile +++ b/hacks/Dockerfile @@ -4,4 +4,4 @@ WORKDIR /usr/src/app COPY . . -CMD [ "./patch.rb" ] +ENTRYPOINT [ "/usr/src/app/entrypoint.sh" ] diff --git a/hacks/action.yml b/hacks/action.yml new file mode 100644 index 0000000..dd297f5 --- /dev/null +++ b/hacks/action.yml @@ -0,0 +1,37 @@ +name: Hack +description: Toolbox for patching OpenAPI specification file + +inputs: + no-date-time: + description: Strip date-time fields + default: "no" + no-date: + description: Strip date fields + default: "no" + no-oneof: + description: Strip oneOf fields + default: "no" + no-properties-array: + description: inflate array's items definition + default: "no" + patch: + description: path to the OpenAPI specification patch + default: "" + input: + description: path to the input OpenAPI specification file + required: true + output: + description: path to the output OpenAPI specification file + required: true + +runs: + using: docker + image: Dockerfile + args: + - ${{ inputs.no-date-time }} + - ${{ inputs.no-date }} + - ${{ inputs.no-oneof }} + - ${{ inputs.no-properties-array }} + - ${{ inputs.patch }} + - ${{ inputs.input }} + - ${{ inputs.output }} diff --git a/hacks/entrypoint.sh b/hacks/entrypoint.sh new file mode 100755 index 0000000..1181244 --- /dev/null +++ b/hacks/entrypoint.sh @@ -0,0 +1,26 @@ +#!/bin/env bash + +set -euxo pipefail + +ARGS="--input ${6}" +if [ "${1}" = "yes" ]; then + ARGS="--nodatetime $ARGS" +fi + +if [ "${2}" = "yes" ]; then + ARGS="--nodate $ARGS" +fi + +if [ "${3}" = "yes" ]; then + ARGS="--nooneof $ARGS" +fi + +if [ "${4}" = "yes" ]; then + ARGS="--noproperties-array $ARGS" +fi + +if [ ! "${5}patch" = "patch" ]; then + ARGS="--patch ${5} $ARGS" +fi + +exec /usr/src/app/patch.rb $ARGS > "${7}"