Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-client-android
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-client-android
Commits
1a767e9d
Commit
1a767e9d
authored
3 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
build: add tool to update version
Change-Id: I886ad7faf5de3c6781cbdfef0bffe83f3c9d1630
parent
c3b35499
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
update_version.py
+62
-0
62 additions, 0 deletions
update_version.py
with
62 additions
and
0 deletions
update_version.py
0 → 100755
+
62
−
0
View file @
1a767e9d
#!python3
import
re
import
datetime
PATTERN_CODE
=
re
.
compile
(
r
'
^(\s*versionCode\s*=\s*)(\d+)$
'
,
re
.
MULTILINE
)
PATTERN_NAME
=
re
.
compile
(
r
'
^(\s*versionName\s*=\s*)
"
(\w+)(?:-(\d+))?
"
\s*$
'
,
re
.
MULTILINE
)
def
get_new_code
(
old_code
):
return
int
(
old_code
)
+
1
def
get_new_name
(
name_base
,
name_serial_str
):
new_name_base
=
datetime
.
date
.
today
().
strftime
(
"
%Y%m%d
"
)
name_serial
=
int
(
name_serial_str
)
if
name_serial_str
else
0
new_name_serial
=
name_serial
+
1
if
name_base
==
new_name_base
else
1
return
f
"
{
new_name_base
}
-
{
new_name_serial
:
02
}
"
def
update_version
(
path
,
new_code
=
None
,
new_name
=
None
):
with
open
(
path
,
'
r
'
)
as
f
:
content
=
f
.
read
()
if
not
new_code
:
new_code
=
get_new_code
(
PATTERN_CODE
.
search
(
content
).
group
(
2
))
if
not
new_name
:
name_match
=
PATTERN_NAME
.
search
(
content
)
new_name
=
get_new_name
(
name_match
.
group
(
2
),
name_match
.
group
(
3
))
content
=
PATTERN_CODE
.
sub
(
rf
'
\g<1>
{
new_code
}
'
,
content
)
content
=
PATTERN_NAME
.
sub
(
rf
'
\g<1>
"
{
new_name
}
"'
,
content
)
with
open
(
path
,
'
w
'
)
as
f
:
f
.
write
(
content
)
return
(
new_code
,
new_name
)
def
commit
(
path
,
new_code
,
new_name
):
import
subprocess
subprocess
.
Popen
([
'
git
'
,
'
add
'
,
path
],
stdout
=
subprocess
.
PIPE
).
communicate
()
subprocess
.
Popen
([
'
git
'
,
'
commit
'
,
'
-m
'
,
f
'
update version to
{
new_name
}
(
{
new_code
}
)
'
],
stdout
=
subprocess
.
PIPE
).
communicate
()
if
__name__
==
'
__main__
'
:
import
argparse
,
json
,
sys
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'
--version-name
'
)
parser
.
add_argument
(
'
--version-code
'
,
type
=
int
)
parser
.
add_argument
(
'
--path
'
,
default
=
'
ring-android/app/build.gradle.kts
'
)
parser
.
add_argument
(
'
--commit
'
,
action
=
'
store_true
'
)
args
=
parser
.
parse_args
()
new_code
,
new_name
=
update_version
(
args
.
path
,
args
.
version_code
,
args
.
version_name
)
json
.
dump
({
'
name
'
:
new_name
,
'
code
'
:
new_code
},
sys
.
stdout
)
print
()
if
args
.
commit
:
commit
(
args
.
path
,
new_code
,
new_name
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment