From e06c1c2c462c0e722249275aa888c57f2773bd56 Mon Sep 17 00:00:00 2001 From: David Crossley Date: Thu, 14 Dec 2023 15:28:45 +1100 Subject: [PATCH 1/2] Use API-related Workflows FOLIO-3678 --- .github/workflows/api-doc.yml | 91 +++++++++++++++++++++++++++ .github/workflows/api-lint.yml | 65 +++++++++++++++++++ .github/workflows/api-schema-lint.yml | 46 ++++++++++++++ 3 files changed, 202 insertions(+) create mode 100644 .github/workflows/api-doc.yml create mode 100644 .github/workflows/api-lint.yml create mode 100644 .github/workflows/api-schema-lint.yml diff --git a/.github/workflows/api-doc.yml b/.github/workflows/api-doc.yml new file mode 100644 index 0000000..9e07c5e --- /dev/null +++ b/.github/workflows/api-doc.yml @@ -0,0 +1,91 @@ +name: api-doc + +# https://dev.folio.org/guides/api-doc/ + +# API_TYPES: string: The space-separated list of types to consider. +# One or more of 'RAML OAS'. +# e.g. 'OAS' +# +# API_DIRECTORIES: string: The space-separated list of directories to search +# for API description files. +# e.g. 'src/main/resources/openapi' +# NOTE: -- Also add each separate path to each of the "on: paths:" sections. +# e.g. 'src/main/resources/openapi/**' +# +# API_EXCLUDES: string: The space-separated list of directories and files +# to exclude from traversal, in addition to the default exclusions. +# e.g. '' + +env: + API_TYPES: 'OAS' + API_DIRECTORIES: 'src/main/resources/swagger.api' + API_EXCLUDES: '' + OUTPUT_DIR: 'folio-api-docs' + AWS_S3_BUCKET: 'foliodocs' + AWS_S3_FOLDER: 'api' + AWS_S3_REGION: 'us-east-1' + AWS_S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} + AWS_S3_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} + +on: + push: + branches: [ main, master ] + paths: + - 'src/main/resources/swagger.api/**' + tags: '[vV][0-9]+.[0-9]+.[0-9]+*' + +jobs: + api-doc: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.REF }} + submodules: recursive + - name: Prepare folio-tools + run: | + git clone https://github.com/folio-org/folio-tools + cd folio-tools/api-doc \ + && yarn install \ + && pip3 install -r requirements.txt + - name: Obtain version if release tag + if: ${{ startsWith(github.ref, 'refs/tags/v') }} + run: | + version=$(echo ${GITHUB_REF#refs/tags/[vV]} | awk -F'.' '{ printf("%d.%d", $1, $2) }') + echo "VERSION_MAJ_MIN=${version}" >> $GITHUB_ENV + - name: Set some vars + run: | + echo "REPO_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV + - name: Report some info + run: | + echo "REPO_NAME=${{ env.REPO_NAME }}" + - name: Do api-doc + run: | + if test -n "${{ env.VERSION_MAJ_MIN }}"; then + echo "Docs for release version ${{ env.VERSION_MAJ_MIN }}" + option_release=$(echo "--version ${{ env.VERSION_MAJ_MIN }}") + else + option_release="" + fi + python3 folio-tools/api-doc/api_doc.py \ + --loglevel info \ + --types ${{ env.API_TYPES }} \ + --directories ${{ env.API_DIRECTORIES }} \ + --excludes ${{ env.API_EXCLUDES }} \ + --output ${{ env.OUTPUT_DIR }} $option_release + - name: Show generated files + working-directory: ${{ env.OUTPUT_DIR }} + run: ls -R + - name: Publish to AWS S3 + uses: sai-sharan/aws-s3-sync-action@v0.1.0 + with: + access_key: ${{ env.AWS_S3_ACCESS_KEY_ID }} + secret_access_key: ${{ env.AWS_S3_ACCESS_KEY }} + region: ${{ env.AWS_S3_REGION }} + source: ${{ env.OUTPUT_DIR }} + destination_bucket: ${{ env.AWS_S3_BUCKET }} + destination_prefix: ${{ env.AWS_S3_FOLDER }} + delete: false + quiet: false + diff --git a/.github/workflows/api-lint.yml b/.github/workflows/api-lint.yml new file mode 100644 index 0000000..22112e1 --- /dev/null +++ b/.github/workflows/api-lint.yml @@ -0,0 +1,65 @@ +name: api-lint + +# https://dev.folio.org/guides/api-lint/ + +# API_TYPES: string: The space-separated list of types to consider. +# One or more of 'RAML OAS'. +# e.g. 'OAS' +# +# API_DIRECTORIES: string: The space-separated list of directories to search +# for API description files. +# e.g. 'src/main/resources/openapi' +# NOTE: -- Also add each separate path to each of the "on: paths:" sections. +# e.g. 'src/main/resources/openapi/**' +# +# API_EXCLUDES: string: The space-separated list of directories and files +# to exclude from traversal, in addition to the default exclusions. +# e.g. '' +# +# API_WARNINGS: boolean: Whether to cause Warnings to be displayed, +# and to fail the workflow. +# e.g. false + +env: + API_TYPES: 'OAS' + API_DIRECTORIES: 'src/main/resources/swagger.api' + API_EXCLUDES: '' + API_WARNINGS: false + +on: + push: + paths: + - 'src/main/resources/swagger.api/**' + pull_request: + paths: + - 'src/main/resources/swagger.api/**' + +jobs: + api-lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + - name: Prepare folio-tools + run: | + git clone https://github.com/folio-org/folio-tools + cd folio-tools/api-lint \ + && yarn install \ + && pip3 install -r requirements.txt + - name: Configure default options + run: | + echo "OPTION_WARNINGS=''" >> $GITHUB_ENV + - name: Configure option warnings + if: ${{ env.API_WARNINGS == 'true' }} + run: | + echo "OPTION_WARNINGS=--warnings" >> $GITHUB_ENV + - name: Do api-lint + run: | + python3 folio-tools/api-lint/api_lint.py \ + --loglevel info \ + --types ${{ env.API_TYPES }} \ + --directories ${{ env.API_DIRECTORIES }} \ + --excludes ${{ env.API_EXCLUDES }} \ + ${{ env.OPTION_WARNINGS }} diff --git a/.github/workflows/api-schema-lint.yml b/.github/workflows/api-schema-lint.yml new file mode 100644 index 0000000..c921f15 --- /dev/null +++ b/.github/workflows/api-schema-lint.yml @@ -0,0 +1,46 @@ +name: api-schema-lint + +# https://dev.folio.org/guides/describe-schema/ + +# API_DIRECTORIES: string: The space-separated list of directories to search +# for JSON Schema files. +# e.g. 'src/main/resources/openapi' +# NOTE: -- Also add each separate path to each of the "on: paths:" sections. +# e.g. 'src/main/resources/openapi/**' +# +# API_EXCLUDES: string: The space-separated list of directories and files +# to exclude from traversal, in addition to the default exclusions. +# e.g. '' + +env: + API_DIRECTORIES: 'src/main/resources/swagger.api' + API_EXCLUDES: '' + +on: + push: + paths: + - 'src/main/resources/swagger.api/**' + pull_request: + paths: + - 'src/main/resources/swagger.api/**' + +jobs: + api-schema-lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + - name: Prepare folio-tools + run: | + git clone https://github.com/folio-org/folio-tools + cd folio-tools/api-schema-lint \ + && yarn install \ + && pip3 install -r requirements.txt + - name: Do api-schema-lint + run: | + python3 folio-tools/api-schema-lint/api_schema_lint.py \ + --loglevel info \ + --directories ${{ env.API_DIRECTORIES }} \ + --excludes ${{ env.API_EXCLUDES }} From e729fd8d856c58a84d713292073291cd86bbffc9 Mon Sep 17 00:00:00 2001 From: David Crossley Date: Thu, 14 Dec 2023 15:29:49 +1100 Subject: [PATCH 2/2] Verify Workflow api related change FOLIO-3678 --- src/main/resources/swagger.api/mgr-tenants.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/swagger.api/mgr-tenants.yaml b/src/main/resources/swagger.api/mgr-tenants.yaml index b494c06..79619fc 100644 --- a/src/main/resources/swagger.api/mgr-tenants.yaml +++ b/src/main/resources/swagger.api/mgr-tenants.yaml @@ -301,3 +301,4 @@ components: description: A CQL query string with search conditions. schema: type: string +