Skip to content

Commit 5f481a0

Browse files
authoredApr 6, 2022
[All] Add a script to update all sample Compose versions (#773)
* Add a script that can change the Compose version in Dependencies.kt * Add support for build.gradle * Support compose snapshots in JetNews * Added better error handling to script
1 parent f96ac51 commit 5f481a0

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
 

‎JetNews/build.gradle

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
buildscript {
1818
ext.kotlin_version = '1.6.10'
1919
ext.compose_version = '1.2.0-alpha06'
20+
ext.compose_snapshot_version = ''
2021
ext.coroutines_version = '1.6.0'
2122
ext.accompanist_version = '0.24.4-alpha'
2223

@@ -39,6 +40,11 @@ subprojects {
3940
repositories {
4041
google()
4142
mavenCentral()
43+
44+
if (!compose_snapshot_version.isEmpty()) {
45+
maven { url "https://androidx.dev/snapshots/builds/" +
46+
"${compose_snapshot_version}/artifacts/repository/" }
47+
}
4248
}
4349

4450
apply plugin: 'com.diffplug.spotless'

‎scripts/upgrade_samples.sh

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/bin/bash
2+
3+
# Copyright (C) 2022 The Android Open Source Project
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
########################################################################
18+
#
19+
# Changes all samples to a new Compose version
20+
#
21+
# Example: To run
22+
# ./scripts/upgrade_samples.sh
23+
#
24+
########################################################################
25+
26+
set -e
27+
28+
# Check for clean git status
29+
if [[ `git status --porcelain` ]]; then
30+
read -r -p "You have uncommited git changes. Are you sure you want to continue? [y/N] " response
31+
if [[ "$response" =~ ^([nN])$ ]]; then
32+
exit 0;
33+
fi
34+
fi
35+
36+
echo "Version to change Compose to (e.g 1.2.0-alpha06): ";
37+
read compose_version;
38+
39+
echo "Snapshot ID: (Blank for none)";
40+
read snapshot_version;
41+
42+
if [ -z "$snapshot_version" ]; then
43+
echo "Changing Compose version to $compose_version"
44+
else
45+
echo "Changing Compose version to $compose_version Snapshot $snapshot_version"
46+
fi
47+
48+
# Change Dependencies.kt versions
49+
for DEPENDENCIES_FILE in `find . -type f -iname "dependencies.kt"` ; do
50+
COMPOSE_BLOCK=false;
51+
MADE_CHANGE=false;
52+
TEMP_FILENAME="${DEPENDENCIES_FILE}_new";
53+
while IFS= read -r line; do
54+
if [[ $line == *"val version ="* ]] && $COMPOSE_BLOCK = true; then
55+
echo "$line" | sed -En 's/".*"/"'$compose_version'"/p'
56+
MADE_CHANGE=true;
57+
elif [[ $line == *"val snapshot ="* ]] && $COMPOSE_BLOCK = true; then
58+
echo "$line" | sed -En 's/".*"/"'$snapshot_version'"/p'
59+
MADE_CHANGE=true;
60+
else
61+
if [[ $line == *"object Compose {"* ]]; then
62+
COMPOSE_BLOCK=true;
63+
elif [[ $line == *"}"* ]]; then
64+
COMPOSE_BLOCK=false;
65+
fi
66+
echo "$line";
67+
fi
68+
done < $DEPENDENCIES_FILE > $TEMP_FILENAME
69+
if $MADE_CHANGE = true; then
70+
echo $DEPENDENCIES_FILE;
71+
mv $TEMP_FILENAME $DEPENDENCIES_FILE;
72+
else
73+
rm $TEMP_FILENAME;
74+
fi
75+
76+
done
77+
78+
# Change build.gradle versions
79+
for DEPENDENCIES_FILE in `find . -type f -iname "build.gradle"` ; do
80+
MADE_CHANGE=false;
81+
TEMP_FILENAME="${DEPENDENCIES_FILE}_new";
82+
while IFS= read -r line; do
83+
if [[ $line == *"ext.compose_version ="* ]]; then
84+
echo "$line" | sed -En "s/\'.*'/\'$compose_version\'/p"
85+
MADE_CHANGE=true;
86+
elif [[ $line == *"ext.compose_snapshot_version ="* ]]; then
87+
echo "$line" | sed -En "s/\'.*'/\'$snapshot_version\'/p"
88+
MADE_CHANGE=true;
89+
else
90+
echo "$line";
91+
fi
92+
done < $DEPENDENCIES_FILE > $TEMP_FILENAME
93+
if $MADE_CHANGE = true; then
94+
echo $DEPENDENCIES_FILE;
95+
mv $TEMP_FILENAME $DEPENDENCIES_FILE;
96+
else
97+
rm $TEMP_FILENAME;
98+
fi
99+
done
100+

0 commit comments

Comments
 (0)
Please sign in to comment.