Skip to content

Commit

Permalink
WIP: Account for multi-plugin repositories
Browse files Browse the repository at this point in the history
This adds a `plugin` list to the template config. For "usual" plugins
it's populated automatically.

[noissue]
  • Loading branch information
mdellweg committed Nov 21, 2023
1 parent 664ee4a commit ef7ce5b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 53 deletions.
6 changes: 6 additions & 0 deletions plugin-template
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ DEFAULT_SETTINGS = {
"plugin_app_label": None,
"plugin_default_branch": "main",
"plugin_name": None,
"plugins": None,
"post_job_template": None,
"pre_job_template": None,
"publish_docs_to_pulpprojectdotorg": False,
Expand Down Expand Up @@ -249,6 +250,10 @@ def main():
for key in set(config.keys()) - set(DEFAULT_SETTINGS.keys()):
config.pop(key)
write_new_config = True
if config["plugins"] is None:
config["plugins"] = [
{"name": config["plugin_name"], "app_label": config["plugin_app_label"]}
]
print(
"\nLoaded plugin template config from "
"{path}/template_config.yml.\n".format(path=plugin_root_dir)
Expand Down Expand Up @@ -470,6 +475,7 @@ def generate_config(plugin_name, plugin_app_label):
config = DEFAULT_SETTINGS.copy()
config["plugin_name"] = plugin_name
config["plugin_app_label"] = plugin_app_label
config["plugins"] = [{"name": plugin_name, "app_label": plugin_app_label}]
return config


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,34 @@

set -mveuo pipefail

export PULP_URL="${PULP_URL:-{{ pulp_scheme }}://pulp}"

# make sure this script runs at the repo root
cd "$(dirname "$(realpath -e "$0")")"/../../..

source .github/workflows/scripts/utils.sh

export PULP_URL="${PULP_URL:-{{ pulp_scheme }}://pulp}"

pip install twine wheel

REPORTED_STATUS="$(pulp status)"
REPORTED_VERSION="$(echo "$REPORTED_STATUS" | jq --arg plugin "{{ plugin_app_label }}" -r '.versions[] | select(.component == $plugin) | .version')"
VERSION="$(echo "$REPORTED_VERSION" | python -c 'from packaging.version import Version; print(Version(input()))')"

RESPONSE="$(curl --write-out '%{http_code}' --silent --output /dev/null "https://pypi.org/project/{{ plugin_name | dash }}-client/$VERSION/")"

if [ "$RESPONSE" == "200" ];
then
# TODO This is probably not needed.
echo "{{ plugin_name }} client $VERSION has already been released. Installing from PyPI."
cms_prefix pip3 install "{{ plugin_name | dash }}-client==$VERSION"
mkdir -p dist
tar cvf python-client.tar ./dist
exit
fi

cd ../pulp-openapi-generator
rm -rf {{ plugin_name | snake }}-client
./generate.sh {{ plugin_name | snake }} python "$VERSION"
cd {{ plugin_name | snake }}-client
pushd ../pulp-openapi-generator
{%- for plugin in plugins %}
rm -rf {{ plugin.name | snake }}-client
./generate.sh {{ plugin.name | snake }} python "$VERSION"
pushd {{ plugin.name | snake }}-client
python setup.py sdist bdist_wheel --python-tag py3
cmd_prefix pip3 install "/root/pulp-openapi-generator/{{ plugin_name | snake }}-client/dist/{{ plugin_name | snake }}_client-${VERSION}-py3-none-any.whl"
tar cvf ../../{{ plugin_name }}/python-client.tar ./dist
cmd_prefix pip3 install "/root/pulp-openapi-generator/{{ plugin.name | snake }}-client/dist/{{ plugin.name | snake }}_client-${VERSION}-py3-none-any.whl"
tar cvf ../../{{ plugin_name }}/{{ plugin.app_label }}-python-client.tar ./dist

find ./docs/* -exec sed -i 's/Back to README/Back to HOME/g' {} \;
find ./docs/* -exec sed -i 's/README//g' {} \;
cp README.md docs/index.md
sed -i 's/docs\///g' docs/index.md
find ./docs/* -exec sed -i 's/\.md//g' {} \;
tar cvf ../../{{ plugin_name }}/python-client-docs.tar ./docs
exit $?
tar cvf ../../{{ plugin_name }}/{{ plugin.app_label }}-python-client-docs.tar ./docs
popd
{%- endfor %}
popd
47 changes: 19 additions & 28 deletions templates/github/.github/workflows/scripts/install_ruby_client.sh.j2
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,28 @@

{% include 'header.j2' %}

set -euv
set -mveuo pipefail

# make sure this script runs at the repo root
cd "$(dirname "$(realpath -e "$0")")"/../../..

source .github/workflows/scripts/utils.sh

export PULP_URL="${PULP_URL:-{{ pulp_scheme }}://pulp}"

export REPORTED_VERSION=$(http $PULP_URL/pulp/api/v3/status/ | jq --arg plugin {{ plugin_app_label }} --arg legacy_plugin {{ plugin_name | snake }} -r '.versions[] | select(.component == $plugin or .component == $legacy_plugin) | .version')
export DESCRIPTION="$(git describe --all --exact-match `git rev-parse HEAD`)"
if [[ $DESCRIPTION == 'tags/'$REPORTED_VERSION ]]; then
export VERSION=${REPORTED_VERSION}
else
export EPOCH="$(date +%s)"
export VERSION=${REPORTED_VERSION}${EPOCH}
fi

export response=$(curl --write-out %{http_code} --silent --output /dev/null https://rubygems.org/gems/{{ plugin_name | snake }}_client/versions/$VERSION)

if [ "$response" == "200" ];
then
echo "{{ plugin_name }} client $VERSION has already been released. Installing from RubyGems.org."
gem install {{ plugin_name | snake }}_client -v $VERSION
touch {{ plugin_name | snake }}_client-$VERSION.gem
tar cvf ruby-client.tar ./{{ plugin_name | snake }}_client-$VERSION.gem
exit
fi

cd ../pulp-openapi-generator
rm -rf {{ plugin_name | snake }}-client
./generate.sh {{ plugin_name | snake }} ruby $VERSION
cd {{ plugin_name | snake }}-client
gem build {{ plugin_name | snake }}_client
gem install --both ./{{ plugin_name | snake }}_client-$VERSION.gem
tar cvf ../../{{ plugin_name }}/ruby-client.tar ./{{ plugin_name | snake }}_client-$VERSION.gem

REPORTED_STATUS="$(pulp status)"
REPORTED_VERSION="$(echo "$REPORTED_STATUS" | jq --arg plugin "{{ plugin_app_label }}" -r '.versions[] | select(.component == $plugin) | .version')"
VERSION="$(echo "$REPORTED_VERSION" | python -c 'from packaging.version import Version; print(Version(input()))')"

pushd ../pulp-openapi-generator
{%- for plugin in plugins %}
rm -rf {{ plugin.name | snake }}-client
./generate.sh {{ plugin.name | snake }} ruby "$VERSION"
pushd {{ plugin.name | snake }}-client
gem build {{ plugin.name | snake }}_client
gem install --both "./{{ plugin.name | snake }}_client-$VERSION.gem"
tar cvf ../../{{ plugin_name }}/{{ plugin.app_label }}-ruby-client.tar "./{{ plugin.name | snake }}_client-$VERSION.gem"
popd
{%- endfor %}
popd
14 changes: 11 additions & 3 deletions templates/github/.github/workflows/test.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,36 @@ jobs:
id: deprecations
run: echo deprecations-{{ "${{ matrix.env.TEST }}" }}=$(docker logs pulp 2>&1 | grep -i pulpcore.deprecation | base64 -w 0) >> $GITHUB_OUTPUT

{%- for plugin in plugins %}
- name: Upload python client packages
if: {{ "${{ env.TEST == 'pulp' }}" }}
uses: actions/upload-artifact@v3
with:
name: "python-client.tar"
path: "{{ plugin_name }}/python-client.tar"
path: "{{ plugin_name }}/{{ plugin.app_label }}-python-client.tar"
if-no-files-found: "error"
retention-days: 5

- name: Upload python client docs
if: {{ "${{ env.TEST == 'pulp' }}" }}
uses: actions/upload-artifact@v3
with:
name: "python-client-docs.tar"
path: "{{ plugin_name }}/python-client-docs.tar"
path: "{{ plugin_name }}/{{ plugin.app_label }}-python-client-docs.tar"
if-no-files-found: "error"
retention-days: 5

{%- if deploy_client_to_rubygems %}
- name: Upload Ruby client
if: {{ "${{ env.TEST == 'pulp' }}" }}
uses: actions/upload-artifact@v3
with:
name: "ruby-client.tar"
path: "{{ plugin_name }}/ruby-client.tar"
path: "{{ plugin_name }}/{{ plugin.app_label }}-ruby-client.tar"
if-no-files-found: "error"
retention-days: 5
{%- endif %}
{%- endfor %}

{%- if docs_test %}
- name: Upload built docs
Expand Down

0 comments on commit ef7ce5b

Please sign in to comment.