Skip to content

Commit f9688e2

Browse files
committed
build: improve docker cache by copying VERSION later
1 parent 05750f0 commit f9688e2

File tree

7 files changed

+131
-132
lines changed

7 files changed

+131
-132
lines changed

.cz.toml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
2+
[tool.commitizen]
3+
version = "0.18.5"
4+
version_files = [
5+
"VERSION",
6+
]
7+
name = "cz_customize"
8+
tag_format = "v$version"
9+
10+
[tool.commitizen.customize]
11+
message_template = "{{prefix}}{% if scope %}({{scope}}){% endif %}: {{subject}}{% if body %}\n\n{{body}}{% endif %}{% if is_breaking_change %}\n\nBREAKING CHANGE: {{footer}}{% else %}\n\n{{footer}}{% endif %}"
12+
13+
bump_pattern = "^(BREAKING[\\-\\ ]CHANGE|feat|fix|refactor|perf|ci|docs|style|test|chore|revert|build)(\\(.+\\))?(!)?"
14+
change_type_order = [
15+
"BREAKING CHANGE",
16+
"Feat",
17+
"Fix",
18+
"Refactor",
19+
"Perf",
20+
"CI",
21+
"Docs",
22+
"Technical",
23+
"Tests",
24+
]
25+
bump_message = "bump: version $current_version → $new_version"
26+
schema = "<type>(<scope>): <subject>\n<BLANK LINE>\n<body>\n<BLANK LINE>\n(BREAKING CHANGE: )<footer>"
27+
schema_pattern = "(?s)(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert|bump)(\\(\\S+\\))?!?:( [^\\n\\r]+)((\\n\\n.*)|(\\s*))?$"
28+
commit_parser = "^(?P<change_type>feat|fix|refactor|perf|BREAKING CHANGE|ci|docs|style|test|chore|revert|build)(?:\\((?P<scope>[^()\\r\\n]*)\\)|\\()?(?P<breaking>!)?:\\s(?P<message>.*)?"
29+
version_parser = "(?P<version>([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+[0-9A-Za-z-]+)?(\\w+)?)"
30+
changelog_pattern = "^(BREAKING[\\-\\ ]CHANGE|feat|fix|refactor|perf|ci|docs|style|test|chore|revert|build)(\\(.+\\))?(!)?" # same as bump_pattern
31+
[tool.commitizen.customize.bump_map]
32+
"^.+!$" = "MAJOR"
33+
"^BREAKING[\\-\\ ]CHANGE" = "MAJOR"
34+
"^feat" = "MINOR"
35+
"^fix" = "PATCH"
36+
"^refactor" = "PATCH"
37+
"^perf" = "PATCH"
38+
"^ci" = "PATCH"
39+
"^docs" = "PATCH"
40+
"^style" = "PATCH"
41+
"^test" = "PATCH"
42+
"^chore" = "PATCH"
43+
"^revert" = "PATCH"
44+
"^build" = "PATCH"
45+
46+
[tool.commitizen.customize.change_type_map]
47+
"feat" = "Feat"
48+
"fix" = "Fix"
49+
"refactor" = "Refactor"
50+
"perf" = "Perf"
51+
"ci" = "CI"
52+
"docs" = "Docs"
53+
"style" = "Technical"
54+
"test" = "Tests"
55+
"chore" = "Technical"
56+
"revert" = "Fix"
57+
"build" = "Technical"
58+
59+
[[tool.commitizen.customize.questions]]
60+
type = "list"
61+
name = "prefix"
62+
message = "Select the type of change you are committing"
63+
choices = [
64+
{ value = "fix", name = "fix: A bug fix. Correlates with PATCH in SemVer", key = "x" },
65+
{ value = "feat", name = "feat: A new feature. Correlates with MINOR in SemVer", key = "f" },
66+
{ value = "docs", name = "docs: Documentation only changes", key = "d" },
67+
{ value = "style", name = "style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)", key = "s" },
68+
{ value = "refactor", name = "refactor: A code change that neither fixes a bug nor adds a feature", key = "r" },
69+
{ value = "perf", name = "perf: A code change that improves performance", key = "p" },
70+
{ value = "test", name = "test: Adding missing or correcting existing tests", key = "t" },
71+
{ value = "build", name = "build: Changes that affect the build system or external dependencies (example scopes: pip, docker, npm)", key = "b" },
72+
{ value = "ci", name = "ci: Changes to our CI configuration files and scripts (example scopes: GitLabCI)", key = "c" },
73+
]
74+
75+
[[tool.commitizen.customize.questions]]
76+
type = "input"
77+
name = "scope"
78+
message = "What is the scope of this change? ((story number, class or file name): (press [enter] to skip)\n"
79+
80+
[[tool.commitizen.customize.questions]]
81+
type = "input"
82+
name = "subject"
83+
message = "Write a short and imperative summary of the code changes: (lower case and no period)\n"
84+
85+
[[tool.commitizen.customize.questions]]
86+
type = "input"
87+
name = "body"
88+
message = "Provide additional contextual information about the code changes: (press [enter] to skip)\n"
89+
90+
[[tool.commitizen.customize.questions]]
91+
type = "confirm"
92+
message = "Is this a BREAKING CHANGE? Correlates with MAJOR in SemVer"
93+
name = "is_breaking_change"
94+
default = false
95+
96+
[[tool.commitizen.customize.questions]]
97+
type = "input"
98+
name = "footer"
99+
message = "Footer. Information about Breaking Changes and reference issues that this commit closes: (press [enter] to skip)\n"

.github/workflows/bumpversion.yml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,8 @@ jobs:
3333
name: Create bump and changelog
3434
run: |
3535
cz bump --yes --changelog
36-
echo "version=$(cz version)" >> $GITHUB_OUTPUT
36+
git push origin HEAD:main
37+
git push origin --tags
3738
3839
- name: Print Version
39-
run: echo "Bumped to version ${{ steps.cz.outputs.version }}"
40-
41-
- name: Install uv
42-
uses: astral-sh/setup-uv@7edac99f961f18b581bbd960d59d049f04c0002f # v6.4.1
43-
44-
- name: Update uv.lock with the latest project version
45-
run: |
46-
uv lock --upgrade-package lightman_ai
47-
git add uv.lock
48-
git commit --amend --no-edit
49-
git push origin HEAD
50-
git push origin --tags
40+
run: echo "Bumped to version $(cz version -p)"

.github/workflows/publish.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,13 @@ jobs:
9191
echo "Deleting old cache version ID: $id"
9292
gh api -X DELETE "orgs/elementsinteractive/packages/container/lightman-ai/versions/$id"
9393
done
94+
release_notes:
95+
runs-on: ubuntu-latest
96+
needs: [push_to_pypi, push_to_docker_hub]
97+
steps:
98+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
99+
- name: Release
100+
uses: softprops/action-gh-release@72f2c25fcb47643c292f7107632f7a47c1df5cd8 #v2.3.2
101+
with:
102+
generate_release_notes: true
103+
token: "${{ secrets.GITHUB_TOKEN }}"

Dockerfile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,32 @@ ENV PATH="/root/.local/bin/:$PATH"
3737
# Copy dependency files
3838
COPY uv.lock pyproject.toml ./
3939

40+
# Create a fake VERSION file, so that we don't break the cache because of a mismatch in that file
41+
RUN echo "v0.0.0" > VERSION
42+
4043
# Install dependencies using uv (only dependencies, not the project itself)
4144
RUN UV_PROJECT_ENVIRONMENT=${VENV_PATH} uv sync --frozen --no-install-project --compile-bytecode
4245
RUN ${BIN_PATH}/python -m ensurepip
4346
# --------------- `final` stage ---------------
4447
FROM base AS final
4548

46-
# Set non-root user and group
47-
USER ${USER}:${GROUP}
48-
4949
# Copy the virtual environment from build stage
5050
COPY --from=build --chown=${USER}:${GROUP} ${VENV_PATH} ${VENV_PATH}
5151

5252
# Set PATH to use the virtual environment
5353
ENV PATH="${BIN_PATH}:$PATH"
5454

55-
# Copy pyproject.toml for package metadata
55+
# Copy needed files to install the package
5656
COPY --from=build --chown=${USER}:${GROUP} ${WORKDIR}/pyproject.toml .
57+
COPY --chown=${USER}:${GROUP} README.md README.md
58+
COPY --chown=${USER}:${GROUP} src src
5759

58-
COPY README.md README.md
59-
# Copy source code
60-
COPY src src
60+
# Copy the real VERSION file
61+
COPY --chown=${USER}:${GROUP} VERSION .
6162

62-
# Install the CLI tool (dependencies already installed in venv)
63+
# Install the CLI tool (dependencies already installed in venv)
6364
RUN ${BIN_PATH}/pip3 install --no-deps .
6465

66+
USER ${USER}:${GROUP}
67+
6568
ENTRYPOINT [ "lightman-ai" ]

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v0.18.5

pyproject.toml

Lines changed: 7 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ dependencies = [
1717
"sentry-sdk>=2.21.0,<3.0.0",
1818
]
1919
name = "lightman_ai"
20-
version = "0.18.5"
2120
description = "Cybersecurity news aggregator."
2221
readme = "README.md"
22+
dynamic = ["version"]
2323

2424
[project.scripts]
2525
lightman-ai = "lightman_ai.cli:entry_point"
2626

27+
2728
[project.optional-dependencies]
2829
test = [
2930
"pytest<9.0.0,>=8.0.0",
@@ -44,8 +45,11 @@ local = [
4445

4546

4647
[build-system]
47-
requires = ["pdm-backend"]
48-
build-backend = "pdm.backend"
48+
requires = ["setuptools>=61.0"]
49+
build-backend = "setuptools.build_meta"
50+
51+
[tool.setuptools.dynamic]
52+
version = {file = "VERSION"}
4953

5054
[tool.pytest.ini_options]
5155
addopts = """
@@ -142,110 +146,3 @@ exclude_lines = [
142146
"pragma: no cover",
143147
"raise NotImplementedError",
144148
]
145-
146-
147-
[tool.commitizen]
148-
version_files = ["pyproject.toml:^version"]
149-
name = "cz_customize"
150-
version = "0.18.5"
151-
tag_format = "v$version"
152-
153-
[tool.commitizen.customize]
154-
message_template = "{{prefix}}{% if scope %}({{scope}}){% endif %}: {{subject}}{% if body %}\n\n{{body}}{% endif %}{% if is_breaking_change %}\n\nBREAKING CHANGE: {{footer}}{% else %}\n\n{{footer}}{% endif %}"
155-
156-
bump_pattern = "^(BREAKING[\\-\\ ]CHANGE|feat|fix|refactor|perf|ci|docs|style|test|chore|revert|build)(\\(.+\\))?(!)?"
157-
change_type_order = [
158-
"BREAKING CHANGE",
159-
"Feat",
160-
"Fix",
161-
"Refactor",
162-
"Perf",
163-
"CI",
164-
"Docs",
165-
"Technical",
166-
"Tests",
167-
]
168-
bump_message = "bump: version $current_version → $new_version"
169-
schema = "<type>(<scope>): <subject>\n<BLANK LINE>\n<body>\n<BLANK LINE>\n(BREAKING CHANGE: )<footer>"
170-
schema_pattern = "(?s)(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert|bump)(\\(\\S+\\))?!?:( [^\\n\\r]+)((\\n\\n.*)|(\\s*))?$"
171-
commit_parser = "^(?P<change_type>feat|fix|refactor|perf|BREAKING CHANGE|ci|docs|style|test|chore|revert|build)(?:\\((?P<scope>[^()\\r\\n]*)\\)|\\()?(?P<breaking>!)?:\\s(?P<message>.*)?"
172-
version_parser = "(?P<version>([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+[0-9A-Za-z-]+)?(\\w+)?)"
173-
changelog_pattern = "^(BREAKING[\\-\\ ]CHANGE|feat|fix|refactor|perf|ci|docs|style|test|chore|revert|build)(\\(.+\\))?(!)?" # same as bump_pattern
174-
[tool.commitizen.customize.bump_map]
175-
"^.+!$" = "MAJOR"
176-
"^BREAKING[\\-\\ ]CHANGE" = "MAJOR"
177-
"^feat" = "MINOR"
178-
"^fix" = "PATCH"
179-
"^refactor" = "PATCH"
180-
"^perf" = "PATCH"
181-
"^ci" = "PATCH"
182-
"^docs" = "PATCH"
183-
"^style" = "PATCH"
184-
"^test" = "PATCH"
185-
"^chore" = "PATCH"
186-
"^revert" = "PATCH"
187-
"^build" = "PATCH"
188-
189-
[tool.commitizen.customize.change_type_map]
190-
"feat" = "Feat"
191-
"fix" = "Fix"
192-
"refactor" = "Refactor"
193-
"perf" = "Perf"
194-
"ci" = "CI"
195-
"docs" = "Docs"
196-
"style" = "Technical"
197-
"test" = "Tests"
198-
"chore" = "Technical"
199-
"revert" = "Fix"
200-
"build" = "Technical"
201-
202-
[[tool.commitizen.customize.questions]]
203-
type = "list"
204-
name = "prefix"
205-
message = "Select the type of change you are committing"
206-
choices = [
207-
{ value = "fix", name = "fix: A bug fix. Correlates with PATCH in SemVer", key = "x" },
208-
{ value = "feat", name = "feat: A new feature. Correlates with MINOR in SemVer", key = "f" },
209-
{ value = "docs", name = "docs: Documentation only changes", key = "d" },
210-
{ value = "style", name = "style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)", key = "s" },
211-
{ value = "refactor", name = "refactor: A code change that neither fixes a bug nor adds a feature", key = "r" },
212-
{ value = "perf", name = "perf: A code change that improves performance", key = "p" },
213-
{ value = "test", name = "test: Adding missing or correcting existing tests", key = "t" },
214-
{ value = "build", name = "build: Changes that affect the build system or external dependencies (example scopes: pip, docker, npm)", key = "b" },
215-
{ value = "ci", name = "ci: Changes to our CI configuration files and scripts (example scopes: GitLabCI)", key = "c" },
216-
]
217-
218-
[[tool.commitizen.customize.questions]]
219-
type = "input"
220-
name = "scope"
221-
message = "What is the scope of this change? ((story number, class or file name): (press [enter] to skip)\n"
222-
223-
[[tool.commitizen.customize.questions]]
224-
type = "input"
225-
name = "subject"
226-
message = "Write a short and imperative summary of the code changes: (lower case and no period)\n"
227-
228-
[[tool.commitizen.customize.questions]]
229-
type = "input"
230-
name = "body"
231-
message = "Provide additional contextual information about the code changes: (press [enter] to skip)\n"
232-
233-
[[tool.commitizen.customize.questions]]
234-
type = "confirm"
235-
message = "Is this a BREAKING CHANGE? Correlates with MAJOR in SemVer"
236-
name = "is_breaking_change"
237-
default = false
238-
239-
[[tool.commitizen.customize.questions]]
240-
type = "input"
241-
name = "footer"
242-
message = "Footer. Information about Breaking Changes and reference issues that this commit closes: (press [enter] to skip)\n"
243-
244-
# TODO: Find a way to include pyproject.toml without the version changes
245-
[tool.cruft]
246-
skip = ["pyproject.toml"]
247-
248-
249-
[[IgnoredVulns]]
250-
# False positive for mkdocs, more info: https://github.com/mkdocs/mkdocs/issues/2601
251-
id = "PYSEC-2021-878"

uv.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)