From 3c8d5ae4e6a9fb91a72bc52da6feed28c785b047 Mon Sep 17 00:00:00 2001 From: Andrei Dabija Date: Wed, 16 Oct 2024 17:41:53 +0300 Subject: [PATCH 01/11] remove not needed debug log --- source/gameanalytics/GAValidator.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/gameanalytics/GAValidator.cpp b/source/gameanalytics/GAValidator.cpp index 06f26085..e6d2b573 100644 --- a/source/gameanalytics/GAValidator.cpp +++ b/source/gameanalytics/GAValidator.cpp @@ -718,8 +718,6 @@ namespace gameanalytics { constexpr int64_t k_maxTs = 99999999999; - logging::GALogger::d("clientTs = %lld", clientTs); - if (clientTs < 0 || clientTs > k_maxTs) { return false; From 63742514e92004c4b3fcce9120fdc88b96de706e Mon Sep 17 00:00:00 2001 From: Andrei Dabija Date: Wed, 16 Oct 2024 21:36:09 +0300 Subject: [PATCH 02/11] recreate build as a reusable workflow --- .github/workflows/build.yml | 24 ++++++++++++++++++++++++ .github/workflows/cmake.yml | 20 +++++++++----------- 2 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..256c155c --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,24 @@ +name: CI + +on: + push: + branches: ['*'] # Trigger on push events for all branches + pull_request: + branches: ['master'] # Trigger on pull requests to master + workflow_dispatch: # Allow manual triggering of workflow + +jobs: + build: + if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/cmake.yml + with: + build_type: Debug + + build_pr: + if: github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'master' + strategy: + matrix: + build_type: [Debug, Release] + uses: ./.github/workflows/cmake.yml + with: + build_type: ${{ matrix.build_type }} diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index f8d5dec2..a9e1e3ef 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -2,7 +2,14 @@ # See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml name: CMake Build and Test -on: [push, workflow_dispatch] +on: + workflow_call: + inputs: + build_type: + description: 'Build type (e.g., "Debug", "Release", "RelWithDebInfo", "MinSizeRel")' + required: true + type: string + jobs: build: @@ -20,7 +27,7 @@ jobs: # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. matrix: os: [ubuntu-latest, windows-latest, macOS-latest] - build_type: [Release] + build_type: ${{ fromJSON(format('[{0}]', inputs.build_type || '"Debug","Release"')) }} c_compiler: [gcc, clang, cl] include: - os: windows-latest @@ -86,15 +93,6 @@ jobs: # Adjust the path to your built library files cp ${{ steps.strings.outputs.build-output-dir }}/${{ matrix.build_type }}/*GameAnalytics.* ${{ steps.strings.outputs.build-output-dir }}/package/ cp -r ${{ github.workspace }}/include ${{ steps.strings.outputs.build-output-dir }}/package/ - - - name: Print Package Contents on Windows - if: matrix.os == 'windows-latest' - run: Get-ChildItem -Recurse "${{ steps.strings.outputs.build-output-dir }}\package" - shell: pwsh - - - name: Print Package Contents on non-Windows (Linux/macOS) - if: matrix.os != 'windows-latest' - run: ls -la ${{ steps.strings.outputs.build-output-dir }}/package - name: Upload Build Artifact if: ${{ success() }} From 1ffdf1f0891d71038686af0b652041b92dead4ab Mon Sep 17 00:00:00 2001 From: Andrei Dabija Date: Thu, 17 Oct 2024 10:54:06 +0300 Subject: [PATCH 03/11] allow building for both debug and release for PRs in master --- .github/workflows/build.yml | 12 +----------- .github/workflows/cmake.yml | 1 + 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 256c155c..ec32db75 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,16 +9,6 @@ on: jobs: build: - if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' uses: ./.github/workflows/cmake.yml with: - build_type: Debug - - build_pr: - if: github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'master' - strategy: - matrix: - build_type: [Debug, Release] - uses: ./.github/workflows/cmake.yml - with: - build_type: ${{ matrix.build_type }} + build_type: ${{ (github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'master') && '"Debug","Release"' || '"Debug"' }} diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index a9e1e3ef..09ba52e7 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -7,6 +7,7 @@ on: inputs: build_type: description: 'Build type (e.g., "Debug", "Release", "RelWithDebInfo", "MinSizeRel")' + default: '"Debug"' required: true type: string From 6639898e2084fcccd520b7a9b935173e1ae43210 Mon Sep 17 00:00:00 2001 From: Andrei Dabija Date: Thu, 17 Oct 2024 16:10:48 +0300 Subject: [PATCH 04/11] dont run build.yml on tags cuz release workflow --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ec32db75..4b391eda 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,6 +3,7 @@ name: CI on: push: branches: ['*'] # Trigger on push events for all branches + tags-ignore: ['*'] # Ignore push events on all tags pull_request: branches: ['master'] # Trigger on pull requests to master workflow_dispatch: # Allow manual triggering of workflow From b2774c89bb3111e9eee2a83e943f0b6efdc9cf30 Mon Sep 17 00:00:00 2001 From: Andrei Dabija Date: Thu, 17 Oct 2024 16:10:59 +0300 Subject: [PATCH 05/11] add create_release workflow --- .github/workflows/create_release.yml | 45 ++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/create_release.yml diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml new file mode 100644 index 00000000..4431d878 --- /dev/null +++ b/.github/workflows/create_release.yml @@ -0,0 +1,45 @@ +name: Create Release +run-name: C++ SDK Release ${{ inputs.tag_name }} + +on: + workflow_dispatch: + inputs: + tag_name: + description: 'Tag name for the release (e.g., v1.0.0)' + required: true + type: string + + +jobs: + build: + uses: ./.github/workflows/cmake.yml + with: + build_type: '"Release"' + + release: + name: Create GitHub Release + needs: build + runs-on: ubuntu-latest + + steps: + - name: Push tag ${{ inputs.tag_name }} + run: | + git tag ${{ inputs.tag_name }} + git push origin ${{ inputs.tag_name }} + + - name: Download Artifacts + uses: actions/download-artifact@v4 + with: + path: ./release-artifacts + + - name: Show downloaded artifacts + run: ls -l ./release-artifacts + + - name: Create release + uses: softprops/action-gh-release@v2.0.8 + with: + tag_name: ${{ inputs.tag_name }} + name: Release GA-CPP-SDK ${{ inputs.tag_name }} + generate_release_notes: true + make_latest: true + files: ./release-artifacts/* \ No newline at end of file From 977ee3b404f3476ae107c2744d9b8f95845f8c46 Mon Sep 17 00:00:00 2001 From: Andrei Dabija Date: Thu, 17 Oct 2024 16:18:32 +0300 Subject: [PATCH 06/11] add release notes format for git actions --- .github/release.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/release.yml diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 00000000..7975d844 --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,22 @@ +changelog: + exclude: + labels: + - ignore-for-release + - github-actions + authors: + - octocat + - renovate[bot] + categories: + - title: Breaking Changes 🛠 + labels: + - breaking-change + - title: Exciting New Features 🎉 + labels: + - enhancement + - feature + - title: Bug fixes 🐛 + labels: + - bug + - title: Other Changes 🔄 + labels: + - "*" \ No newline at end of file From d1ead30e7e16bad9d2b04ac19cf8c1e8605fbe57 Mon Sep 17 00:00:00 2001 From: Andrei Dabija Date: Thu, 17 Oct 2024 16:36:21 +0300 Subject: [PATCH 07/11] add gh create release --- .github/workflows/create_release.yml | 3 +- gh_create_release.py | 70 ++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 gh_create_release.py diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index 4431d878..deb3a30e 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -1,5 +1,5 @@ name: Create Release -run-name: C++ SDK Release ${{ inputs.tag_name }} +# run-name: C++ SDK Release ${{ inputs.tag_name }} on: workflow_dispatch: @@ -9,7 +9,6 @@ on: required: true type: string - jobs: build: uses: ./.github/workflows/cmake.yml diff --git a/gh_create_release.py b/gh_create_release.py new file mode 100644 index 00000000..48f3e4e7 --- /dev/null +++ b/gh_create_release.py @@ -0,0 +1,70 @@ +import subprocess +import sys +import re + +def run_command(command): + """Run the specified command and handle errors.""" + try: + result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True) + print(result.stdout) + return result.returncode + except subprocess.CalledProcessError as e: + print(f"Error occurred: {e.stderr}", file=sys.stderr) + return e.returncode + +def trigger_workflow(tag_name): + """Trigger the GitHub Actions workflow using GitHub CLI.""" + # Set repository and branch + repo = "GameAnalytics/GA-SDK-CPP-NEW" + branch = "main" + + # Construct the GitHub CLI command + command = f'gh workflow run "Create Release" --repo {repo} --ref {branch} -f tag_name={tag_name}' + print(f"Running command: {command}") + + # Execute the command + return_code = run_command(command) + + if return_code == 0: + print("Workflow triggered successfully.") + else: + print(f"Failed to trigger workflow. Return code: {return_code}") + +def check_gh_cli_installed(): + """Check if GitHub CLI (gh) is installed and available in the system path.""" + try: + subprocess.run(['gh', '--version'], capture_output=True, check=True) + return True + except FileNotFoundError: + return False + +def validate_tag_name(tag_name): + """Validate that the tag name matches the format 'v1.0.0'.""" + pattern = r"^v\d+\.\d+\.\d+$" + if re.match(pattern, tag_name): + return True + else: + return False + +def main(): + # Ensure GitHub CLI is installed + if not check_gh_cli_installed(): + print("GitHub CLI (gh) is not installed. Please install it and try again.") + sys.exit(1) + + # Validate tag name passed as an argument + if len(sys.argv) != 2: + print("Usage: python trigger_workflow.py ") + sys.exit(1) + + tag_name = sys.argv[1] + + if not validate_tag_name(tag_name): + print("Invalid tag name format. Please use the format 'v1.0.0'.") + sys.exit(1) + + # Trigger the workflow with validated tag name + trigger_workflow(tag_name) + +if __name__ == "__main__": + main() From 37bce74e0d2c36dc81ee29fba839d4e482bcf96d Mon Sep 17 00:00:00 2001 From: Andrei Dabija Date: Thu, 17 Oct 2024 17:32:44 +0300 Subject: [PATCH 08/11] Update cmake.yml --- .github/workflows/cmake.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 09ba52e7..7040171b 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -88,7 +88,7 @@ jobs: run: ctest --build-config ${{ matrix.build_type }} --verbose --output-on-failure - name: Package Build Artifacts - if: ${{ success() }} + if: github.event_name == 'pull_request' && github.base_ref == 'master' && ${{ success() }} run: | mkdir -p ${{ steps.strings.outputs.build-output-dir }}/package # Adjust the path to your built library files @@ -96,7 +96,7 @@ jobs: cp -r ${{ github.workspace }}/include ${{ steps.strings.outputs.build-output-dir }}/package/ - name: Upload Build Artifact - if: ${{ success() }} + if: github.event_name == 'pull_request' && github.base_ref == 'master' && ${{ success() }} uses: actions/upload-artifact@v4 with: name: ga-cpp-sdk-${{ matrix.os }}-${{ matrix.c_compiler }}-${{ matrix.build_type }} From 61b5c7bb5075cfe48f83ed79acec7c050bb4c955 Mon Sep 17 00:00:00 2001 From: Andrei Dabija Date: Fri, 18 Oct 2024 10:48:17 +0300 Subject: [PATCH 09/11] Update create_release.yml --- .github/workflows/create_release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index deb3a30e..c7c5f2d5 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -1,5 +1,5 @@ name: Create Release -# run-name: C++ SDK Release ${{ inputs.tag_name }} +run-name: C++ SDK Release ${{ inputs.tag_name }} on: workflow_dispatch: From d6885128589f5b6d9e9827723baed57865a8f902 Mon Sep 17 00:00:00 2001 From: Andrei Dabija Date: Fri, 18 Oct 2024 11:39:29 +0300 Subject: [PATCH 10/11] add a bool to decide if it should upload artifacts. --- .github/workflows/build.yml | 3 ++- .github/workflows/cmake.yml | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4b391eda..b2c368eb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,4 +12,5 @@ jobs: build: uses: ./.github/workflows/cmake.yml with: - build_type: ${{ (github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'master') && '"Debug","Release"' || '"Debug"' }} + build_type: ${{ (github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main') && '"Debug","Release"' || '"Debug"' }} + upload_artifacts: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main' }} \ No newline at end of file diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 7040171b..28938db9 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -10,10 +10,14 @@ on: default: '"Debug"' required: true type: string - + upload_artifacts: + description: 'Whether to upload artifacts (true/false)' + default: false + required: true + type: boolean jobs: - build: + cmake_build: runs-on: ${{ matrix.os }} strategy: @@ -88,7 +92,7 @@ jobs: run: ctest --build-config ${{ matrix.build_type }} --verbose --output-on-failure - name: Package Build Artifacts - if: github.event_name == 'pull_request' && github.base_ref == 'master' && ${{ success() }} + if: ${{ inputs.upload_artifacts && success() }} run: | mkdir -p ${{ steps.strings.outputs.build-output-dir }}/package # Adjust the path to your built library files @@ -96,7 +100,7 @@ jobs: cp -r ${{ github.workspace }}/include ${{ steps.strings.outputs.build-output-dir }}/package/ - name: Upload Build Artifact - if: github.event_name == 'pull_request' && github.base_ref == 'master' && ${{ success() }} + if: ${{ inputs.upload_artifacts && success() }} uses: actions/upload-artifact@v4 with: name: ga-cpp-sdk-${{ matrix.os }}-${{ matrix.c_compiler }}-${{ matrix.build_type }} From 41173e9348573ec49bf49c37fd37ed29ad585d5a Mon Sep 17 00:00:00 2001 From: Andrei Dabija Date: Fri, 18 Oct 2024 11:50:22 +0300 Subject: [PATCH 11/11] Update create_release.yml --- .github/workflows/create_release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index c7c5f2d5..e5abe367 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -14,6 +14,7 @@ jobs: uses: ./.github/workflows/cmake.yml with: build_type: '"Release"' + upload_artifacts: true release: name: Create GitHub Release