Skip to content

Commit

Permalink
fixup! Use openapi command to generate api.json
Browse files Browse the repository at this point in the history
  • Loading branch information
mdellweg committed Jun 20, 2024
1 parent ea3c8d7 commit 600c082
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 75 deletions.
24 changes: 17 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# WARNING: DO NOT EDIT!
#
# This file was generated by plugin_template, and is managed by it. Please use
# './plugin-template --github pulp_catdog' to update this file.
#
# For more info visit https://github.com/pulp/plugin_template

---
name: "Build"
on:
Expand Down Expand Up @@ -43,6 +36,13 @@ jobs:
run: |
python3 setup.py sdist bdist_wheel --python-tag py3
twine check dist/*
- name: "Install built packages"
run: |
pip install dist/pulp_catdog-*-py3-none-any.whl
- name: "Generate api specs"
run: |
pulpcore-manager openapi --file "api.json"
pulpcore-manager openapi --bindings --component "catdog" --file "catdog-api.json"
- name: "Upload Package whl"
uses: "actions/upload-artifact@v4"
with:
Expand All @@ -51,3 +51,13 @@ jobs:
if-no-files-found: "error"
retention-days: 5
overwrite: true
- name: "Upload API specs"
uses: "actions/upload-artifact@v4"
with:
name: "api_spec"
path: |
pulp_catdog/api.json
pulp_catdog/catdog-api.json
if-no-files-found: "error"
retention-days: 5
overwrite: true
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:
steps:
- uses: "actions/checkout@v4"
with:
path: "plugin_template"
fetch-depth: 0
path: "plugin_template"
- uses: "actions/setup-python@v5"
with:
python-version: "3.11"
Expand Down
8 changes: 5 additions & 3 deletions templates/github/.github/workflows/build.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ jobs:
pip install dist/{{ plugin_name }}-*-py3-none-any.whl
- name: "Generate api specs"
run: |
pulpcore-manager openapi --file "api.json"
{%- for plugin in plugins %}
python3 pulpcore-manager openapi --bindings --component "{{ plugin.name }}" --file "{{ plugin.name }}-api.json }}"
pulpcore-manager openapi --bindings --component "{{ plugin.app_label }}" --file "{{ plugin.app_label }}-api.json"
{%- endfor %}
- name: "Upload Package whl"
uses: "actions/upload-artifact@v4"
Expand All @@ -45,9 +46,10 @@ jobs:
uses: "actions/upload-artifact@v4"
with:
name: "api_spec"
path:
path: |
{{ plugin_name }}/api.json
{%- for plugin in plugins %}
- "{{ plugin.name }}-api.json"
{{ plugin_name }}/{{ plugin.app_label }}-api.json
{%- endfor %}
if-no-files-found: "error"
retention-days: 5
Expand Down
98 changes: 34 additions & 64 deletions templates/github/.github/workflows/scripts/script.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -55,72 +55,42 @@ cmd_prefix bash -c "chmod 600 ~pulp/.netrc"

# Generate and install binding
pushd ../pulp-openapi-generator
if pulp debug has-plugin --name "core" --specifier ">=3.44.0.dev"
then
# Use app_label to generate api.json and package to produce the proper package name.
# Use app_label to generate api.json and package to produce the proper package name.

if [ "$(jq -r '.domain_enabled' <<<"$REPORTED_STATUS")" = "true" ]
then
# Workaround: Domains are not supported by the published bindings.
# Generate new bindings for all packages.
for item in $(jq -r '.versions[] | tojson' <<<"$REPORTED_STATUS")
do
echo $item
COMPONENT="$(jq -r '.component' <<<"$item")"
VERSION="$(jq -r '.version' <<<"$item")"
MODULE="$(jq -r '.module' <<<"$item")"
PACKAGE="${MODULE%%.*}"
curl --fail-with-body -k -o api.json "${PULP_URL}${PULP_API_ROOT}api/v3/docs/api.json?bindings&component=$COMPONENT"
USE_LOCAL_API_JSON=1 ./generate.sh "${PACKAGE}" python "${VERSION}"
cmd_prefix pip3 install "/root/pulp-openapi-generator/${PACKAGE}-client"
sudo rm -rf "./${PACKAGE}-client"
done
else
# Sadly: Different pulpcore-versions aren't either...
for item in $(jq -r '.versions[]
{%- for plugin in plugins -%}
| select(.component!="{{ plugin.app_label }}")
{%- endfor -%}
| tojson' <<<"$REPORTED_STATUS")
do
echo $item
COMPONENT="$(jq -r '.component' <<<"$item")"
VERSION="$(jq -r '.version' <<<"$item")"
MODULE="$(jq -r '.module' <<<"$item")"
PACKAGE="${MODULE%%.*}"
curl --fail-with-body -k -o api.json "${PULP_URL}${PULP_API_ROOT}api/v3/docs/api.json?bindings&component=$COMPONENT"
USE_LOCAL_API_JSON=1 ./generate.sh "${PACKAGE}" python "${VERSION}"
cmd_prefix pip3 install "/root/pulp-openapi-generator/${PACKAGE}-client"
sudo rm -rf "./${PACKAGE}-client"
done
fi
if [ "$(jq -r '.domain_enabled' <<<"$REPORTED_STATUS")" = "true" ]
then
# Workaround: Domains are not supported by the published bindings.
# Generate new bindings for all packages.
for item in $(jq -r '.versions[] | tojson' <<<"$REPORTED_STATUS")
do
echo $item
COMPONENT="$(jq -r '.component' <<<"$item")"
VERSION="$(jq -r '.version' <<<"$item")"
MODULE="$(jq -r '.module' <<<"$item")"
PACKAGE="${MODULE%%.*}"
cmd_prefix pulpcore-manager openapi --bindings --component "${COMPONENT}" > api.json
./gen-client.sh api.json "${COMPONENT}" python "${PACKAGE}"
cmd_prefix pip3 install "/root/pulp-openapi-generator/${PACKAGE}-client"
sudo rm -rf "./${PACKAGE}-client"
done
else
# Infer the client name from the package name by replacing "-" with "_".
# Use the component to infer the package name on older versions of pulpcore.

if [ "$(echo "$REPORTED_STATUS" | jq -r '.domain_enabled')" = "true" ]
then
# Workaround: Domains are not supported by the published bindings.
# Generate new bindings for all packages.
for item in $(echo "$REPORTED_STATUS" | jq -r '.versions[]|(.package // ("pulp_" + .component)|sub("pulp_core"; "pulpcore"))|sub("-"; "_")')
do
./generate.sh "${item}" python
cmd_prefix pip3 install "/root/pulp-openapi-generator/${item}-client"
sudo rm -rf "./${item}-client"
done
else
# Sadly: Different pulpcore-versions aren't either...
for item in $(echo "$REPORTED_STATUS" | jq -r '.versions[]
{%- for plugin in plugins -%}
|select(.component!="{{ plugin.app_label }}")
{%- endfor -%}
|(.package // ("pulp_" + .component)|sub("pulp_core"; "pulpcore"))|sub("-"; "_")')
do
./generate.sh "${item}" python
cmd_prefix pip3 install "/root/pulp-openapi-generator/${item}-client"
sudo rm -rf "./${item}-client"
done
fi
# Sadly: Different pulpcore-versions aren't either...
for item in $(jq -r '.versions[]
{%- for plugin in plugins -%}
| select(.component!="{{ plugin.app_label }}")
{%- endfor -%}
| tojson' <<<"$REPORTED_STATUS")
do
echo $item
COMPONENT="$(jq -r '.component' <<<"$item")"
VERSION="$(jq -r '.version' <<<"$item")"
MODULE="$(jq -r '.module' <<<"$item")"
PACKAGE="${MODULE%%.*}"
cmd_prefix pulpcore-manager openapi --bindings --component "${COMPONENT}" > api.json
./gen-client.sh api.json "${COMPONENT}" python "${PACKAGE}"
cmd_prefix pip3 install "/root/pulp-openapi-generator/${PACKAGE}-client"
sudo rm -rf "./${PACKAGE}-client"
done
fi
popd

Expand Down

0 comments on commit 600c082

Please sign in to comment.