Skip to content

Commit

Permalink
Prep for new release (#64)
Browse files Browse the repository at this point in the history
* added job to deployment for generating a github release

* updated lock file

* removed setup.py

* cleaning up code and fixed derivation of edit uris

* Update CHANGELOG.md

* Bumped version
  • Loading branch information
jdoiro3 authored Oct 20, 2022
1 parent b90db51 commit 15a023f
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 156 deletions.
51 changes: 50 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
- name: Integration Tests
run: ./__tests__/test-bats-ci.sh

publish:
publish-to-pypi:
needs: integration-tests
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -132,3 +132,52 @@ jobs:
with:
user: __token__
password: ${{ secrets.pypi_api_key }}

tag-and-generate-github-release:
needs: publish-to-pypi
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: 14
- run: |
npm install semver
npm install toml
npm install changelog-parser
- name: Create tag
id: create-tag-and-return-changes
uses: actions/github-script@v6
with:
script: |
const toml = require('toml')
const fs = require('fs').promises
const parseChangelog = require('changelog-parser')
var version = toml.parse(await fs.readFile('pyproject.toml', 'utf8')).tool.poetry.version
var changelog = await parseChangelog('CHANGELOG.md')
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/v${version}`,
sha: context.sha
})
return changelog.versions[0].body
result-encoding: string
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: |
Changes in this Release
${{steps.create-tag-and-return-changes.outputs.result}}
draft: false
prerelease: false
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 0.4.11

- Added a specific `GithubAccessToken` environment variable that allows usage of the plugin with GitHub Apps-generated access tokens and personal access tokens.
- Added a specific `GithubAccessToken` environment variable that allows usage of the plugin with GitHub Apps-generated access tokens and personal access tokens.
- Fixed edit urls for imported repos where the the Mkdocs `edit_uri` and `repo_url` aren't set, and the Multirepo `edit_uri` for an imported repo isn't set. Note that the edit url for imported repos hasn't been robustly tested yet.

## 0.4.10

Expand Down
2 changes: 1 addition & 1 deletion __tests__/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ docker build -t mkdocs-multirepo-test-runner:$1 --quiet -f- . <<EOF
ENV VIRTUAL_ENV=env
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
COPY ./setup.py /workspace/setup.py
COPY ./pyproject.toml /workspace/pyproject.toml
COPY ./mkdocs_multirepo_plugin /workspace/mkdocs_multirepo_plugin
COPY ./README.md /workspace/README.md
COPY ./integration-requirements.txt /workspace/integration-requirements.txt
Expand Down
19 changes: 13 additions & 6 deletions mkdocs_multirepo_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,18 @@ def set_temp_dir(self, dir):
self.temp_dir = dir

def derive_config_edit_uri(self, repo_name: str, repo_url: str, config: Config) -> str:
"""returns the derived edit_uri based on the imported repos url"""
"""returns the derived edit_uri based on the imported repo's url"""
repo_url_key = f"{repo_name}_repo_url"
# temporarily set a new config value b/c EditURI uses it
config[repo_url_key] = repo_url
edit_uri_obj = config_options.EditURI(repo_url_key)
# sets the mkdocs edit_uri in place
# sets the mkdocs edit_uri in place
edit_uri_obj.post_validation(config, "edit_uri")
derived_edit_uri = config.get("edit_uri")
# we just used mkdocs machinery to get the derived value and
# now we delete since the edit_uri needs to be None for other imported repos
# now we can delete these two config entries
del config["edit_uri"]
del config[repo_url_key]
return derived_edit_uri or ""

def setup_imported_repo(self, config: Config):
Expand Down Expand Up @@ -136,12 +138,14 @@ def handle_nav_based_import(self, config: Config) -> Config:
nav_imports = get_import_stmts(nav, self.temp_dir, DEFAULT_BRANCH)
repos: List[DocsRepo] = [nav_import.repo for nav_import in nav_imports]
asyncio_run(batch_import(repos))
need_to_derive_edit_uris = config.get("edit_uri") is None

for nav_import, repo in zip(nav_imports, repos):
repo_config = repo.load_config()
if not repo_config.get("nav"):
raise ImportDocsException(f"{repo.name}'s {repo.config} file doesn't have a nav section")
# mkdocs config values edit_uri and repo_url aren't set
if not config.get("edit_uri"):
if need_to_derive_edit_uris:
derived_edit_uri = self.derive_config_edit_uri(repo.name, repo.url, config)
repo.set_edit_uri(repo_config.get("edit_uri") or config.get("edit_uri") or derived_edit_uri)
# Change the section title value from '!import {url}' to the imported repo's nav
Expand All @@ -152,11 +156,14 @@ def handle_nav_based_import(self, config: Config) -> Config:

def handle_repos_based_import(self, config: Config, repos: List[Dict]) -> Config:
"""Imports documentation in other repos based on repos configuration"""
need_to_derive_edit_uris = config.get("edit_uri") is None
docs_repo_objs = []
for repo in repos:
import_stmt = parse_repo_url(repo.get("import_url"))
if "!import" in import_stmt.get("url"):
raise ImportSyntaxError(f"import_url should only contain the url with plugin accepted params. You included '!import'.")
raise ImportSyntaxError(
"import_url should only contain the url with plugin accepted params. You included '!import'."
)
if set(repo.keys()).difference({"import_url", "section", "section_path"}) != set():
raise ReposSectionException(
"Repos section now only supports 'import_url', 'section', and 'section_path'. \
Expand All @@ -166,7 +173,7 @@ def handle_repos_based_import(self, config: Config, repos: List[Dict]) -> Config
path = repo.get("section_path")
repo_name = f"{path}/{name_slug}" if path is not None else name_slug
# mkdocs config values edit_uri and repo_url aren't set
if not config.get("edit_uri"):
if need_to_derive_edit_uris:
derived_edit_uri = self.derive_config_edit_uri(repo_name, import_stmt.get("url"), config)
repo = DocsRepo(
name=repo_name,
Expand Down
2 changes: 0 additions & 2 deletions mkdocs_multirepo_plugin/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,6 @@ def _fix_edit_uri(self, edit_uri: str) -> str:
# Mkdocs by default sets the edit_uri to 'edit/master/docs/' when the repo_url is GitHub and
# 'src/default/docs/' when it's Bitbucket. We don't want docs to be in the edit_uri since
# documentation isn't always in the docs directory for this plugin.
if not edit_uri:
log.warning(f"set edit_uri in !import statement so edit urls can be formatted correctly for {self.name}.")
edit_uri_parts = edit_uri.strip("/").split("/")
parts = len(edit_uri_parts)
if parts > 1 and edit_uri_parts[1] == "master" and self.branch != "master":
Expand Down
1 change: 0 additions & 1 deletion mkdocs_multirepo_plugin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from mkdocs.utils import warning_filter
from collections import namedtuple
from re import search
import os

# used for getting Git version
GitVersion = namedtuple("GitVersion", "major minor")
Expand Down
Loading

0 comments on commit 15a023f

Please sign in to comment.