-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workflow for generating api.json file
[noissue]
- Loading branch information
Showing
5 changed files
with
184 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: "Generate REST-API data" | ||
|
||
on: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: "main-${{ github.ref_name }}-${{ github.workflow }}" | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
update-restapi-data: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# Setup pulp instance | ||
- uses: "actions/checkout@v4" | ||
with: | ||
fetch-depth: 0 | ||
path: "pulp-docs" | ||
|
||
- uses: "actions/checkout@v4" | ||
with: | ||
fetch-depth: 1 | ||
repository: "pulp/pulp-openapi-generator" | ||
path: "pulp-openapi-generator" | ||
|
||
- uses: "actions/setup-python@v4" | ||
with: | ||
python-version: "3.11" | ||
|
||
- name: "Setup and run Pulp instance" | ||
run: "pulp-docs/.github/workflows/scripts/setup-pulp.sh" | ||
|
||
# Generate api.json | ||
- name: "Generate api.json OpenApi schema" | ||
run: | | ||
echo "Generating OpenAPI schema" | ||
# Commit api.json | ||
- name: "Configure Git with pulpbot name and email" | ||
run: | | ||
git config --global user.name 'pulpbot' | ||
git config --global user.email '[email protected]' | ||
- name: commit-changes | ||
run: | | ||
echo "Commiting changes" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#!/usr/bin/env bash | ||
# coding=utf-8 | ||
|
||
set -mveuo pipefail | ||
|
||
# make sure this script runs at the repo root | ||
cd "$(dirname "$(realpath -e "$0")")"/../../.. | ||
|
||
source .github/workflows/scripts/utils.sh | ||
|
||
export POST_SCRIPT=$PWD/.github/workflows/scripts/post_script.sh | ||
export POST_DOCS_TEST=$PWD/.github/workflows/scripts/post_docs_test.sh | ||
export FUNC_TEST_SCRIPT=$PWD/.github/workflows/scripts/func_test_script.sh | ||
|
||
# Needed for both starting the service and building the docs. | ||
# Gets set in .github/settings.yml, but doesn't seem to inherited by | ||
# this script. | ||
export DJANGO_SETTINGS_MODULE=pulpcore.app.settings | ||
export PULP_SETTINGS=$PWD/.ci/ansible/settings/settings.py | ||
|
||
export PULP_URL="https://pulp" | ||
|
||
REPORTED_STATUS="$(pulp status)" | ||
|
||
echo "machine pulp | ||
login admin | ||
password password | ||
" | cmd_user_stdin_prefix bash -c "cat >> ~pulp/.netrc" | ||
# Some commands like ansible-galaxy specifically require 600 | ||
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. | ||
|
||
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[]| select(.component!="core")| select(.component!="file")| select(.component!="certguard")| 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 | ||
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[]|select(.component!="core")|select(.component!="file")|select(.component!="certguard")|(.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 | ||
fi | ||
popd | ||
|
||
# At this point, this is a safeguard only, so let's not make too much fuzz about the old status format. | ||
echo "$REPORTED_STATUS" | jq -r '.versions[]|select(.package)|(.package|sub("_"; "-")) + "-client==" + .version' > bindings_requirements.txt | ||
cmd_stdin_prefix bash -c "cat > /tmp/unittest_requirements.txt" < unittest_requirements.txt | ||
cmd_stdin_prefix bash -c "cat > /tmp/functest_requirements.txt" < functest_requirements.txt | ||
cmd_stdin_prefix bash -c "cat > /tmp/bindings_requirements.txt" < bindings_requirements.txt | ||
cmd_prefix pip3 install -r /tmp/unittest_requirements.txt -r /tmp/functest_requirements.txt -r /tmp/bindings_requirements.txt | ||
|
||
CERTIFI=$(cmd_prefix python3 -c 'import certifi; print(certifi.where())') | ||
cmd_prefix bash -c "cat /etc/pulp/certs/pulp_webserver.crt >> '$CERTIFI'" | ||
|
||
# check for any uncommitted migrations | ||
echo "Checking for uncommitted migrations..." | ||
cmd_user_prefix bash -c "django-admin makemigrations core --check --dry-run" | ||
cmd_user_prefix bash -c "django-admin makemigrations file --check --dry-run" | ||
cmd_user_prefix bash -c "django-admin makemigrations certguard --check --dry-run" | ||
|
||
if [ -f "$POST_SCRIPT" ]; then | ||
source "$POST_SCRIPT" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# This file is meant to be sourced by ci-scripts | ||
|
||
PULP_CI_CONTAINER=pulp | ||
|
||
# Run a command | ||
cmd_prefix() { | ||
docker exec "$PULP_CI_CONTAINER" "$@" | ||
} | ||
|
||
# Run a command as the limited pulp user | ||
cmd_user_prefix() { | ||
docker exec -u pulp "$PULP_CI_CONTAINER" "$@" | ||
} | ||
|
||
# Run a command, and pass STDIN | ||
cmd_stdin_prefix() { | ||
docker exec -i "$PULP_CI_CONTAINER" "$@" | ||
} | ||
|
||
# Run a command as the lmited pulp user, and pass STDIN | ||
cmd_user_stdin_prefix() { | ||
docker exec -i -u pulp "$PULP_CI_CONTAINER" "$@" | ||
} |
Empty file.