Skip to content

Commit

Permalink
Reuse test workflow for nightly performance
Browse files Browse the repository at this point in the history
  • Loading branch information
mdellweg committed Nov 27, 2024
1 parent 517975a commit 5f19e54
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 109 deletions.
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
84 changes: 8 additions & 76 deletions templates/github/.github/workflows/nightly.yml.j2
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{% include 'header.j2' %}
{% from 'macros.j2' import
checkout,
setup_python,
setup_ruby,
install_python_deps,
setup_env,
configure_git,
display_logs,
install_python_deps,
matrix_env,
run_script,
configure_git,
setup_env,
setup_python,
with context %}
---
name: "{{ plugin_app_label | camel }} Nightly CI"
Expand All @@ -33,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 @@ -57,75 +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) }}

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

- name: "Download plugin package"
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 }}/"
{%- if plugins %}

- 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 %}
{%- endif %}

{{ install_python_deps(["towncrier", "twine", "wheel", "httpie", "docker", "netaddr", "boto3", "ansible~=10.3.0", "mkdocs", "jq", "jsonpatch", "bump-my-version"]) | indent(6) }}

{{ setup_env(test="performance") | 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="Script", file="script.sh") | indent(6) }}

{{ display_logs() | indent(6) }}
{%- endif %}
...
28 changes: 10 additions & 18 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
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

0 comments on commit 5f19e54

Please sign in to comment.