From 8a1a3b066da4600e5d6465e769282dc9d6c559b2 Mon Sep 17 00:00:00 2001 From: Nikolai Selivanov Date: Tue, 4 Jun 2024 23:19:14 +0300 Subject: [PATCH] Improve di --- .github/workflows/publish.yml | 37 +++++-------------- .../Zenject/Source/Zenject.csproj.meta | 8 ---- getVersion.py | 37 +++++++++++++++++++ 3 files changed, 47 insertions(+), 35 deletions(-) delete mode 100644 DemoUnityProj/QuickStartUnityMVVM/Assets/Plugins/Zenject/Source/Zenject.csproj.meta create mode 100644 getVersion.py diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 90ba73c..5c14ace 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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 @@ -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' > $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>\)/\1$newVersion\3/" src/UnityMVVM/UnityMVVM.csproj + sed -i '' -e "s/\(\)\(.*\)\(<\/Version>\)/\1$CURRENT_TAG_VERSION\3/" src/UnityMVVM/UnityMVVM.csproj - name: Run tests run: dotnet test src --verbosity normal - name: Build for demo project diff --git a/DemoUnityProj/QuickStartUnityMVVM/Assets/Plugins/Zenject/Source/Zenject.csproj.meta b/DemoUnityProj/QuickStartUnityMVVM/Assets/Plugins/Zenject/Source/Zenject.csproj.meta deleted file mode 100644 index 7e1c87a..0000000 --- a/DemoUnityProj/QuickStartUnityMVVM/Assets/Plugins/Zenject/Source/Zenject.csproj.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 8645273165cb7f54290d6eaa1e10ab37 -timeCreated: 1461878212 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/getVersion.py b/getVersion.py new file mode 100644 index 0000000..97e8cd5 --- /dev/null +++ b/getVersion.py @@ -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])) \ No newline at end of file