From 3271e88d996b73ea4d4ecfe9504c4a3aa5244849 Mon Sep 17 00:00:00 2001 From: David Davis Date: Fri, 23 Jul 2021 15:07:08 -0400 Subject: [PATCH] Allow plugins to configure python_version fixes #457 --- CHANGES/457.feature | 1 + README.md | 2 ++ plugin-template | 1 + templates/github/.ci/ansible/Containerfile.j2.copy | 3 ++- templates/github/.github/workflows/ci.yml.j2 | 6 +++--- templates/github/.github/workflows/nightly.yml.j2 | 6 +++--- templates/github/.github/workflows/release.yml.j2 | 6 +++--- .../.github/workflows/scripts/before_install.sh.j2 | 11 +++++++++-- .../github/.github/workflows/scripts/script.sh.j2 | 2 +- 9 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 CHANGES/457.feature diff --git a/CHANGES/457.feature b/CHANGES/457.feature new file mode 100644 index 00000000..fb56cbb6 --- /dev/null +++ b/CHANGES/457.feature @@ -0,0 +1 @@ +Added python_version option. diff --git a/README.md b/README.md index 3462dea0..bba84f20 100644 --- a/README.md +++ b/README.md @@ -189,6 +189,8 @@ The following settings are stored in `template_config.yml`. is required unless deploy_client_to_pypi and deploy_daily_client_to_pypi and deploy_to_pypi are specified. + python_version Python version to use in the CI. Currently only 3.6 and 3.8 are supported. + redmine_project A string that corresponds to the redmine identifier for the repo's project. This is used during commit validation to make sure the commit is attached to an issue in the correct project. diff --git a/plugin-template b/plugin-template index 9de1ba2d..900ac2ec 100755 --- a/plugin-template +++ b/plugin-template @@ -53,6 +53,7 @@ DEFAULT_SETTINGS = { 'pulpprojectdotorg_key_id': None, 'pydocstyle': True, 'pypi_username': None, + 'python_version': "3.8", 'redmine_project': None, 'release_user': 'pulpbot', 'sync_ci': True, diff --git a/templates/github/.ci/ansible/Containerfile.j2.copy b/templates/github/.ci/ansible/Containerfile.j2.copy index aa0f608b..eeccb850 100644 --- a/templates/github/.ci/ansible/Containerfile.j2.copy +++ b/templates/github/.ci/ansible/Containerfile.j2.copy @@ -23,7 +23,8 @@ RUN pip3 install \ RUN mkdir -p /etc/nginx/pulp/ {% for item in plugins %} -RUN ln /usr/local/lib/python3.8/site-packages/{{ item.name }}/app/webserver_snippets/nginx.conf /etc/nginx/pulp/{{ item.name }}.conf || true +RUN export {{ item.name }}_PATH="$(pip show {{ item.name }} | sed -n -e "s/Location: //p")/{{ item.name }}" +RUN ln ${{ item.name }}_PATH/app/webserver_snippets/nginx.conf /etc/nginx/pulp/{{ item.name }}.conf || true {% endfor %} ENTRYPOINT ["/init"] diff --git a/templates/github/.github/workflows/ci.yml.j2 b/templates/github/.github/workflows/ci.yml.j2 index 384566a2..8b251c4f 100644 --- a/templates/github/.github/workflows/ci.yml.j2 +++ b/templates/github/.github/workflows/ci.yml.j2 @@ -20,7 +20,7 @@ jobs: - uses: actions/setup-python@v2 with: - python-version: "3.8" + python-version: "{{ python_version }}" # dev_requirements contains tools needed for flake8, etc. - name: Install requirements @@ -92,7 +92,7 @@ jobs: - uses: actions/setup-python@v2 with: - python-version: "3.8" + python-version: "{{ python_version }}" {%- if test_bindings %} - uses: actions/setup-ruby@v1 @@ -185,7 +185,7 @@ jobs: - uses: actions/setup-python@v2 with: - python-version: "3.8" + python-version: "{{ python_version }}" - name: Install httpie run: | diff --git a/templates/github/.github/workflows/nightly.yml.j2 b/templates/github/.github/workflows/nightly.yml.j2 index 339f617e..629c5729 100644 --- a/templates/github/.github/workflows/nightly.yml.j2 +++ b/templates/github/.github/workflows/nightly.yml.j2 @@ -40,7 +40,7 @@ jobs: - uses: actions/setup-python@v2 with: - python-version: "3.8" + python-version: "{{ python_version }}" - name: Install httpie run: | @@ -139,7 +139,7 @@ jobs: - uses: actions/setup-python@v2 with: - python-version: "3.8" + python-version: "{{ python_version }}" - uses: actions/setup-ruby@v1 with: @@ -263,7 +263,7 @@ jobs: - uses: actions/setup-python@v2 with: - python-version: "3.8" + python-version: "{{ python_version }}" - name: Install httpie run: | diff --git a/templates/github/.github/workflows/release.yml.j2 b/templates/github/.github/workflows/release.yml.j2 index 7b5b6d6a..9e4e16e8 100644 --- a/templates/github/.github/workflows/release.yml.j2 +++ b/templates/github/.github/workflows/release.yml.j2 @@ -32,7 +32,7 @@ jobs: - uses: actions/setup-python@v2 with: - python-version: "3.8" + python-version: "{{ python_version }}" - name: Install python dependencies run: | @@ -90,7 +90,7 @@ jobs: - uses: actions/setup-python@v2 with: - python-version: "3.8" + python-version: "{{ python_version }}" {%- if test_bindings or deploy_client_to_rubygems %} - uses: actions/setup-ruby@v1 @@ -211,7 +211,7 @@ jobs: - uses: actions/setup-python@v2 with: - python-version: "3.8" + python-version: "{{ python_version }}" - uses: actions/setup-ruby@v1 with: diff --git a/templates/github/.github/workflows/scripts/before_install.sh.j2 b/templates/github/.github/workflows/scripts/before_install.sh.j2 index 22a578f3..71d43f25 100755 --- a/templates/github/.github/workflows/scripts/before_install.sh.j2 +++ b/templates/github/.github/workflows/scripts/before_install.sh.j2 @@ -48,6 +48,10 @@ echo "legacy_component_name: {{ plugin_snake }}" >> .ci/ansible/vars/main.yaml echo "component_name: {{ plugin_app_label }}" >> .ci/ansible/vars/main.yaml echo "component_version: '${COMPONENT_VERSION}'" >> .ci/ansible/vars/main.yaml +{% if python_version == '3.6' %} +echo "ci_base: pulp/pulp-ci-centos:python36" >> .ci/ansible/vars/main.yaml +{% endif %} + export PRE_BEFORE_INSTALL=$PWD/.github/workflows/scripts/pre_before_install.sh export POST_BEFORE_INSTALL=$PWD/.github/workflows/scripts/post_before_install.sh @@ -68,12 +72,15 @@ then {%- for item in additional_repos %} export {{ item.name | upper | replace("-", "_") }}_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/{{item.org | default("pulp")}}\/{{ item.name }}\/pull\/(\d+)' | awk -F'/' '{print $7}') {%- endfor %} - echo $COMMIT_MSG | sed -n -e 's/.*CI Base Image:\s*\([-_/[:alnum:]]*:[-_[:alnum:]]*\).*/ci_base: "\1"/p' >> .ci/ansible/vars/main.yaml + export CI_BASE_IMAGE=$(echo $COMMIT_MSG | sed -n -e 's/.*CI Base Image:\s*\([-_/[:alnum:]]*:[-_[:alnum:]]*\).*/ci_base: "\1"/p') + if [[ ! -z "$CI_BASE_IMAGE" ]]; then + sed -i '/ci_base:/d' .ci/ansible/vars/main.yml + echo $CI_BASE_IMAGE >> .ci/ansible/vars/main.yaml + fi else {%- for repository in ["pulpcore", "pulp-smash", "pulp-openapi-generator", "pulp-cli"] + additional_repos | map(attribute="name") | list %} export {{ repository | upper | replace("-", "_") }}_PR_NUMBER= {%- endfor %} - export CI_BASE_IMAGE= fi diff --git a/templates/github/.github/workflows/scripts/script.sh.j2 b/templates/github/.github/workflows/scripts/script.sh.j2 index b59426bd..b2e641d8 100755 --- a/templates/github/.github/workflows/scripts/script.sh.j2 +++ b/templates/github/.github/workflows/scripts/script.sh.j2 @@ -104,7 +104,7 @@ echo "Checking for uncommitted migrations..." cmd_prefix bash -c "django-admin makemigrations --check --dry-run" # Run unit tests. -cmd_prefix bash -c "PULP_DATABASES__default__USER=postgres django-admin test --noinput /usr/local/lib/python3.8/site-packages/{{ plugin_snake }}/tests/unit/" +cmd_prefix bash -c "PULP_DATABASES__default__USER=postgres django-admin test --noinput /usr/local/lib/python{{ python_version }}/site-packages/{{ plugin_snake }}/tests/unit/" # Run functional tests {%- if plugin_name == 'pulpcore' %}