Skip to content

Commit

Permalink
Devide the release process in two parts
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
mdellweg committed Nov 24, 2023
1 parent 4f9e3c7 commit 89b1d48
Show file tree
Hide file tree
Showing 9 changed files with 309 additions and 414 deletions.
3 changes: 1 addition & 2 deletions plugin-template
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ DEPRECATED_FILES = {
".ci/scripts/upper_bound.py",
".github/workflows/fips.yml",
".github/workflows/scripts/create_release_from_tag.sh",
".github/workflows/scripts/release.py",
".github/workflows/scripts/stage-changelog-for-master.py",
".github/workflows/scripts/update_ci.sh",
".travis",
Expand Down Expand Up @@ -377,8 +378,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:
Expand Down
6 changes: 4 additions & 2 deletions templates/github/.github/workflows/build.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ jobs:
steps:
{{ checkout(path=plugin_name) | indent(6) }}
{{ setup_python() | indent(6) }}
{{ install_python_deps("packaging wheel") | indent(6) }}
{{ install_python_deps("packaging twine wheel") | indent(6) }}
- name: "Build package"
run: "python3 setup.py sdist bdist_wheel --python-tag py3"
run: |
python3 setup.py sdist bdist_wheel --python-tag py3
twine check dist/*
- name: 'Upload Package whl'
uses: "actions/upload-artifact@v3"
with:
Expand Down
269 changes: 269 additions & 0 deletions templates/github/.github/workflows/publish.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
{% 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:
uses: "./.github/workflows/build.yml"

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) }}

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

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

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

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

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

{%- if deploy_to_pypi %}
publish-package:
runs-on: ubuntu-latest
needs: build-bindings-docs

env:
GITHUB_TOKEN: {{ "${{ secrets.GITHUB_TOKEN }}" }}

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

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

{{ setup_python(pyversion="3.8") | indent(6) }}

{{ install_python_deps("requests packaging~=21.3") | indent(6) }}

{{ set_secrets() | indent(6) }}

- name: Deploy plugin to pypi
run: bash .github/workflows/scripts/publish_plugin_pypi.sh {{ "${{ github.ref_name }}" }}
{%- endif %}

{%- if deploy_client_to_pypi %}
publish-python-bindings:
runs-on: ubuntu-latest
needs: build-bindings-docs

env:
GITHUB_TOKEN: {{ "${{ secrets.GITHUB_TOKEN }}" }}

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

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

- name: "Untar python client packages"
run: |
{%- for plugin in plugins %}
tar -xvf {{ plugin.app_label }}-python-client.tar
{%- endfor %}

{{ setup_python(pyversion="3.8") | indent(6) }}

{{ install_python_deps("requests packaging~=21.3") | indent(6) }}

{{ set_secrets() | indent(6) }}

- name: "Publish client to pypi"
run: |
bash .github/workflows/scripts/publish_client_pypi.sh
{%- endif %}

{%- if deploy_client_to_rubygems %}
publish-ruby-bindings:
runs-on: ubuntu-latest
needs: build-bindings-docs

env:
GITHUB_TOKEN: {{ "${{ secrets.GITHUB_TOKEN }}" }}

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

- name: "Download Ruby client"
uses: actions/download-artifact@v3
with:
name: "ruby-client.tar"
path: "{{ plugin_name }}/"

- name: "Untar Ruby client packages"
run: |
{%- for plugin in plugins %}
tar -xvf {{ plugin.app_label }}-ruby-client.tar
{%- endfor %}

{{ setup_python(pyversion="3.8") | indent(6) }}

{{ setup_ruby() | indent(6) }}

{{ set_secrets() | indent(6) }}

- name: "Publish client to rubygems"
run: |
bash .github/workflows/scripts/publish_client_gem.sh
{%- endif %}

{%- if publish_docs_to_pulpprojectdotorg %}
publish-docs:
runs-on: ubuntu-latest
needs: build-bindings-docs

env:
GITHUB_TOKEN: {{ "${{ secrets.GITHUB_TOKEN }}" }}

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

{{ setup_python(pyversion="3.8") | indent(6) }}

{{ install_python_deps("requests packaging~=21.3") | indent(6) }}

{{ set_secrets() | indent(6) }}

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

create-gh-release:
runs-on: ubuntu-latest
needs:
- build-bindings-docs
{%- if deploy_to_pypi %}
- publish-package
{%- endif %}
{%- if deploy_client_to_pypi %}
- publish-python-bindings
{%- endif %}
{%- if deploy_client_to_rubygems %}
- publish-ruby-bindings
{%- endif %}
{%- if publish_docs_to_pulpprojectdotorg %}
- publish-docs
{%- endif %}

steps:
- name: Create release on GitHub
uses: actions/github-script@v7
env:
TAG_NAME: {{ '${{ github.ref_name }}' }}
with:
const { TAG_NAME } = process.env;

script: |
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: TAG_NAME,
make_latest: "legacy",
});
Loading

0 comments on commit 89b1d48

Please sign in to comment.