diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index 5b40020..129a422 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -14,6 +14,30 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Use last commit hash as build version for the developer build. + if: "startsWith(github.ref, 'refs/heads/')" + run: echo "build_version=${GITHUB_SHA}" >> $GITHUB_ENV + + - name: Use tag name as build version for the release build. + if: startsWith(github.ref, 'refs/tags/v') + run: echo "build_version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV + + # This flow should not be used for pull requests. However the section + # below might be useful for testing purposes. + - name: Use last commit hash as build version for the pull request + if: startsWith(github.ref, 'refs/pull') + run: echo "build_version=${GITHUB_SHA}" >> $GITHUB_ENV + + - name: Replace CDC_BUILD_VERSION + run: | + if grep -q "DCDC_BUILD_VERSION=DEV" "common/BUILD"; then + sed -i 's/DCDC_BUILD_VERSION=DEV/DCDC_BUILD_VERSION=${{ env.build_version }}/g' common/BUILD + else + echo "CDC_BUILD_VERSION was moved out from common/BUILD file." + echo "Please edit create_release.yaml workflow." + exit 1 + fi + - name: Initialize submodules run: git submodule update --init --recursive @@ -58,6 +82,40 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Use last commit hash as build version for the developer build. + if: "startsWith(github.ref, 'refs/heads/')" + run: | + $build_version="${{ github.sha }}" + echo "build_version=$build_version" >> $env:GITHUB_ENV + + - name: Use tag name as build version for the release build. + if: "startsWith(github.ref, 'refs/tags/v')" + run: | + $build_version="${{ github.ref }}".replace("refs/tags/v", "") + echo "build_version=$build_version" >> $env:GITHUB_ENV + + # This flow should not be used for pull requests. However the section + # below might be useful for testing purposes. + - name: Use last commit hash as build version for the pull request + if: startsWith(github.ref, 'refs/pull') + run: | + $build_version="${{ github.sha }}" + echo "build_version=$build_version" >> $env:GITHUB_ENV + + - name: Replace CDC_BUILD_VERSION + run: | + $cdc_version = Select-String -Path common/BUILD -Pattern "DCDC_BUILD_VERSION=DEV" + if ($cdc_version -ne $null) { + $build_file = Get-Content -path common/BUILD -Raw + $build_file = $build_file -replace 'DCDC_BUILD_VERSION=DEV','DCDC_BUILD_VERSION=${{ env.build_version }}' + $build_file | Set-Content -Path common/BUILD + } + else { + Write-Host "CDC_BUILD_VERSION was moved out from common/BUILD file." + Write-Host "Please edit create_release.yaml workflow." + exit 1 + } + - name: Initialize submodules run: git submodule update --init --recursive diff --git a/common/BUILD b/common/BUILD index 1f0faca..0b8e657 100644 --- a/common/BUILD +++ b/common/BUILD @@ -64,7 +64,10 @@ cc_library( cc_library( name = "build_version", + srcs = ["build_version.cc"], hdrs = ["build_version.h"], + # This definition should be replaced by release flow. + copts = ["-DCDC_BUILD_VERSION=DEV"], ) cc_library( diff --git a/common/build_version.cc b/common/build_version.cc new file mode 100644 index 0000000..45de7f5 --- /dev/null +++ b/common/build_version.cc @@ -0,0 +1,9 @@ +#include "build_version.h" + +#ifdef CDC_BUILD_VERSION +#define TO_STR(arg) #arg +#define TO_STR_VALUE(arg) TO_STR(arg) +const char* BUILD_VERSION = TO_STR_VALUE(CDC_BUILD_VERSION); +#else +const char* BUILD_VERSION = DEV_BUILD_VERSION; +#endif \ No newline at end of file diff --git a/common/build_version.h b/common/build_version.h index 2200901..a0894e9 100644 --- a/common/build_version.h +++ b/common/build_version.h @@ -1,10 +1,7 @@ -#ifndef BUILD_VERSION +#ifndef COMMON_BUILD_VERSION_H_ +#define COMMON_BUILD_VERSION_H_ + #define DEV_BUILD_VERSION "DEV" -#ifdef CDC_BUILD_VERSION -#define TO_STR(arg) #arg -#define TO_STR_VALUE(arg) TO_STR(arg) -#define BUILD_VERSION TO_STR_VALUE(CDC_BUILD_VERSION) -#else -#define BUILD_VERSION DEV_BUILD_VERSION -#endif -#endif +extern const char* BUILD_VERSION; + +#endif \ No newline at end of file diff --git a/common/gamelet_component_test.cc b/common/gamelet_component_test.cc index 9a33ee6..b7d0920 100644 --- a/common/gamelet_component_test.cc +++ b/common/gamelet_component_test.cc @@ -124,9 +124,30 @@ TEST_F(GameletComponentTest, GetChangedComponents) { // Force equal timestamps, so that we don't depend on when the files were // actually written to everyone's drives. + // Also force set build_version to developer since otherwise we would skip + // component size check. ASSERT_EQ(components.size(), other_components.size()); for (size_t n = 0; n < components.size(); ++n) { other_components[n].modified_time = components[n].modified_time; + other_components[n].build_version = DEV_BUILD_VERSION; + + EXPECT_NE(components, other_components); + } +} + +TEST_F(GameletComponentTest, GetChangedComponents_BuildVersionChanged) { + std::vector components; + EXPECT_OK(GameletComponent::Get({valid_component_path_}, &components)); + + std::vector other_components; + EXPECT_OK(GameletComponent::Get({other_component_path_}, &other_components)); + + ASSERT_EQ(components.size(), other_components.size()); + for (size_t n = 0; n < components.size(); ++n) { + other_components[n].modified_time = components[n].modified_time; + other_components[n].size = components[n].size; + components[n].build_version = "build_version"; + other_components[n].build_version = "other_build_version"; EXPECT_NE(components, other_components); }