Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PULP-206] Refactor nightly #932

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ jobs:
test:
needs: "build"
uses: "./.github/workflows/test.yml"
with:
matrix_env: |
[{"TEST": "pulp"}, {"TEST": "azure"}, {"TEST": "gcp"}, {"TEST": "s3"}, {"TEST": "lowerbounds"}]
deprecations:
runs-on: "ubuntu-latest"
Expand Down
19 changes: 9 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
name: "Test"
on:
workflow_call:
inputs:
matrix_env:
required: true
type: string

defaults:
run:
Expand All @@ -20,12 +24,7 @@ jobs:
strategy:
fail-fast: false
matrix:
env:
- TEST: pulp
- TEST: azure
- TEST: gcp
- TEST: s3
- TEST: lowerbounds
env: ${{ fromJSON(inputs.matrix_env) }}

steps:
- uses: "actions/checkout@v4"
Expand Down Expand Up @@ -87,6 +86,10 @@ jobs:
- name: "Set environment variables"
run: |
echo "TEST=${{ matrix.env.TEST }}" >> $GITHUB_ENV
if [ "${{ matrix.env.TEST }}" = "performance" ]
then
echo "PERFORMANCE_TEST=${{ matrix.env.PERFORMANCE_TEST }}" >> $GITHUB_ENV
fi
- name: "Before Install"
run: |
Expand All @@ -97,10 +100,6 @@ jobs:
ANSIBLE_FORCE_COLOR: "1"
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
GITHUB_CONTEXT: "${{ github.event.pull_request.commits_url }}"
- uses: ruby/setup-ruby@v1
if: ${{ env.TEST == 'pulp' }}
with:
ruby-version: "2.6"

- name: "Install"
run: |
Expand Down
1 change: 1 addition & 0 deletions plugin-template
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ def write_template_section(config, name, plugin_root_dir, verbose=False):
env.filters["dash"] = utils.to_dash
env.filters["snake"] = utils.to_snake
env.filters["to_yaml"] = utils.to_nice_yaml
env.filters["from_yaml"] = utils.from_yaml
env.filters["shquote"] = shlex.quote

files_templated = 0
Expand Down
8 changes: 6 additions & 2 deletions templates/github/.github/workflows/ci.yml.j2
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{% include 'header.j2' %}
{% from 'macros.j2' import
set_env_vars,
checkout,
setup_python,
install_python_deps,
matrix_env,
set_env_vars,
setup_python,
with context %}
---
name: "{{ plugin_app_label | camel }} CI"
Expand Down Expand Up @@ -56,6 +57,9 @@ jobs:
test:
needs: "build"
uses: "./.github/workflows/test.yml"
with:
matrix_env: |
{{ matrix_env() | from_yaml | tojson }}
{%- if test_deprecations %}

deprecations:
Expand Down
83 changes: 9 additions & 74 deletions templates/github/.github/workflows/nightly.yml.j2
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{% include 'header.j2' %}
{% from 'macros.j2' import
checkout,
setup_python,
setup_ruby,
setup_env,
configure_git,
display_logs,
run_script,
set_secrets,
install_python_deps,
configure_git,
matrix_env,
run_script,
setup_env,
setup_python,
with context %}
---
name: "{{ plugin_app_label | camel }} Nightly CI"
Expand All @@ -34,6 +33,9 @@ jobs:
test:
needs: "build"
uses: "./.github/workflows/test.yml"
with:
matrix_env: |
{{ matrix_env(performance=true) | from_yaml | tojson }}

changelog:
runs-on: ubuntu-latest
Expand All @@ -58,71 +60,4 @@ jobs:
branch: "changelog/update"
delete-branch: true
path: "{{ plugin_name }}"

{%- if test_performance %}

performance:
runs-on: ubuntu-latest
needs: test

strategy:
fail-fast: false
matrix:
env:
{%- if test_performance is iterable and test_performance|length > 1 %}
{%- for test in test_performance %}
- TEST: performance
PERFORMANCE_TEST: {{test}}
{%- endfor %}
{%- else %}
- TEST: performance
{%- endif %}

steps:
{{ checkout(path=plugin_name) | indent(6) }}

{{ checkout(repository="pulp/pulp-openapi-generator", path="pulp-openapi-generator") | indent(6) }}

- uses: actions/download-artifact@v4
with:
name: "plugin_package"
path: "{{ plugin_name }}/dist/"

- name: "Download API specs"
uses: "actions/download-artifact@v4"
with:
name: "api_spec"
path: "{{ plugin_name }}/"

- name: "Download client packages"
uses: "actions/download-artifact@v4"
with:
name: "python-client.tar"
path: "{{ plugin_name }}"

- name: "Unpack client packages"
working-directory: "pulp-openapi-generator"
run: |
{%- for plugin in plugins %}
mkdir -p "{{ plugin.name | snake }}-client"
pushd "{{ plugin.name | snake }}-client"
tar xvf "../../{{ plugin_name }}/{{ plugin.app_label }}-python-client.tar"
popd
{%- endfor %}

{{ setup_python() | indent(6) }}

{{ setup_env(test="performance") | indent(6) }}

{{ install_python_deps(["towncrier", "twine", "wheel", "httpie", "docker", "netaddr", "boto3", "ansible", "mkdocs"]) | indent(6) }}

{{ run_script(name="Before Install", file="before_install.sh") | indent(6) }}

{{ run_script(name="Install", file="install.sh") | indent(6) }}

{{ run_script(name="Before Script", file="before_script.sh", extra_env={"REDIS_DISABLED": "${{ contains('%s', matrix.env.TEST) }}" % (disabled_redis_runners | default(["TILT"]) | join(' '))}) | indent(6) }}

{{ run_script(name="Performance Test", file="script.sh") | indent(6) }}

{{ display_logs() | indent(6) }}
{%- endif %}
...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this ... ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is being polite in yaml.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also on a crusade quote all string values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm following the quote crusade, but i was not aware of the ... thing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, its usually used in multifile yaml. I remembered it as was just ---.

32 changes: 10 additions & 22 deletions templates/github/.github/workflows/test.yml.j2
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{% include 'header.j2' %}
{% from 'macros.j2' import
checkout,
setup_python,
setup_ruby,
install_python_deps,
setup_env,
display_logs,
install_python_deps,
run_script,
setup_env,
setup_python,
with context %}
---
name: "Test"
on:
workflow_call:
inputs:
matrix_env:
required: true
type: string

defaults:
run:
Expand All @@ -23,20 +26,9 @@ jobs:
strategy:
fail-fast: false
matrix:
env:
- TEST: pulp
{%- if test_azure %}
- TEST: azure
{%- endif %}
{%- if test_gcp %}
- TEST: gcp
{%- endif %}
{%- if test_s3 %}
- TEST: s3
{%- endif %}
{%- if test_lowerbounds %}
- TEST: lowerbounds
{%- endif %}
{%- raw %}
env: ${{ fromJSON(inputs.matrix_env) }}
{%- endraw %}

steps:
{{ checkout(path=plugin_name) | indent(6) }}
Expand Down Expand Up @@ -81,10 +73,6 @@ jobs:

{{ run_script(name="Before Install", file="before_install.sh") | indent(6) }}

{%- if deploy_client_to_rubygems %}
{{ setup_ruby(condition="${{ env.TEST == 'pulp' }}") | indent(6) }}
{%- endif %}

{{ run_script(name="Install", file="install.sh") | indent(6) }}

{{ run_script(name="Before Script", file="before_script.sh", extra_env={"REDIS_DISABLED": "${{ contains('%s', matrix.env.TEST) }}" % (disabled_redis_runners | default(["TILT"]) | join(' '))}) | indent(6) }}
Expand Down
38 changes: 35 additions & 3 deletions templates/macros.j2
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ GITHUB_CONTEXT: "{{ '${{ github.event.pull_request.commits_url }}' }}"
run: |
echo "TEST={{ "${{ matrix.env.TEST }}" }}" >> $GITHUB_ENV

{%- if test_performance and test == "performance" %}
{%- if test_performance is iterable and test_performance|length > 1 %}
echo "PERFORMANCE_TEST={{ "${{ matrix.env.PERFORMANCE_TEST }}" }}" >> $GITHUB_ENV
{%- endif %}
{%- raw %}
if [ "${{ matrix.env.TEST }}" = "performance" ]
then
echo "PERFORMANCE_TEST=${{ matrix.env.PERFORMANCE_TEST }}" >> $GITHUB_ENV
fi
{%- endraw %}
{%- endif %}
{%- endmacro -%}

Expand Down Expand Up @@ -129,3 +132,32 @@ GITHUB_CONTEXT: "{{ '${{ github.event.pull_request.commits_url }}' }}"
git config --global user.name '{{ release_user }}'
git config --global user.email '{{ release_email }}'
{%- endmacro -%}


{%- macro matrix_env(performance=false) -%}
---
- TEST: "pulp"
{%- if test_azure %}
- TEST: "azure"
{%- endif %}
{%- if test_gcp %}
- TEST: "gcp"
{%- endif %}
{%- if test_s3 %}
- TEST: "s3"
{%- endif %}
{%- if test_lowerbounds %}
- TEST: "lowerbounds"
{%- endif %}
{%- if performance and test_performance %}
{%- if test_performance is iterable and test_performance|length > 1 %}
{%- for test in test_performance %}
- TEST: "performance"
PERFORMANCE_TEST: "{{test}}"
{%- endfor %}
{%- else %}
- TEST: "performance"
{%- endif %}
{%- endif %}
...
{%- endmacro -%}
5 changes: 5 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def to_nice_yaml(data):
return yaml.dump(data, indent=2, allow_unicode=True, default_flow_style=False)


def from_yaml(data):
"""Jinja filter to convert yaml data into a variable."""
return yaml.safe_load(data)


# Information gathering


Expand Down