-
Notifications
You must be signed in to change notification settings - Fork 6
GitHub Action and GitLab CI/CD Component #232
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
Open
gronke
wants to merge
7
commits into
collective:master
Choose a base branch
from
gronke:feat/setup-zpretty-action
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2509d21
feat: add a composite action to set up zpretty
gronke 49ad700
feat: add a GitLab CI template for zpretty
gronke 39b2fe0
docs: document the GitHub Action and GitLab CI/CD component
gronke 913d6d2
ci: install zpretty with a single python -m pip call in both runners
gronke aeda4f6
docs: pin the CI examples to the upcoming release
gronke 4479a97
test: guard the README CI examples against version drift
gronke eedf02e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| 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 | ||
| with: | ||
| python-version: ${{ inputs.python-version }} | ||
|
|
||
| - name: Install zpretty | ||
| shell: bash | ||
| run: python -m pip install "${{ inputs.spec }}" | ||
|
|
||
| - name: Report zpretty version | ||
| shell: bash | ||
| run: zpretty --version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
| - 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: | ||
| - python -m pip install "$ZPRETTY_SPEC" | ||
| - zpretty --version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| from zpretty.tests.mock import MockCLIRunner | ||
|
|
||
| import argparse | ||
| import re | ||
|
|
||
|
|
||
| class TestReadme(TestCase): | ||
|
|
@@ -36,3 +37,32 @@ def test_readme(self): | |
| observed = self.extract_usage_from_readme() | ||
| expected = self.extract_usage_from_parser() | ||
| self.assertListEqual(observed, expected) | ||
|
|
||
| def extract_pinned_versions_from_readme(self): | ||
| """Extract the versions pinned in the CI examples""" | ||
| readme_path = files("zpretty").parent / "README.md" | ||
| readme = readme_path.read_text() | ||
| github = re.search(r"collective/zpretty/\.github/actions/zpretty@(\S+)", readme) | ||
| gitlab = re.search( | ||
| r"collective/zpretty/([^/\s]+)/gitlab/zpretty\.gitlab-ci\.yml", readme | ||
| ) | ||
| return github.group(1), gitlab.group(1) | ||
|
|
||
| def extract_versions_from_history(self): | ||
| """Return the topmost and the latest released version from HISTORY.md""" | ||
| history_path = files("zpretty").parent / "HISTORY.md" | ||
| entries = re.findall( | ||
| r"^## (\d\S*) \(([^)]+)\)", history_path.read_text(), re.MULTILINE | ||
| ) | ||
| released = [version for version, date in entries if date != "unreleased"] | ||
| return entries[0][0], released[0] | ||
|
|
||
| def test_ci_examples_pin_a_current_release(self): | ||
| """Both CI examples must pin the same version, and it must be the | ||
| latest released or the upcoming one, so the README cannot silently | ||
| fall a release behind. | ||
| """ | ||
| github, gitlab = self.extract_pinned_versions_from_readme() | ||
| self.assertEqual(github, gitlab) | ||
| topmost, latest_released = self.extract_versions_from_history() | ||
| self.assertIn(github, (topmost, latest_released)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this test is a pain to keep it running and not very comprehensive. |
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
.