diff --git a/.github/workflows/openapi.yaml b/.github/workflows/openapi.yaml new file mode 100644 index 00000000..31407b03 --- /dev/null +++ b/.github/workflows/openapi.yaml @@ -0,0 +1,81 @@ +# workflow that receives updated api specifications from https://github.com/wordlift/docs, bumps version, build and publish to pypi +name: Generate OpenAPI Spec + +on: + workflow_dispatch: + push: + branches: + - openapi_gha + +jobs: + build: + name: Generate OpenAPI Spec + runs-on: ubuntu-latest + + steps: + # Step 1: Checkout the first repository + - name: Checkout repository + uses: actions/checkout@v4 + with: + token: ${{ secrets.WORKFLOW_TOKEN }} + fetch-depth: 2 + + # Step 2: Set up Node.js + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "20" # Specify the Node.js version to use + + # Step 3: Install openapi-merge-cli, openapi-down-convert and openapi-generator-cli + - name: Install openapi-merge-cli + run: | + npm i openapi-merge-cli ajv uri-js + npm i @apiture/openapi-down-convert@^0.14.2 + npm i @openapitools/openapi-generator-cli@~2.20.2 + + # Step 4: Set up Python + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.8" + + # Step 5: Install Python dependencies + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.pinned.txt + pip install build pyyaml + + # Step 6: Run the Python script to generate json for openApi-merge + - name: generate json for openApi-merge + run: python3 ./utils/json_merge_generator.py + + # Step 7: Promote global security to operation level in each spec + - name: Promote global security to operation level + run: python3 ./utils/promote_security.py + + # Step 7b: Rename duplicate schema names with spec-based prefixes + - name: Rename duplicate schemas + run: python3 ./utils/rename_duplicate_schemas.py + + # Step 8: Merge the YAML files + - name: Merge the yaml files + run: npx openapi-merge-cli --config ./openapi-merge.json + + # Step 8b: Down-convert any OAS 3.1-only constructs (openapi-merge always declares + # 3.0.3 regardless of input, so source specs written for 3.1 need this to stay valid) + - name: Down-convert OpenAPI 3.1 constructs to 3.0 + run: npx openapi-down-convert --input ./wordliftApiSpec.yaml --output ./wordliftApiSpec.yaml + + # Step 9: Normalize security scheme aliases in the merged spec + - name: Normalize security scheme aliases + run: python3 ./utils/normalize_security_schemes.py + + - name: Rename spec for upload + run: cp ./wordliftApiSpec.yaml ./openapi.yaml + + - name: Upload merged spec as artifact + uses: actions/upload-artifact@v4 + with: + name: openapi.yaml + path: ./openapi.yaml