Skip to content

Commit 5efe6ee

Browse files
Chore: Optimize script
Use git ls-remote command to fetch refs or tags instead of cloning the projects first. This script now only takes a few seconds to complete.
1 parent 1992f6b commit 5efe6ee

File tree

1 file changed

+33
-90
lines changed

1 file changed

+33
-90
lines changed

scripts/update-ref.sh

Lines changed: 33 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -2,109 +2,52 @@
22

33
# Update the fetch-poky.sh script
44
FILE="scripts/fetch-poky.sh"
5-
TMP_FILE="tmp.txt"
6-
tail -n +6 $FILE > $TMP_FILE
7-
8-
echo "#!/bin/bash" > $FILE
9-
echo "" >> $FILE
10-
11-
git clone --depth 1 --filter=blob:none --sparse https://github.com/yoctoproject/poky.git
12-
cd poky
13-
git fetch --tags
14-
TMP_TAG=$(git tag | grep "yocto-" | tail -n 1) # There is a tag: yocto_1.5_M5.rc8 which will take the tail, thus adding a hyphen
15-
LASTEST_RELEASE=$(git show $TMP_TAG | grep commit | sed "s/^commit //")
16-
echo "# Tag: $TMP_TAG" >> ../$FILE
17-
echo "COMMIT=$LASTEST_RELEASE" >> ../$FILE
18-
echo "" >> ../$FILE
19-
cd ..
20-
rm -rf poky
21-
22-
cat $TMP_FILE >> $FILE
23-
rm $TMP_FILE
5+
LATEST_REF=$(git ls-remote --tags https://github.com/yoctoproject/poky.git | grep "yocto-" | tail -n 1)
6+
LATEST_COMMIT=$(echo $LATEST_REF | awk '{print $1}')
7+
LATEST_TAG=$(echo $LATEST_REF | awk '{print $2}' | sed -e "s/refs\\/tags\\///" -e "s/\^.*//")
8+
sed -i $FILE \
9+
-e "s/^\(# Tag: \).*/\1$LATEST_TAG/" \
10+
-e "s/^\(COMMIT=\).*/\1$LATEST_COMMIT/"
2411

2512
# Update the version.ts
26-
DEST="integration-tests/src/utils/version.ts"
27-
28-
# Keep the header
29-
TOTAL_LINES=$(wc -l < $DEST)
30-
LINES_TO_KEEP=$(($TOTAL_LINES - 2))
31-
TMP="tmp.ts"
32-
head -n $LINES_TO_KEEP $DEST > $TMP
13+
FILE="integration-tests/src/utils/version.ts"
3314

34-
git clone --depth 1 --filter=blob:none --sparse https://github.com/bash-lsp/bash-language-server
35-
cd bash-language-server
36-
git fetch --tags
37-
echo "export const bashVersion = '$(git tag --sort=-v:refname | head -n 1 | sed "s/^vscode-client-//")'" >> ../$TMP
38-
cd ..
39-
rm -rf bash-language-server
15+
LATEST_COMMIT=$(git ls-remote --refs --sort=-v:refname https://github.com/bash-lsp/bash-language-server | grep client | head -n 1 | awk '{print $2}' | sed s/refs\\/tags\\/vscode-client-//)
16+
sed -e "s/^\(export const bashVersion =\).*/\1 '$LATEST_COMMIT'/" -i $FILE
4017

41-
git clone --depth 1 --filter=blob:none --sparse https://github.com/Microsoft/vscode-python
42-
cd vscode-python
43-
git fetch --tags
44-
echo "export const pythonVersion = '$(git tag --sort=-v:refname | head -n 1 | sed "s/^v//")'" >> ../$TMP
45-
cd ..
46-
rm -rf vscode-python
47-
48-
cp $TMP $DEST
49-
rm $TMP
18+
LATEST_COMMIT=$(git ls-remote --refs --sort=-v:refname https://github.com/Microsoft/vscode-python | head -n 1 | awk '{print $2}' | sed s/refs\\/tags\\/v//)
19+
sed -e "s/^\(export const pythonVersion =\).*/\1 '$LATEST_COMMIT'/" -i $FILE
5020

5121
# Update the fetch-docs.sh script
5222
FILE="scripts/fetch-docs.sh"
53-
TMP_FILE="tmp.txt"
54-
tail -n +8 $FILE > $TMP_FILE
55-
56-
echo "#!/bin/bash" > $FILE
57-
echo "" >> $FILE
5823

59-
git clone --depth 1 --filter=blob:none --sparse https://github.com/openembedded/bitbake.git
60-
cd bitbake
61-
git fetch --tags
62-
TMP_TAG=$(git tag --sort=-v:refname | head -n 1)
63-
LASTEST_RELEASE=$(git show $TMP_TAG | grep commit | sed "s/^commit //")
64-
echo "# Tag: $TMP_TAG" >> ../$FILE
65-
echo "BITBAKE_DOCS_COMMIT=$LASTEST_RELEASE" >> ../$FILE
66-
cd ..
67-
rm -rf bitbake
24+
LATEST_REF=$(git ls-remote --refs --sort=-v:refname https://github.com/openembedded/bitbake.git | head -n 1)
25+
LATEST_COMMIT=$(echo $LATEST_REF | awk '{print $1}')
26+
LATEST_TAG=$(echo $LATEST_REF | awk '{print $2}' | sed s/refs\\/tags\\///)
27+
sed -i $FILE \
28+
-e "s/^\(# Tag: \).*/\1$LATEST_TAG/" \
29+
-e "s/^\(BITBAKE_DOCS_COMMIT=\).*/\1$LATEST_COMMIT/"
6830

69-
git clone --depth 1 --filter=blob:none --sparse https://git.yoctoproject.org/yocto-docs
70-
cd yocto-docs
71-
git fetch --tags
72-
TMP_TAG=$(git tag --sort=-v:refname | head -n 1)
73-
LASTEST_RELEASE=$(git show $TMP_TAG | grep commit | sed "s/^commit //")
74-
echo "# Tag: $TMP_TAG" >> ../$FILE
75-
echo "YOCTO_DOCS_COMMIT=$LASTEST_RELEASE" >> ../$FILE
76-
echo "" >> ../$FILE
77-
cd ..
78-
rm -rf yocto-docs
31+
LATEST_REF=$(git ls-remote --refs --sort=-v:refname https://git.yoctoproject.org/yocto-docs | head -n 1)
32+
LATEST_COMMIT=$(echo $LATEST_REF | awk '{print $1}')
33+
LATEST_TAG=$(echo $LATEST_REF | awk '{print $2}' | sed s/refs\\/tags\\///)
34+
sed -i $FILE \
35+
-e "s/^\(# Tag: \).*/\1$LATEST_TAG/" \
36+
-e "s/^\(YOCTO_DOCS_COMMIT=\).*/\1$LATEST_COMMIT/"
7937

80-
git clone --depth 1 --filter=blob:none --sparse https://github.com/microsoft/vscode.git
81-
cd vscode
82-
git fetch --tags
83-
TMP_TAG=$(git tag --sort=-v:refname | grep -E '^[0-9.]+$' | head -n 1)
84-
sed -e "s/vscodeVersion = '.*'/vscodeVersion = '$TMP_TAG'/" -i ../integration-tests/src/runTest.ts
85-
cd ..
86-
rm -rf vscode
38+
# Update vscodeVersion in runTest.ts
39+
FILE="integration-tests/src/runTest.ts"
8740

88-
cat $TMP_FILE >> $FILE
89-
rm $TMP_FILE
41+
LATEST_TAG=$(git ls-remote --tags --sort=-v:refname https://github.com/microsoft/vscode.git | grep "refs/tags/[0-9.]" | head -n 1 | awk '{print $2}' | sed s/refs\\/tags\\///)
42+
sed -e "s/vscodeVersion = '.*'/vscodeVersion = '$LATEST_TAG'/" -i $FILE
9043

9144
# Update the fetch-spdx-licenses.sh script
9245
FILE="scripts/fetch-spdx-licenses.sh"
93-
TMP_FILE="tmp.txt"
94-
tail -n +5 $FILE > $TMP_FILE
95-
96-
echo "#!/bin/bash" > $FILE
97-
echo "" >> $FILE
9846

99-
git clone --depth 1 --filter=blob:none --sparse https://github.com/spdx/license-list-data.git
100-
cd license-list-data
101-
git fetch --tags
102-
TMP_TAG=$(git tag --sort=-v:refname | head -n 1)
103-
LATEST_RELEASE=$(git show $TMP_TAG | grep commit -m 1 | sed "s/^commit //")
104-
echo "# Tag: $TMP_TAG" >> ../$FILE
105-
echo "SPDX_LICENSES_COMMIT=$LATEST_RELEASE" >> ../$FILE
106-
cd ..
107-
rm -rf license-list-data
47+
LATEST_REF=$(git ls-remote --refs --sort=-v:refname https://github.com/spdx/license-list-data.git | head -n 1)
48+
LATEST_COMMIT=$(echo $LATEST_REF | awk '{print $1}')
49+
LATEST_TAG=$(echo $LATEST_REF | awk '{print $2}' | sed s/refs\\/tags\\///)
50+
sed -i $FILE \
51+
-e "s/^\(# Tag: \).*/\1$LATEST_TAG/" \
52+
-e "s/^\(SPDX_LICENSES_COMMIT=\).*/\1$LATEST_COMMIT/"
10853

109-
cat $TMP_FILE >> $FILE
110-
rm $TMP_FILE

0 commit comments

Comments
 (0)