Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
33 changes: 33 additions & 0 deletions .github/actions/zpretty/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Set up zpretty
description: >
Install zpretty so a workflow can run it (for example `zpretty --check`).

inputs:
spec:
description: >
pip requirement specifier for zpretty: a release such as
"zpretty==4.0.2", a VCS URL, or "." to install the checked-out source.
required: false
default: zpretty
python-version:
description: Python version to set up.
required: false
default: "3.x"

runs:
using: composite
steps:
- name: Set up Python
uses: actions/setup-python@v6
Comment thread
ale-rt marked this conversation as resolved.
with:
python-version: ${{ inputs.python-version }}

- name: Install zpretty
shell: bash
run: |
python -m pip install --upgrade pip
python -m pip install "${{ inputs.spec }}"

- name: Report zpretty version
shell: bash
run: zpretty --version
22 changes: 22 additions & 0 deletions .github/workflows/zpretty-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: zpretty action

on: [push, pull_request]

permissions:
contents: read

jobs:
self-test:
name: Set up zpretty from source and run it
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
Comment thread
ale-rt marked this conversation as resolved.

- name: Set up zpretty from this checkout
uses: ./.github/actions/zpretty
with:
spec: .

- name: Smoke-test the installed zpretty
shell: bash
run: zpretty --check zpretty/tests/original/sample_xml.xml
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
@ale-rt
- Fix possible issue with whitespaces lost around comments in XML documents.
@ale-rt
- Add a reusable GitHub Action and GitLab CI/CD component to set up
`zpretty` in CI pipelines.
(#232)
@gronke


## 4.0.2 (2026-06-09)
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
global-exclude *.pyc __pycache__ pyvenv.cfg
graft zpretty
graft zpretty/tests/include-excludes/.git
recursive-include gitlab *.yml
include *.cfg *.txt *.md *.in LICENSE Makefile .pre-commit-config.yaml .pre-commit-hooks.yaml tox.ini pyproject.toml
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,43 @@ To do so, add the following to your `.pre-commit-config.yaml`:
- id: zpretty
```

# Continuous integration

## GitHub Actions

This repository ships a composite action that installs `zpretty` so a
workflow can run it:

```yaml
- uses: actions/checkout@v6
- uses: collective/zpretty/.github/actions/zpretty@master
- run: zpretty --check path/to/file.xml
Comment on lines +153 to +155

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The change of line 147 is wrong.
I agree about the use of <ref> but that should be explained.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Indeed v6 is the latest Action. One could think that Microsoft trains their models on the docs of their own services 🤔

The benefit of pointing at the default branch @master is that users can just copy-paste and use it. Otherwise one would need to remember what the default branch was called.

@ale-rt think we should change to @<ref>?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you look e.g. at https://github.com/actions/checkout#fetch-only-the-root-files they are pointing to a version.
This of course means that once the version is upgraded the docs should be upgraded as well.

Using <ref> and adding to the docs a note about that might be the mvp.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ah, I see. You mean to pin the currently latest version in the readme, not <rev>. Makes sense to pin a version, so that linting behavior does not change unexpectedly across repeated builds.

Want to add a drift test for the readme?

```

The action takes two optional inputs: `spec`, a pip requirement specifier
(a release such as `zpretty==4.0.2`, a VCS URL, or `.` to install the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I do not see the reason of checking out a zpretty and then using a spec different from .

checked-out source; defaults to `zpretty`), and `python-version`
(defaults to `3.x`).

## GitLab CI/CD

For GitLab there is a reusable CI/CD configuration. Include it and extend
the `.zpretty` job it defines:

```yaml
include:
- remote: "https://raw.githubusercontent.com/collective/zpretty/master/gitlab/zpretty.gitlab-ci.yml"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree about the use of but that should be explained.


zpretty:
extends: .zpretty
script:
- zpretty --check path/to/file.xml
```

Set the `ZPRETTY_SPEC` variable (default `zpretty`) to change the pip
specifier and `ZPRETTY_PYTHON_VERSION` (default `3`) to pick the Python
image tag.

# VSCode extension

There is a VSCode extension that uses `zpretty`:
Expand Down
15 changes: 15 additions & 0 deletions gitlab/zpretty.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Reusable zpretty setup for GitLab CI. Usage:
# include:
# - remote: "https://raw.githubusercontent.com/collective/zpretty/<ref>/gitlab/zpretty.gitlab-ci.yml"
# zpretty:
# extends: .zpretty
# variables: { ZPRETTY_SPEC: "zpretty==4.0.2" } # optional
# script: [zpretty --check path/to/file.xml]
.zpretty:
image: "python:$ZPRETTY_PYTHON_VERSION"
variables:
ZPRETTY_PYTHON_VERSION: "3"
ZPRETTY_SPEC: zpretty
before_script:
- pip install "$ZPRETTY_SPEC"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The GH action looks like:

        python -m pip install --upgrade pip
        python -m pip install "${{ inputs.spec }}"

Maybe we should have the same here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

As mentioned on the Action, I am leaning to remove the pip upgrade, unless you prefer to upgrade it here as well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have no hard preference.

- zpretty --version
Comment on lines +13 to +15

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am +0 on this

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The Python environment should need to bother us here, because if Pip fails installing zpretty, it probably also fails upgrading itself.

Loading