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

Add pulp_openapi_generator_ref #906

Closed
wants to merge 4 commits into from
Closed
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
13 changes: 5 additions & 8 deletions plugin-template
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ DEFAULT_SETTINGS = {
"pulp_env_azure": {},
"pulp_env_gcp": {},
"pulp_env_s3": {},
"pulp_openapi_generator_ref": None,
Copy link
Member Author

Choose a reason for hiding this comment

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

How do we want to go about updating this?
Shall we try to keep it floating on latest main, or find the latest available tag, and only pin it down once we branch of a release branch?
Providing a default tag here will not really help updating it in the plugins, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the floating on main and then pin once we branch a release branch. Sounds reasonable and straight-forward.

Copy link
Member Author

Choose a reason for hiding this comment

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

Now we have a problem: After using the default branch on "main", this would pin the release branch to a probably older commit. That does not seem quite right, no?

"pulp_scheme": "https",
"pulp_settings_azure": {"domain_enabled": True},
"pulp_settings_gcp": None,
Expand Down Expand Up @@ -114,10 +115,6 @@ DEPRECATED_FILES = {
"flake8.cfg",
"CHANGES/.TEMPLATE.rst",
],
"docs": [
"docs/_static/.this_makes_it_so_git_keeps_the__static_folder",
"docs/_static/api.json",
],
}

DOCS_OPTION_DEPRECATION_INFO = """\
Expand Down Expand Up @@ -254,10 +251,6 @@ def main():
if key not in config:
config[key] = value
write_new_config = True
# Rename "ci_update_branches" to "supported_release_branches"
if "ci_update_branches" in config:
config["supported_release_branches"] = config.pop("ci_update_branches")
write_new_config = True
# remove deprecated options
for key in set(config.keys()) - set(DEFAULT_SETTINGS.keys()):
config.pop(key)
Expand All @@ -266,6 +259,7 @@ def main():
config["plugins"] = [
{"name": config["plugin_name"], "app_label": config["plugin_app_label"]}
]
# Make up for yaml being crazy with version strings.
if not all(
(
isinstance(version, str)
Expand All @@ -276,6 +270,9 @@ def main():
str(version) for version in config["supported_release_branches"]
]
write_new_config = True
if config["pulp_openapi_generator_ref"] == "PIN THIS":
config["pulp_openapi_generator_ref"] = utils.fetch_latest_pog_tag()
write_new_config = True
print(
"\nLoaded plugin template config from "
"{path}/template_config.yml.\n".format(path=plugin_root_dir)
Expand Down
1 change: 1 addition & 0 deletions scripts/update_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ then
sed -i \
-e 's/^\(ci_update_docs: \)true$/\1false/' \
-e 's/^\(docs_test: \)true$/\1false/' \
-e 's/^\(pulp_openapi_generator_ref: \)null/\1"PIN THIS"/' \
"template_config.yml"
fi

Expand Down
2 changes: 1 addition & 1 deletion templates/github/.github/workflows/build.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

steps:
{{ checkout(path=plugin_name) | indent(6) }}
{{ checkout(repository="pulp/pulp-openapi-generator", path="pulp-openapi-generator") | indent(6) }}
{{ checkout(repository="pulp/pulp-openapi-generator", path="pulp-openapi-generator", ref=pulp_openapi_generator_ref) | indent(6) }}
{{ setup_python() | indent(6) }}
{{ install_python_deps(["packaging", "twine", "wheel", "mkdocs", "jq"]) | indent(6) }}
{%- if os_required_packages %}
Expand Down
52 changes: 34 additions & 18 deletions templates/github/.github/workflows/create-branch.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
install_python_deps
with context %}
---
name: Create New Release Branch
name: "Create New Release Branch"
on:
workflow_dispatch:

env:
RELEASE_WORKFLOW: true

jobs:
create-branch:
runs-on: ubuntu-latest
runs-on: "ubuntu-latest"

strategy:
fail-fast: false
Expand Down Expand Up @@ -59,27 +56,46 @@ jobs:
run: |
find CHANGES -type f -regex ".*\.\(bugfix\|doc\|feature\|misc\|deprecation\|removal\)" -exec git rm {} +

- name: Update CI branches in template_config
working-directory: plugin_template
- name: "Update CI branches in template_config"
working-directory: "plugin_template"
run: |
python3 ./plugin-template {{ plugin_name }} --github --latest-release-branch "${NEW_BRANCH}"
git add -A

- name: Make a PR with version bump and without CHANGES/*
uses: peter-evans/create-pull-request@v6
- name: "Make a PR with version bump and without CHANGES/*"
uses: "peter-evans/create-pull-request@v6"
with:
path: {{ plugin_name }}
token: {{ '${{ secrets.RELEASE_TOKEN }}' }}
committer: {{release_user}} <{{ release_email }}>
author: {{release_user}} <{{ release_email }}>
branch: minor-version-bump
base: {{ plugin_default_branch }}
title: Bump minor version
path: "{{ plugin_name }}"
token: "{{ '${{ secrets.RELEASE_TOKEN }}' }}"
committer: "{{release_user}} <{{ release_email }}>"
author: "{{release_user}} <{{ release_email }}>"
branch: "minor-version-bump"
base: "{{ plugin_default_branch }}"
title: "Bump minor version"
commit-message: |
Bump minor version
delete-branch: true

- name: Push release branch
working-directory: {{ plugin_name }}
- name: "Push release branch"
working-directory: "{{ plugin_name }}"
run: |
git push origin "${NEW_BRANCH}"
git switch "${NEW_BRANCH}"
../plugin_template/scripts/update_ci --release

- name: "Make a PR with to setup the new release branch"
uses: "peter-evans/create-pull-request@v6"
with:
path: "{{ plugin_name }}"
token: "{{ '${{ secrets.RELEASE_TOKEN }}' }}"
committer: "{{release_user}} <{{ release_email }}>"
author: "{{release_user}} <{{ release_email }}>"
branch: "{{ 'update-ci/${{ env.NEW_BRANCH }}' }}"
base: "${{ '{{ env.NEW_BRANCH }}' }}"
title: "Setup Release branch"
body: "[noissue]"
commit-message: |
Bump minor version
[noissue]
delete-branch: true
...
15 changes: 15 additions & 0 deletions utils.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,18 @@ def get_pulpdocs_members() -> list[str]:
)

return [line.strip()[8:] for line in response.content.decode().split("\n") if "- name:" in line]


def fetch_latest_pog_tag():
response = requests.get(
"https://api.github.com/repos/pulp/pulp-openapi-generator/git/refs/tags"
)
tags = [item["ref"] for item in response.json()]
matched_tags = sorted(
[
((int(match.group(1)), int(match.group(2))), f"{match.group(1)}.{match.group(2)}")
for match in (re.fullmatch(r"^refs/tags/(\d{8})\.(\d+)$", tag) for tag in tags)
if match is not None
]
)
return matched_tags[-1][1]
Loading