Skip to content

Commit

Permalink
Improve di
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolai Selivanov committed Jun 4, 2024
1 parent f825a35 commit 8a1a3b0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 35 deletions.
37 changes: 10 additions & 27 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:

env:
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
RUNNER_USERNAME: ${{ secrets.RUNNER_USERNAME }}
REPO_URL: ${{github.repositoryUrl}}

steps:
- uses: actions/checkout@v3
Expand All @@ -25,35 +27,16 @@ jobs:
- name: Configure version
run: |
git fetch --unshallow
lastTag=$(git describe --tags --abbrev=0)
currentTag=$(git tag --contains)
lastTagMainVersion=$(sed -n 's/^\([0-9]*\.[0-9]*\).*/\1/p' <<<"$lastTag")
currentVersion=$(cat VERSION)
currentMainVersion=$(sed -n 's/^\([0-9]*\.[0-9]*\).*/\1/p' <VERSION)
if [ "$lastTag" = "$currentTag" ]
CURRENT_TAG_VERSION=$(git tag --points-at HEAD)
echo $CURRENT_TAG_VERSION
if [ -z "$CURRENT_TAG_VERSION" ]
then
echo "Build from tagged commit"
newVersion=$lastTag
echo "newVersion=$newVersion"
echo "newVersion=$newVersion" >> $GITHUB_ENV
else
if [ "$lastTagMainVersion" = "$currentMainVersion" ]
then
echo "Version the same."
lastTagBuildVersion=$(sed -n 's/^[0-9]*\.[0-9]*\.\([0-9]*\).*/\1/p' <<<"$lastTag")
newBuildVersion=$((lastTagBuildVersion+1))
newVersion="$lastTagMainVersion"."$newBuildVersion"
echo "newVersion=$newVersion"
echo "newVersion=$newVersion" >> $GITHUB_ENV
else
echo "New version!"
newVersion="$currentMainVersion".1
VersionPrefix=$newVersion
echo "newVersion=$newVersion"
echo "newVersion=$newVersion" >> $GITHUB_ENV
fi
git remote set-url origin https://$RUNNER_USERNAME:$PAT_TOKEN@${REPO_URL:8}.git
CURRENT_TAG_VERSION=$(python3 getVersion.py ./VERSION $UMVVM_BUILD_DATA_PATH/buildVersionV1.txt)
git tag $CURRENT_TAG_VERSION
git push origin --tags
fi
sed -i '' -e "s/\(<Version>\)\(.*\)\(<\/Version>\)/\1$newVersion\3/" src/UnityMVVM/UnityMVVM.csproj
sed -i '' -e "s/\(<Version>\)\(.*\)\(<\/Version>\)/\1$CURRENT_TAG_VERSION\3/" src/UnityMVVM/UnityMVVM.csproj
- name: Run tests
run: dotnet test src --verbosity normal
- name: Build for demo project
Expand Down

This file was deleted.

37 changes: 37 additions & 0 deletions getVersion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import sys

unityProjectSettingsPath = sys.argv[1];
buildDataPath = sys.argv[2];
bundleParameter = "bundleVersion: ";

with open(unityProjectSettingsPath) as file:
for line in file:
line = line.strip()
if line.startswith(bundleParameter):
projectVersion = line[len(bundleParameter):len(line)].strip();

projectVersion = projectVersion.split('.')

open(buildDataPath, 'a+')


with open(buildDataPath, 'r+') as buildDataFile:
buildVersions = [x.strip().split('.') for x in buildDataFile.readlines()]

if (len(buildVersions) == 0):
with open(buildDataPath, 'w+') as buildDataFile:
version = projectVersion[0] + '.' + projectVersion[1] + '.0'
buildDataFile.write(version)
print(version)
else:
lastVersions = next(filter(lambda x: x[0] == projectVersion[0] and x[1] == projectVersion[1], buildVersions), None)
if (lastVersions == None):
lastVersions = projectVersion.copy()
buildVersions.append(lastVersions)
print('.'.join(lastVersions))
else:
lastVersions[2] = str(int(lastVersions[2]) + 1)
version = lastVersions[0] + '.' + lastVersions[1] + '.' + lastVersions[2]
print(version)
with open(buildDataPath, 'w+') as buildDataFile:
buildDataFile.write('\n'.join(['.'.join(x) for x in buildVersions]))

0 comments on commit 8a1a3b0

Please sign in to comment.