From a50cc7a4c65629ef6329d401290f0f15d2c77565 Mon Sep 17 00:00:00 2001 From: JsNcAr Date: Mon, 12 Oct 2026 11:02:36 -0500 Subject: [PATCH 1/2] ci: GitLab pipeline with the same lint, test and release jobs .gitlab-ci.yml for a GitLab instance, kept in step with the GitHub workflows: one pipeline per change (merge request pipelines win over branch pipelines), lint (black, flake8, mypy, pip-audit) and test (postgres:17 service, JUnit report in the merge request widget) on every change, and on a v* tag the release jobs: verify (scripts/release.py, nothing installed), build (poetry build) and release (glab, job-token login, wheel and sdist in the generic package registry and linked from the release page). Python comes from PYTHON_VERSION, checked against .python-version so the two cannot drift; Poetry from poetry.lock's header. Validated with the instance's CI lint API (GitLab 19.2). Docs describe both hosts; the adapting list names the GitLab variables. Co-Authored-By: Claude Fable 5.1 --- .gitlab-ci.yml | 173 +++++++++++++++++++++++++++++++++++++++++++ AGENTS.md | 5 +- CHANGELOG.md | 5 ++ README.md | 9 ++- docs/known_issues.md | 4 +- docs/releasing.md | 52 ++++++++----- docs/setup.md | 27 +++++-- 7 files changed, 242 insertions(+), 33 deletions(-) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..d82ff50 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,173 @@ +# Lint, tests and releases on a GitLab instance. The GitHub equivalents are +# .github/workflows/ci.yml and release.yml; both hosts read the same sources +# of truth, so nothing is pinned twice: Python from .python-version (checked +# against PYTHON_VERSION below), Poetry from poetry.lock's header, the +# version and the release notes through scripts/release.py. +# +# Adapting this starter to a new project: edit the `variables` block and the +# postgres image tag in `test`; nothing in the jobs refers to the project by +# name. The starter itself never gets a v* tag (scripts/release.py refuses +# while [tool.release] starter = true), so the release jobs are dormant here. + +# One pipeline per change: a branch with an open merge request gets the merge +# request pipeline only, not a second branch pipeline for the same commit. +# A v* tag gets its own pipeline, which adds the release jobs. +workflow: + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS + when: never + - if: $CI_COMMIT_BRANCH + - if: $CI_COMMIT_TAG =~ /^v[0-9]/ + +stages: + - lint + - test + - build + - release + +variables: + # The image tag cannot read .python-version, so the minor is repeated here; + # .python's before_script fails the job if the two disagree. + PYTHON_VERSION: "3.14" + # Paths black and flake8 check; mypy takes its paths from [tool.mypy]. + CODE_PATHS: src tests scripts + # Throwaway database for the test job. None of these are secrets. The + # POSTGRES_* values configure the service; tests/conftest.py builds the test + # database URL from DB_*, so the two sets must agree. DB_HOST is the service + # host name the runner derives from the image name. + POSTGRES_USER: ci + POSTGRES_PASSWORD: ci + POSTGRES_DB: ci_test_db + DB_USER: ci + DB_PASSWORD: ci + DB_HOST: postgres + DB_PORT: "5432" + TEST_DB_NAME: ci_test_db + # The app refuses to import without these two; the secret must be at least + # 32 bytes (config.py checks), otherwise any value works in CI. + JWT_SECRET_KEY: ci-only-not-a-secret-but-at-least-32-bytes-long + API_KEY: ci-only-not-a-secret + +# Python with the dev group installed, and pip and Poetry caches that live for +# as long as poetry.lock is unchanged. +.python: + image: python:${PYTHON_VERSION}-slim + variables: + PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" + POETRY_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pypoetry" + cache: + key: + files: + - poetry.lock + paths: + - .cache/pip + - .cache/pypoetry + before_script: + - | + wanted="$(tr -d '[:space:]' < .python-version)" + actual="$(python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')" + if [ "$wanted" != "$actual" ]; then + echo "PYTHON_VERSION=$PYTHON_VERSION gives Python $actual but .python-version says $wanted; keep them in step." + exit 1 + fi + - pip install "poetry==$(sed -n 's/.*generated by Poetry \([0-9.]*\).*/\1/p' poetry.lock | head -1)" + - poetry install --no-interaction + +lint: + extends: .python + stage: lint + # Only test saves the cache: its contents change only with poetry.lock, and + # re-saving it in both jobs costs time for nothing. + cache: + policy: pull + interruptible: true + script: + - poetry run black --check $CODE_PATHS + - poetry run flake8 $CODE_PATHS + - poetry run mypy + # Known vulnerabilities in the installed dependencies; the project's own + # package is editable and not on PyPI, so it is skipped rather than failed. + - poetry run pip-audit --progress-spinner off --skip-editable + +test: + extends: .python + stage: test + # Start at once instead of after lint; build and release still need both. + needs: [] + interruptible: true + services: + # The PostgreSQL major the project targets; CI on GitHub tests the same one. + - postgres:17 + script: + - poetry run pytest --junitxml=report.xml + artifacts: + when: always + reports: + # Test results show up in the merge request widget. + junit: report.xml + expire_in: 1 week + +# --- Release pipeline: only on a v* tag made by scripts/release.py --------- + +# The script is standard library only, so nothing is installed first: the tag +# must match pyproject.toml and CHANGELOG.md must have the section. +verify: + stage: lint + image: python:${PYTHON_VERSION}-slim + cache: [] + rules: + - if: $CI_COMMIT_TAG =~ /^v[0-9]/ + script: + - python scripts/release.py check-version "$CI_COMMIT_TAG" + - python scripts/release.py notes "$CI_COMMIT_TAG" > release-notes.md + artifacts: + paths: + - release-notes.md + expire_in: 1 week + +build: + extends: .python + stage: build + cache: + policy: pull + rules: + - if: $CI_COMMIT_TAG =~ /^v[0-9]/ + needs: + - verify + - lint + - test + script: + - poetry build + artifacts: + paths: + - dist/ + expire_in: 1 week + +# One job creates the release once everything passed, so a failed check never +# leaves a release behind. glab authenticates with the job token +# (GLAB_ENABLE_CI_AUTOLOGIN); the wheel and sdist go to the project's generic +# package registry, which accepts the job token, and are linked from the +# release page. release-cli is deprecated since GitLab 18.0; glab replaces it. +release: + stage: release + # Pinned, not `latest`: every upstream rebuild of a floating tag leaves the + # previous image dangling on the runner host. + image: registry.gitlab.com/gitlab-org/cli:v1.122.0 + cache: [] + rules: + - if: $CI_COMMIT_TAG =~ /^v[0-9]/ + needs: + - verify + - build + variables: + GIT_STRATEGY: none + GLAB_ENABLE_CI_AUTOLOGIN: "true" + script: + - | + glab release create "$CI_COMMIT_TAG" dist/* \ + --name "$CI_COMMIT_TAG" \ + --notes-file release-notes.md \ + --ref "$CI_COMMIT_SHA" \ + --use-package-registry \ + --package-name "$CI_PROJECT_NAME" diff --git a/AGENTS.md b/AGENTS.md index 595bdeb..435f846 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -7,7 +7,7 @@ Poetry-managed. * **Environment**: the app refuses to start without `DATABASE_URL`, `API_KEY` and a 32+ byte `JWT_SECRET_KEY` (`src/basic_api/config.py`); copy `.env.example` to `.env`. A dev machine may have no PostgreSQL: database - tests then run only in CI. + tests then run only in CI (`.github/workflows/ci.yml` and `.gitlab-ci.yml`, kept in step). * **Configuration**: add a variable in `config.py` and `.env.example` together; nothing else reads the environment. * **Errors**: routers translate domain exceptions (`exceptions.py`) to status @@ -56,7 +56,8 @@ docs/ # setup, authentication, api, schemas, releasing, known_issue * **Type check**: `poetry run mypy` (covers `src` and `scripts`) * **Release** (in a clone, never in the starter): `poetry run python scripts/release.py prepare minor`; `--dry-run` first. The version lives only in `pyproject.toml`; Unreleased in - `CHANGELOG.md` becomes the notes. `.github/workflows/release.yml` publishes the tag. + `CHANGELOG.md` becomes the notes. `.github/workflows/release.yml` (GitHub) or the + tag jobs in `.gitlab-ci.yml` (GitLab) publish the tag. * **Dependency audit**: `poetry run pip-audit` (CI runs it in `lint`) * **Dependencies**: `poetry add ` (dev tools: `--group dev`), then `poetry install`. Ranges in `pyproject.toml` are open to the next major; `poetry.lock` is the pin. diff --git a/CHANGELOG.md b/CHANGELOG.md index 97d6176..07f956f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,11 @@ notes (see [docs/releasing.md](docs/releasing.md)). - `cryptography` 46.0.3 to 50.0.2, closing seven published advisories (#7). ### Added +- `.gitlab-ci.yml`: the same lint and test jobs as the GitHub workflow for a + GitLab instance (test results in the merge request widget), plus the release + jobs on a `v*` tag: verify, build, and a GitLab release created with `glab` + with the wheel and sdist in the generic package registry. The release script + prints the pipeline URL for GitHub or GitLab remotes (#18). - Release tooling: `scripts/release.py prepare patch|minor|major|X.Y.Z` runs the suite, bumps `pyproject.toml`, turns Unreleased into the version's section, commits, tags and pushes atomically; `.github/workflows/release.yml` diff --git a/README.md b/README.md index 64b1258..ff324e3 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ configuration right. That work is done here, tested, and documented. - User self-service: read, update, change password and delete the own account - Async PostgreSQL through SQLModel and asyncpg; health check that pings it - One `config.py` reads and validates every environment variable at startup -- black, flake8 and mypy clean; pytest suite; GitHub Actions lint and test jobs +- black, flake8 and mypy clean; pytest suite; lint and test pipelines for GitHub Actions and GitLab CI ## Documentation @@ -34,7 +34,7 @@ configuration right. That work is done here, tested, and documented. | [Authentication](docs/authentication.md) | API key, login flow, token lifetime, what invalidates a token, rate limits, errors | | [API Reference](docs/api.md) | Every endpoint with status codes, response envelope and error shape | | [Schemas](docs/schemas.md) | Request and response models with their limits | -| [Releasing](docs/releasing.md) | `scripts/release.py`: version bump, changelog, tag, GitHub release; writing the notes | +| [Releasing](docs/releasing.md) | `scripts/release.py`: version bump, changelog, tag, release on GitHub or GitLab; writing the notes | | [Known Issues](docs/known_issues.md) | What the starter deliberately does not do yet | | [Changelog](CHANGELOG.md) | What changed and when | @@ -62,7 +62,8 @@ basic_api/ users.py # Business rules for users, independent of HTTP tests/ # pytest suite; database-backed and pure tests docs/ # Written documentation - .github/workflows/ci.yml + .github/workflows/ # ci.yml and release.yml (GitHub Actions) + .gitlab-ci.yml # the same jobs for GitLab pyproject.toml # Poetry project, dev group, black and mypy config .env.example # Every variable, grouped, with its default ``` @@ -123,7 +124,7 @@ poetry run black --check src tests && poetry run flake8 src tests && poetry run ``` CI runs the same three checks and the full suite against `postgres:17` on every -push and pull request. +push and pull or merge request, on GitHub Actions or GitLab. ## Adapting this starter diff --git a/docs/known_issues.md b/docs/known_issues.md index d5512a5..7c8e238 100644 --- a/docs/known_issues.md +++ b/docs/known_issues.md @@ -171,9 +171,9 @@ logging handler or ASGI middleware. ### CI has no coverage or secret scan -**Where:** `.github/workflows/ci.yml`. +**Where:** `.github/workflows/ci.yml`, `.gitlab-ci.yml`. -The pipeline formats, lints, type-checks, audits dependencies (`pip-audit`) +The pipelines format, lint, type-checks, audits dependencies (`pip-audit`) and tests, and Dependabot proposes updates. It does not measure coverage and does not scan for committed secrets. diff --git a/docs/releasing.md b/docs/releasing.md index 0a55251..9483f87 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -10,21 +10,29 @@ project built from it. ```text CHANGELOG.md "Unreleased" --> scripts/release.py prepare --> commit + tag vX.Y.Z --> push | -GitHub release (notes, wheel, sdist) <-- publish <-- build <-- ci <-- verify <----+ +release page (notes, wheel, sdist) <-- publish <-- build <-- lint + test <-- verify <-+ ``` - **The notes** are the `## [Unreleased]` section of [CHANGELOG.md](../CHANGELOG.md). - The script renames it to the version; the workflow publishes that section as + The script renames it to the version; the pipeline publishes that section as the release notes, word for word. - **The script** (`scripts/release.py`) bumps the version, updates the changelog, commits, tags, and pushes. The version lives in one place, `[project] version` in `pyproject.toml`; the app reads it from the installed package metadata (`APP_VERSION`, shown by `GET /` and the OpenAPI document). -- **The workflow** (`.github/workflows/release.yml`) runs on the pushed tag: +- **The pipeline** runs on the pushed tag, on either host: 1. **verify**: the tag matches `pyproject.toml` and the notes exist. - 2. **ci**: the same lint and test jobs as a pull request, PostgreSQL included. + 2. **lint and test**: the same jobs as a pull or merge request, PostgreSQL + included. 3. **build**: the wheel and the sdist (`poetry build`). - 4. **publish**: one GitHub release, created only when everything passed. + 4. **publish**: one release, created only when everything passed. + + On GitHub that is `.github/workflows/release.yml` (a GitHub release with the + archives attached, marked pre-release when the version has a suffix). On + GitLab it is the tag pipeline in `.gitlab-ci.yml` (a GitLab release created + with `glab`; the archives go to the project's generic package registry and + are linked from the release page). Both repositories can hold both files; a + host ignores the other's. ## Choosing the version @@ -41,8 +49,9 @@ a client of this API would notice. The commit type cannot tell the script that a `feat` broke a client; you choose the part. For a test deployment ahead of a release, give an explicit pre-release version: `prepare 1.0.0-rc.1`. It is published as a **pre-release**, -so GitHub does not show it as "Latest". A later `prepare patch|minor|major` -from `1.0.0-rc.N` finishes it as `1.0.0`. +so GitHub does not show it as "Latest" (GitLab has no pre-release flag; the +suffix in the name is the signal). A later `prepare patch|minor|major` from +`1.0.0-rc.N` finishes it as `1.0.0`. A pre-release spelled `1.0.0-rc.1` is valid PEP 440, and the installed metadata normalises it: `GET /` reports `1.0.0rc1`. The tag and the changelog keep the @@ -98,7 +107,7 @@ The script: server reports the new version; the installed metadata is written at install time, not read from `pyproject.toml`. 8. Asks, then pushes `main` and the tag in one atomic push, which starts the - workflow. + pipeline, and prints where to watch it. Answer **no** at the push question, or pass `--no-push`, to stop with everything still local. Push later with the command it prints, or undo with: @@ -110,12 +119,20 @@ git tag -d vX.Y.Z && git reset --hard HEAD~1 Other options: `--skip-tests` when you have just run them; `--yes` answers every question, for scripted use; `--allow-branch` releases from another branch. -### 5. Watch the workflow and check the release +### 5. Watch the pipeline and check the release + +Open the repository's **Actions** tab (GitHub) or **Build > Pipelines** +(GitLab). The release appears under **Releases** (GitHub) or **Deploy > +Releases** (GitLab) when the last job finishes. Check that the notes read +correctly, the wheel and the sdist are attached, and a deployment of the tag +answers the new version on `GET /`. -Open the repository's **Actions** tab. The release appears under **Releases** -when *publish* finishes. Check that the notes read correctly, the wheel and the -sdist are attached, and a deployment of the tag answers the new version on -`GET /`. +On GitLab, the first release of a project is also the first test of the job +token's rights: if `release` fails uploading the archives (a 401 or 403 from +the package registry), check that **Settings > General > Visibility > Package +registry** is on and that the job token is allowed to reach the project +(**Settings > CI/CD > Job token permissions**). Nothing was published; fix and +rerun the job. ## The starter and its clones @@ -129,7 +146,7 @@ starter = true A project built from the starter sets it to `false` once (it is in the [Adapting this starter](setup.md#adapting-this-starter) list) and inherits the -script, the workflow, the test and this page unchanged; nothing in them names +script, both pipelines, the test and this page unchanged; nothing in them names the project. The first release works from a repository with no tags: the Unreleased section is the notes, and if it is empty the script lists every conventional commit in the history, so write the section. Start wherever the @@ -209,7 +226,8 @@ Each entry is the summary with its scope in bold and the short commit hash. ```bash python scripts/release.py notes X.Y.Z > notes.md - gh release edit vX.Y.Z --notes-file notes.md + gh release edit vX.Y.Z --notes-file notes.md # GitHub + glab release create vX.Y.Z --notes-file notes.md # GitLab: updates an existing release ``` The annotated tag keeps the original text; that is expected. @@ -224,8 +242,8 @@ Each entry is the summary with its scope in bold and the short commit hash. | Tests fail in `prepare` | Nothing was written. Fix on `main` first. | | The push was rejected (branch protection on `main`) | Nothing was pushed: the push is atomic. Allow the push for the release commit, or push it through a PR and push the tag after merging (`git push origin vX.Y.Z`; the tag must point at the merged commit). | | *verify* fails | The tag was not made by the script, or `pyproject.toml` was edited by hand. Delete the tag (`git push --delete origin vX.Y.Z && git tag -d vX.Y.Z`), fix, release again. Nothing was published. | -| *ci* or *build* fails | Nothing is published. A flaky runner: **Re-run failed jobs**. Code at fault: fix on `main`, delete the tag as above, release the next patch version rather than reusing the number. | -| *publish* fails | Re-run the failed job; the archives from *build* are reused. | +| *lint*, *test* or *build* fails | Nothing is published. A flaky runner: rerun the failed job. Code at fault: fix on `main`, delete the tag as above, release the next patch version rather than reusing the number. | +| *publish* (GitHub) or *release* (GitLab) fails | Rerun the failed job; the archives from *build* are reused. | | `GET /` still shows the old version on your machine | `poetry install --only-root`. | Never re-point or reuse a tag that has a published release. Release the next diff --git a/docs/setup.md b/docs/setup.md index 34d6772..6122b2e 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -128,12 +128,22 @@ poetry run mypy # types, [tool.mypy] in pyproject.toml poetry run pip-audit # known vulnerabilities in the installed dependencies ``` -CI (`.github/workflows/ci.yml`) runs all four in `lint` and the suite in `test` -against a `postgres:17` service, on every push to `main` and every pull -request. Dependabot (`.github/dependabot.yml`) opens weekly pull requests for -dependency and action updates, grouped by minor and patch; the same CI checks -them. It installs the Poetry version named in `poetry.lock`'s header and the -Python version in `.python-version`, so neither is pinned twice. +CI runs all four in `lint` and the suite in `test` against a `postgres:17` +service, on every push to `main` and every pull or merge request. Two +pipeline files cover the two hosts this starter is used on, and a repository +may carry both; each host ignores the other's file: + +- `.github/workflows/ci.yml` (GitHub Actions). Dependabot + (`.github/dependabot.yml`) opens weekly pull requests for dependency and + action updates, grouped by minor and patch; the same CI checks them. +- `.gitlab-ci.yml` (GitLab, including a self-hosted instance). Test results + appear in the merge request widget; a `v*` tag adds the release jobs (see + [Releasing](releasing.md)). + +Both install the Poetry version named in `poetry.lock`'s header and the Python +version in `.python-version`, so neither is pinned twice. The GitLab image tag +repeats the Python minor in `PYTHON_VERSION`, and the job fails if that ever +disagrees with `.python-version`. ## Adapting this starter @@ -145,8 +155,9 @@ Everything a new project renames or changes, in one list: 2. **Imports in tests**: the `from basic_api ...` lines at the top of `tests/conftest.py` and the test modules. 3. **CI**: the `env` block and the `postgres` matrix entry at the top of - `.github/workflows/ci.yml`; nothing in the jobs refers to the project by - name. + `.github/workflows/ci.yml`, or the `variables` block and the postgres + service tag in `.gitlab-ci.yml`; nothing in the jobs refers to the project + by name. Delete the file for the host you do not use, or keep both. 4. **Names shown to clients**: `title` and `description` in `main.py`, and `SERVICE_NAME` returned by `/health`. 5. **Configuration**: add a variable in `config.py` and `.env.example` together. From cebd686415513e1663dd5c971031d2a95b0df7a6 Mon Sep 17 00:00:00 2001 From: JsNcAr Date: Mon, 12 Oct 2026 11:02:36 -0500 Subject: [PATCH 2/2] feat(release): pipeline URL for GitHub and GitLab remotes After the push, the script prints where the release pipeline runs: /actions on github.com, /-/pipelines elsewhere, parsed from the three remote URL spellings (scp-like, ssh:// with a port, https). Tested. Co-Authored-By: Claude Fable 5.1 --- scripts/release.py | 47 +++++++++++++++++++++++++++--------- tests/test_release_script.py | 33 +++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 12 deletions(-) diff --git a/scripts/release.py b/scripts/release.py index 87cc6aa..60a233e 100644 --- a/scripts/release.py +++ b/scripts/release.py @@ -15,9 +15,10 @@ push nothing has left your machine; undo it with `git tag -d vX.Y.Z && git reset --hard HEAD~1`. -Pushing a `v*` tag starts `.github/workflows/release.yml`, which checks the tag -against `pyproject.toml`, runs the CI workflow, builds the wheel and sdist, and -publishes a GitHub release whose notes are this version's CHANGELOG.md section. +Pushing a `v*` tag starts the release pipeline (`.github/workflows/release.yml` +on GitHub, `.gitlab-ci.yml` on GitLab), which checks the tag against +`pyproject.toml`, runs lint and tests, builds the wheel and sdist, and publishes +a release whose notes are this version's CHANGELOG.md section. The starter is never released: `prepare` refuses while `[tool.release] starter = true` in pyproject.toml. A clone sets it to false once (see @@ -429,22 +430,44 @@ def cmd_prepare(args: argparse.Namespace) -> None: refresh_installed_metadata() push = ["push", "--atomic", REMOTE, branch, tag] - question = f"Push {branch} and {tag} to {REMOTE} (starts the release workflow)?" + question = f"Push {branch} and {tag} to {REMOTE} (starts the release pipeline)?" if args.no_push or not confirm(question, args.yes): print(f"Not pushed. When ready: git {' '.join(push)}") print(f"To undo instead: git tag -d {tag} && git reset --hard HEAD~1") return git(*push) - print( - "Pushed. The release workflow is running: " - f"https://github.com/{repo_slug()}/actions" - ) + print(f"Pushed. The release pipeline is running: {pipelines_url(remote_url())}") + + +def remote_url() -> str: + return git("remote", "get-url", REMOTE, check=False) + + +def pipelines_url(remote: str) -> str: + """ + Where the release pipeline shows up, from the remote URL. + Handles the three spellings git uses: `git@host:group/repo.git`, + `ssh://git@host:port/group/repo.git` and `https://host/group/repo.git`. + GitHub shows pipelines under /actions, GitLab under /-/pipelines. -def repo_slug() -> str: - url = git("remote", "get-url", REMOTE, check=False) - match = re.search(r"github\.com[:/](.+?)(?:\.git)?$", url) - return match.group(1) if match else "/" + Args: + remote: Output of `git remote get-url`. + + Returns: + A URL, or a short hint when the remote is not recognised. + """ + match = re.match( + r"^(?:[a-z+]+://)?(?:[^@/]+@)?(?P[^:/]+)(?::\d+)?" + r"[:/](?P.+?)(?:\.git)?/?$", + remote.strip(), + ) + if not match: + return "" + host, path = match["host"], match["path"] + if host == "github.com": + return f"https://{host}/{path}/actions" + return f"https://{host}/{path}/-/pipelines" def write_outputs(fh: TextIO, version: str) -> None: diff --git a/tests/test_release_script.py b/tests/test_release_script.py index 7d38107..463e909 100644 --- a/tests/test_release_script.py +++ b/tests/test_release_script.py @@ -118,6 +118,39 @@ def test_write_version_touches_only_the_project_version(): assert updated.replace('version = "0.2.0"', 'version = "0.1.0"', 1) == PYPROJECT +# -- remotes ------------------------------------------------------------------ + + +@pytest.mark.parametrize( + "remote, expected", + [ + ( + "git@github.com:JsNcAr/basic_api.git", + "https://github.com/JsNcAr/basic_api/actions", + ), + ( + "https://github.com/JsNcAr/basic_api", + "https://github.com/JsNcAr/basic_api/actions", + ), + ( + "ssh://git@gitlab.example.net:2222/group/sub/repo.git", + "https://gitlab.example.net/group/sub/repo/-/pipelines", + ), + ( + "git@gitlab.example.net:group/repo.git", + "https://gitlab.example.net/group/repo/-/pipelines", + ), + ( + "https://gitlab.example.net/group/repo.git", + "https://gitlab.example.net/group/repo/-/pipelines", + ), + ("", ""), + ], +) +def test_pipelines_url_handles_github_and_gitlab_remotes(remote, expected): + assert release.pipelines_url(remote) == expected + + # -- changelog ----------------------------------------------------------------