From 40e11c359be4b6d9a7002fc603d0e690fde3c345 Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Fri, 10 Nov 2023 09:30:19 +0100 Subject: [PATCH] Devide the release process in two parts This will first run a workflow that performs the "git-actions", like creating the changelog, bumping the version and tagging. Secondly the tag itself will trigger a publish workflow that will build packages and docs and publish them to the corresponding places. [noissue] --- plugin-template | 2 - .../github/.github/workflows/publish.yml.j2 | 172 +++++++++++++++ .../github/.github/workflows/release.yml.j2 | 201 +----------------- .../.github/workflows/scripts/release.py.j2 | 1 - 4 files changed, 174 insertions(+), 202 deletions(-) create mode 100644 templates/github/.github/workflows/publish.yml.j2 diff --git a/plugin-template b/plugin-template index cbd71e9b..85c74414 100755 --- a/plugin-template +++ b/plugin-template @@ -375,8 +375,6 @@ def write_template_section(config, name, plugin_root_dir, verbose=False): for relative_path in generate_relative_path_set(section_template_dir): if not config["stalebot"] and "stale" in relative_path: continue - if config["issue_tracker"] != "github" and "update_github" in relative_path: - continue if config["use_issue_template"] is False and "ISSUE_TEMPLATE" in relative_path: continue if config["kanban"] is False and "kanban" in relative_path: diff --git a/templates/github/.github/workflows/publish.yml.j2 b/templates/github/.github/workflows/publish.yml.j2 new file mode 100644 index 00000000..d94dbe7d --- /dev/null +++ b/templates/github/.github/workflows/publish.yml.j2 @@ -0,0 +1,172 @@ +{% include 'header.j2' %} +{% from 'macros.j2' import + set_env_vars, + checkout, + setup_python, + setup_ruby, + install_httpie, + display_logs, + run_script, + set_secrets, + install_python_deps, + configure_git, +with context %} +--- +name: {{ plugin_app_label | camel }} Publish Release +on: + push: + tags: + - "[0-9]+.[0-9]+.[0-9]" + +defaults: + run: + working-directory: "{{ plugin_name }}" + +jobs: + build-bindings-docs: + needs: build-artifacts + runs-on: ubuntu-latest + # Install scripts expect TEST to be set, 'docs' is most appropriate even though we don't run tests + env: + TEST: docs + PLUGIN_VERSION: {{ "${{ github.ref_name }}" }} + + steps: + {{ checkout(depth=1, path=plugin_name) | indent(6) }} + + {{ setup_python() | indent(6) }} + + {%- if deploy_client_to_rubygems %} + {{ setup_ruby() | indent(6) }} + {%- endif %} + + {{ install_httpie() | indent(6) }} + + # Building the bindings and docs requires accessing the OpenAPI specs endpoint, so we need to + # setup the Pulp instance. + {{ run_script(name="Before Install", file="before_install.sh") | indent(6) }} + + {{ run_script(name="Install", file="install.sh") | indent(6) }} + + {{ run_script(name="Install Python client", file="install_python_client.sh", withenv=False) | indent(6) }} + + {%- if deploy_client_to_rubygems %} + {{ run_script(name="Install Ruby client", file="install_ruby_client.sh", withenv=False) | indent(6) }} + {%- endif %} + + - name: Upload python client packages + uses: actions/upload-artifact@v3 + with: + name: python-client.tar + path: python-client.tar + + - name: Upload python client docs + uses: actions/upload-artifact@v3 + with: + name: python-client-docs.tar + path: python-client-docs.tar + + {%- if deploy_client_to_rubygems %} + - name: Upload ruby client packages + uses: actions/upload-artifact@v3 + with: + name: ruby-client.tar + path: ruby-client.tar + {%- endif %} + + {%- if publish_docs_to_pulpprojectdotorg and docs_test %} + - name: Build docs + run: | + export DJANGO_SETTINGS_MODULE=pulpcore.app.settings + export PULP_SETTINGS=$PWD/.ci/ansible/settings/settings.py + make -C docs/ PULP_URL="{{ pulp_scheme }}://pulp" diagrams html + tar -cvf docs/docs.tar docs/_build + + - name: Upload built docs + uses: actions/upload-artifact@v3 + with: + name: docs.tar + path: docs/docs.tar + {%- endif %} + + {{ display_logs() | indent(6) }} + + + publish: + runs-on: ubuntu-latest + needs: build-bindings-docs + + env: + TEST: publish + GITHUB_TOKEN: {{ "${{ secrets.GITHUB_TOKEN }}" }} + + steps: + - uses: actions/download-artifact@v3 + with: + name: {{ plugin_name }}.tar + + {{ setup_python(pyversion="3.8") | indent(6) }} + + {{ setup_ruby() | indent(6) }} + + {{ configure_git() | indent(6) }} + + - name: Untar repository + run: | + tar -xf {{ plugin_name }}.tar + + {{ set_secrets() | indent(6) }} + + {{ install_python_deps("gitpython requests packaging~=21.3") | indent(6) }} + + {%- if publish_docs_to_pulpprojectdotorg and docs_test %} + + - name: Download built docs + uses: actions/download-artifact@v3 + with: + name: docs.tar + + - name: Download Python client docs + uses: actions/download-artifact@v3 + with: + name: python-client-docs.tar + + - name: Publish docs to pulpproject.org + run: | + tar -xvf docs.tar + .github/workflows/scripts/publish_docs.sh tag {{ "${{ github.ref_name }}" }} + {%- endif %} + + {%- if deploy_to_pypi %} + - name: Deploy plugin to pypi + run: bash .github/workflows/scripts/publish_plugin_pypi.sh {{ "${{ github.ref_name }}" }} + {%- endif %} + + {%- if deploy_client_to_pypi %} + - name: Download Python client + uses: actions/download-artifact@v3 + with: + name: python-client.tar + + - name: Untar python client packages + run: tar -xvf python-client.tar + + - name: Publish client to pypi + run: bash .github/workflows/scripts/publish_client_pypi.sh + {%- endif %} + + {%- if deploy_client_to_rubygems %} + - name: Download Ruby client + uses: actions/download-artifact@v3 + with: + name: ruby-client.tar + + - name: Untar Ruby client packages + run: tar -xvf ruby-client.tar + + - name: Publish client to rubygems + run: bash .github/workflows/scripts/publish_client_gem.sh + {%- endif %} + + - name: Create release on GitHub + run: bash .github/workflows/scripts/create_release_from_tag.sh {{ "${{ github.ref_name }}" }} diff --git a/templates/github/.github/workflows/release.yml.j2 b/templates/github/.github/workflows/release.yml.j2 index 2b3b6c20..6ff12b49 100644 --- a/templates/github/.github/workflows/release.yml.j2 +++ b/templates/github/.github/workflows/release.yml.j2 @@ -1,12 +1,7 @@ {% include 'header.j2' %} {% from 'macros.j2' import - set_env_vars, checkout, setup_python, - setup_ruby, - install_httpie, - display_logs, - run_script, set_secrets, install_python_deps, configure_git, @@ -15,9 +10,6 @@ with context %} name: {{ plugin_app_label | camel }} Release Pipeline on: workflow_dispatch: - inputs: - release: - description: "Release tag (e.g. 3.2.1)" defaults: run: @@ -41,194 +33,5 @@ jobs: {{ set_secrets() | indent(6) }} - - name: Create the release commit, tag it, create a post-release commit, and build plugin package - run: python .github/workflows/scripts/release.py {{ "${{ github.event.inputs.release }}" }} - - - name: "Tar files" - run: | - tar -cvf {{ plugin_name }}.tar . - - - name: "Upload Artifact" - uses: actions/upload-artifact@v3 - with: - name: "{{ plugin_name }}.tar" - path: "{{ plugin_name }}/{{ plugin_name }}.tar" - - - build-bindings-docs: - needs: build-artifacts - runs-on: ubuntu-latest - # Install scripts expect TEST to be set, 'docs' is most appropriate even though we don't run tests - env: - TEST: docs - - steps: - - uses: actions/download-artifact@v3 - with: - name: "{{ plugin_name }}.tar" - path: "{{ plugin_name }}/" - - {{ checkout(repository="pulp/pulp-openapi-generator", path="pulp-openapi-generator") | indent(6) }} - - {{ setup_python() | indent(6) }} - - {%- if deploy_client_to_rubygems %} - {{ setup_ruby() | indent(6) }} - {%- endif %} - - - name: "Untar repository" - run: | - tar -xf {{ plugin_name }}.tar - - {{ install_httpie() | indent(6) }} - - # Building the bindings and docs requires accessing the OpenAPI specs endpoint, so we need to - # setup the Pulp instance. - {{ run_script(name="Before Install", file="before_install.sh") | indent(6) }} - - - name: Install - run: | - export PLUGIN_VERSION={{ "${{ github.event.inputs.release }}" }} - .github/workflows/scripts/install.sh - env: - {{ set_env_vars() | indent(10) }} - shell: bash - - {{ run_script(name="Install Python client", file="install_python_client.sh", withenv=False) | indent(6) }} - - {%- if deploy_client_to_rubygems %} - {{ run_script(name="Install Ruby client", file="install_ruby_client.sh", withenv=False) | indent(6) }} - {%- endif %} - - {%- for plugin in plugins %} - - name: "Upload python client packages" - uses: actions/upload-artifact@v3 - with: - name: "python-client.tar" - path: "{{ plugin_name }}/{{ plugin.app_label }}-python-client.tar" - if-no-files-found: "error" - - - name: "Upload python client docs" - uses: actions/upload-artifact@v3 - with: - name: "python-client-docs.tar" - path: "{{ plugin_name }}/{{ plugin.app_label }}-python-client-docs.tar" - if-no-files-found: "error" - - {%- if deploy_client_to_rubygems %} - - name: "Upload ruby client packages" - uses: actions/upload-artifact@v3 - with: - name: "ruby-client.tar" - path: "{{ plugin_name }}/{{ plugin.app_label }}-ruby-client.tar" - if-no-files-found: "error" - {%- endif %} - {%- endfor %} - - {%- if publish_docs_to_pulpprojectdotorg and docs_test %} - - name: Build docs - run: | - export DJANGO_SETTINGS_MODULE=pulpcore.app.settings - export PULP_SETTINGS=$PWD/.ci/ansible/settings/settings.py - make -C docs/ PULP_URL="{{ pulp_scheme }}://pulp" diagrams html - tar -cvf docs/docs.tar docs/_build - - - name: "Upload built docs" - uses: actions/upload-artifact@v3 - with: - name: "docs.tar" - path: "{{ plugin_name }}/docs/docs.tar" - {%- endif %} - - {{ display_logs() | indent(6) }} - - - publish: - runs-on: ubuntu-latest - needs: build-bindings-docs - - env: - TEST: publish - GITHUB_TOKEN: {{ "${{ secrets.GITHUB_TOKEN }}" }} - - steps: - - uses: actions/download-artifact@v3 - with: - name: "{{ plugin_name }}.tar" - path: "{{ plugin_name }}/" - - {{ setup_python(pyversion="3.8") | indent(6) }} - - {{ setup_ruby() | indent(6) }} - - {{ configure_git() | indent(6) }} - - - name: Untar repository - run: | - tar -xf {{ plugin_name }}.tar - - {{ set_secrets() | indent(6) }} - - {{ install_python_deps("gitpython requests packaging~=21.3 tweepy") | indent(6) }} - - - name: Push branch and tag to GitHub - run: bash .github/workflows/scripts/push_branch_and_tag_to_github.sh {{ "${{ github.event.inputs.release }}" }} - - {%- if publish_docs_to_pulpprojectdotorg and docs_test %} - - name: "Download built docs" - uses: actions/download-artifact@v3 - with: - name: "docs.tar" - path: "{{ plugin_name }}/" - - - name: "Download Python client docs" - uses: actions/download-artifact@v3 - with: - name: "python-client-docs.tar" - path: "{{ plugin_name }}/" - - - name: Publish docs to pulpproject.org - run: | - tar -xvf docs.tar - .github/workflows/scripts/publish_docs.sh tag {{ "${{ github.event.inputs.release }}" }} - {%- endif %} - - {%- if deploy_to_pypi %} - - name: Deploy plugin to pypi - run: bash .github/workflows/scripts/publish_plugin_pypi.sh {{ "${{ github.event.inputs.release }}" }} - {%- endif %} - - {%- if deploy_client_to_pypi %} - - name: "Download Python client" - uses: actions/download-artifact@v3 - with: - name: "python-client.tar" - path: "{{ plugin_name }}/" - - - name: "Untar python client packages" - run: | - tar -xvf python-client.tar - - - name: "Publish client to pypi" - run: | - bash .github/workflows/scripts/publish_client_pypi.sh - {%- endif %} - - {%- if deploy_client_to_rubygems %} - - name: "Download Ruby client" - uses: actions/download-artifact@v3 - with: - name: "ruby-client.tar" - path: "{{ plugin_name }}/" - - - name: "Untar Ruby client packages" - run: | - tar -xvf ruby-client.tar - - - name: "Publish client to rubygems" - run: | - bash .github/workflows/scripts/publish_client_gem.sh - {%- endif %} - - - name: Create release on GitHub - run: bash .github/workflows/scripts/create_release_from_tag.sh {{ "${{ github.event.inputs.release }}" }} + - name: Create the release commit, tag it, create a post-release commit, and push them to github + run: python .github/workflows/scripts/release.py diff --git a/templates/github/.github/workflows/scripts/release.py.j2 b/templates/github/.github/workflows/scripts/release.py.j2 index 4e8d62a4..b748b55a 100644 --- a/templates/github/.github/workflows/scripts/release.py.j2 +++ b/templates/github/.github/workflows/scripts/release.py.j2 @@ -4,7 +4,6 @@ import argparse import re import os import textwrap -import requests import subprocess from git import Repo