Skip to content

Commit fdbcf32

Browse files
author
Igor Stepin
committed
Switch to Kotlin
1 parent 0a46355 commit fdbcf32

29 files changed

+786
-1217
lines changed

.editorconfig

+6-8
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ insert_final_newline = true
1010
trim_trailing_whitespace = true
1111
charset = utf-8
1212

13-
# 4 space indentation
14-
[*.{py,java,r,R}]
15-
indent_style = space
16-
indent_size = 4
13+
[{*.kt,*.kts}]
14+
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
1715

18-
# 2 space indentation
19-
[*.{js,json,y{a,}ml,html,cwl}]
20-
indent_style = space
21-
indent_size = 2
16+
# Disable wildcard imports entirely
17+
ij_kotlin_name_count_to_use_star_import = 2147483647
18+
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
19+
ij_kotlin_packages_to_use_import_on_demand = unset
2220

2321
[*.{md,Rmd,rst}]
2422
trim_trailing_whitespace = false

.github/workflows/main.yml

-30
This file was deleted.

.gitignore

-21
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
*.py[cod]
2-
*.egg-info
3-
*.eggs
4-
5-
dist
6-
.cache
7-
8-
htmlcov
9-
.coverage
10-
coverage.xml
11-
.pytest_cache
12-
13-
docs/_build
14-
docs/apidocs
15-
161
# ide
172
.idea
183
.eclipse
@@ -21,12 +6,6 @@ docs/apidocs
216
# Mac
227
.DS_Store
238

24-
# virtual environments
25-
env
26-
env3
27-
venv
28-
venv3
29-
309
/tests/repo
3110
/tests/repo2
3211
/tests/repo3

Dockerfile

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
#NOTE: jc requires gcc and there is no package for alpine, that's why it's not alpine base image
2-
FROM python:3
1+
FROM stepin/kotlin-scripting
32

4-
RUN pip3 install jc \
5-
&& apt-get update \
6-
&& apt-get install -y jq \
7-
&& rm -rf /var/lib/apt/lists/* \
8-
&& mkdir /app
3+
RUN apt-get update \
4+
&& apt-get -y install jc git \
5+
&& rm -rf /var/lib/apt/lists/*
96

10-
WORKDIR /app
11-
ENV PATH="${PATH}:/app"
7+
COPY git-parse-commits.main.kts ./
128

13-
COPY git-parse-commits ./
9+
# Cache dependencies and compilation result for better start-up speed
10+
ENV KOTLIN_MAIN_KTS_COMPILED_SCRIPTS_CACHE_DIR /app
11+
RUN /app/git-parse-commits.main.kts version
1412

15-
ENTRYPOINT ["/app/git-parse-commits"]
13+
ENTRYPOINT ["/app/git-parse-commits.main.kts"]

README.md

+29-31
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Docker image: [stepin/git-parse-commits:latest](https://hub.docker.com/r/stepin/
99
Example how to use with Docker:
1010

1111
```shell
12-
docker run --rm -it -v "$(PWD):/git" -w /git --user "$(id -u)" stepin/git-parse-commits:1.0.2 releaseVersion
13-
docker run --rm -it -v "$(PWD):/git" -w /git --user "$(id -u)" stepin/git-parse-commits:1.0.2 releaseNotes
12+
docker run --rm -it -v "$(PWD):/git" -w /git --user "$(id -u)" stepin/git-parse-commits:2.0.0 releaseVersion
13+
docker run --rm -it -v "$(PWD):/git" -w /git --user "$(id -u)" stepin/git-parse-commits:2.0.0 releaseNotes
1414
```
1515

1616
Example usage for Gitlab:
@@ -19,7 +19,7 @@ Example usage for Gitlab:
1919
create_changelog:
2020
stage: "build"
2121
image:
22-
name: "stepin/git-parse-commits:1.0.2"
22+
name: "stepin/git-parse-commits:2.0.0"
2323
entrypoint: [""]
2424
variables:
2525
GIT_DEPTH: "0"
@@ -75,31 +75,25 @@ release:
7575
```
7676
docker run --rm -it stepin/git-parse-commits --help
7777

78-
usage: git-parse-commits [-h] [-j] [-t [TAG_PREFIX]] [-s [SCOPE]] [-i [INITIAL_REVISION]] [-l [LAST_REVISION]] [--tag]
79-
{version,currentVersion,lastReleaseVersion,releaseVersion,releaseNotes} ...
80-
81-
Provides next release version and release notes from git commit messages.
82-
83-
positional arguments:
84-
{version,currentVersion,lastReleaseVersion,releaseVersion,releaseNotes}
85-
version Prints version of this tool
86-
currentVersion Prints current version (useful for non-release builds)
87-
lastReleaseVersion Prints version of last release
88-
releaseVersion Prints version of next release from git commit messages
89-
releaseNotes Prints release notes from git commit messages
90-
91-
options:
92-
-h, --help show this help message and exit
93-
-j, --json Output in json format
94-
-t [TAG_PREFIX], --tag-prefix [TAG_PREFIX]
95-
prefix for tags (optional)
96-
-s [SCOPE], --scope [SCOPE]
97-
scope to filter release note items
98-
-i [INITIAL_REVISION], --initial-revision [INITIAL_REVISION]
99-
start range from next revision
100-
-l [LAST_REVISION], --last-revision [LAST_REVISION]
101-
stop on this revision
102-
--tag add tag prefix to version (only if tag prefix is defined)
78+
Usage: git-parse-commits [<options>] <command> [<args>]...
79+
80+
Provides next release version and release notes from git commit messages.
81+
82+
Options:
83+
-j, --json output in json format
84+
-t, --tag-prefix=<text> prefix for tags (optional)
85+
--tag add tag prefix to versions (only if tag prefix is defined)
86+
-s, --scope=<text> scope to filter release note items
87+
-i, --initial-revision=<text> start range from next revision
88+
-l, --last-revision=<text> stop on this revision
89+
-h, --help Show this message and exit
90+
91+
Commands:
92+
version Prints version of this tool
93+
currentVersion Prints current version (useful for non-release builds)
94+
lastReleaseVersion Prints version of last release
95+
releaseVersion Prints version of next release from git commit messages
96+
releaseNotes Prints release notes from git commit messages
10397
```
10498
10599
@@ -240,13 +234,17 @@ Feel free to send MRs/patches.
240234

241235
Following components should be installed locally (or in Docker):
242236

243-
- Python 3
237+
- Kotlin
244238
- git
245239
- bash
246240
- jq https://jqlang.github.io/jq/
247241
- jc https://github.com/kellyjonbrazil/jc
248242

249243
```bash
250-
brew install jq jc
251-
poetry install
244+
brew install jq jc kotlin
252245
```
246+
247+
Currently, it's not possible to split single script to several files. So, it will be when it will
248+
be possible (like around Kotlin 2.0.20).
249+
250+
Also, it's not clear how to write unit tests for this script. Ping me if you know some example / article.

bin/build

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
set -eEuo pipefail
3+
cd "$(dirname "$0")"
4+
5+
cd ..
6+
7+
VERSION=$(git describe --tags --always)
8+
IMAGE_LATEST="stepin/git-parse-commits"
9+
IMAGE="$IMAGE_LATEST:$VERSION"
10+
11+
docker build . -t "$IMAGE" -t "$IMAGE_LATEST"

bin/klint

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
set -eEuo pipefail
3+
cd "$(dirname "$0")"
4+
5+
cd ..
6+
7+
ktlint --format git-parse-commits.main.kts

bin/publish

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ VERSION=$(git describe --tags --always)
88
IMAGE_LATEST="stepin/git-parse-commits"
99
IMAGE="$IMAGE_LATEST:$VERSION"
1010

11-
cp git-parse-commits git-parse-commits.orig
12-
sed "s/SNAPSHOT/$VERSION/g" git-parse-commits.orig > git-parse-commits
11+
cp git-parse-commits.main.kts git-parse-commits.main.kts.orig
12+
sed "s/SNAPSHOT/$VERSION/g" git-parse-commits.main.kts.orig > git-parse-commits.main.kts
1313

1414
docker buildx create --use
1515
docker buildx build --push --platform linux/amd64,linux/arm64 . -t "$IMAGE" -t "$IMAGE_LATEST"

bin/pylint

-9
This file was deleted.

0 commit comments

Comments
 (0)