Skip to content

Commit db41660

Browse files
authored
Add Release Workflow + CI improvements (#14)
* remove not needed debug log * recreate build as a reusable workflow * allow building for both debug and release for PRs in master * dont run build.yml on tags cuz release workflow * add create_release workflow * add release notes format for git actions * add gh create release * Update cmake.yml * Update create_release.yml * add a bool to decide if it should upload artifacts. * Update create_release.yml
1 parent 745551e commit db41660

File tree

6 files changed

+170
-16
lines changed

6 files changed

+170
-16
lines changed

.github/release.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
changelog:
2+
exclude:
3+
labels:
4+
- ignore-for-release
5+
- github-actions
6+
authors:
7+
- octocat
8+
- renovate[bot]
9+
categories:
10+
- title: Breaking Changes 🛠
11+
labels:
12+
- breaking-change
13+
- title: Exciting New Features 🎉
14+
labels:
15+
- enhancement
16+
- feature
17+
- title: Bug fixes 🐛
18+
labels:
19+
- bug
20+
- title: Other Changes 🔄
21+
labels:
22+
- "*"

.github/workflows/build.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: ['*'] # Trigger on push events for all branches
6+
tags-ignore: ['*'] # Ignore push events on all tags
7+
pull_request:
8+
branches: ['master'] # Trigger on pull requests to master
9+
workflow_dispatch: # Allow manual triggering of workflow
10+
11+
jobs:
12+
build:
13+
uses: ./.github/workflows/cmake.yml
14+
with:
15+
build_type: ${{ (github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main') && '"Debug","Release"' || '"Debug"' }}
16+
upload_artifacts: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main' }}

.github/workflows/cmake.yml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,22 @@
22
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml
33
name: CMake Build and Test
44

5-
on: [push, workflow_dispatch]
5+
on:
6+
workflow_call:
7+
inputs:
8+
build_type:
9+
description: 'Build type (e.g., "Debug", "Release", "RelWithDebInfo", "MinSizeRel")'
10+
default: '"Debug"'
11+
required: true
12+
type: string
13+
upload_artifacts:
14+
description: 'Whether to upload artifacts (true/false)'
15+
default: false
16+
required: true
17+
type: boolean
618

719
jobs:
8-
build:
20+
cmake_build:
921
runs-on: ${{ matrix.os }}
1022

1123
strategy:
@@ -20,7 +32,7 @@ jobs:
2032
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
2133
matrix:
2234
os: [ubuntu-latest, windows-latest, macOS-latest]
23-
build_type: [Release]
35+
build_type: ${{ fromJSON(format('[{0}]', inputs.build_type || '"Debug","Release"')) }}
2436
c_compiler: [gcc, clang, cl]
2537
include:
2638
- os: windows-latest
@@ -80,24 +92,15 @@ jobs:
8092
run: ctest --build-config ${{ matrix.build_type }} --verbose --output-on-failure
8193

8294
- name: Package Build Artifacts
83-
if: ${{ success() }}
95+
if: ${{ inputs.upload_artifacts && success() }}
8496
run: |
8597
mkdir -p ${{ steps.strings.outputs.build-output-dir }}/package
8698
# Adjust the path to your built library files
8799
cp ${{ steps.strings.outputs.build-output-dir }}/${{ matrix.build_type }}/*GameAnalytics.* ${{ steps.strings.outputs.build-output-dir }}/package/
88100
cp -r ${{ github.workspace }}/include ${{ steps.strings.outputs.build-output-dir }}/package/
89-
90-
- name: Print Package Contents on Windows
91-
if: matrix.os == 'windows-latest'
92-
run: Get-ChildItem -Recurse "${{ steps.strings.outputs.build-output-dir }}\package"
93-
shell: pwsh
94-
95-
- name: Print Package Contents on non-Windows (Linux/macOS)
96-
if: matrix.os != 'windows-latest'
97-
run: ls -la ${{ steps.strings.outputs.build-output-dir }}/package
98101
99102
- name: Upload Build Artifact
100-
if: ${{ success() }}
103+
if: ${{ inputs.upload_artifacts && success() }}
101104
uses: actions/upload-artifact@v4
102105
with:
103106
name: ga-cpp-sdk-${{ matrix.os }}-${{ matrix.c_compiler }}-${{ matrix.build_type }}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Create Release
2+
run-name: C++ SDK Release ${{ inputs.tag_name }}
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
tag_name:
8+
description: 'Tag name for the release (e.g., v1.0.0)'
9+
required: true
10+
type: string
11+
12+
jobs:
13+
build:
14+
uses: ./.github/workflows/cmake.yml
15+
with:
16+
build_type: '"Release"'
17+
upload_artifacts: true
18+
19+
release:
20+
name: Create GitHub Release
21+
needs: build
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Push tag ${{ inputs.tag_name }}
26+
run: |
27+
git tag ${{ inputs.tag_name }}
28+
git push origin ${{ inputs.tag_name }}
29+
30+
- name: Download Artifacts
31+
uses: actions/download-artifact@v4
32+
with:
33+
path: ./release-artifacts
34+
35+
- name: Show downloaded artifacts
36+
run: ls -l ./release-artifacts
37+
38+
- name: Create release
39+
uses: softprops/[email protected]
40+
with:
41+
tag_name: ${{ inputs.tag_name }}
42+
name: Release GA-CPP-SDK ${{ inputs.tag_name }}
43+
generate_release_notes: true
44+
make_latest: true
45+
files: ./release-artifacts/*

gh_create_release.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import subprocess
2+
import sys
3+
import re
4+
5+
def run_command(command):
6+
"""Run the specified command and handle errors."""
7+
try:
8+
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
9+
print(result.stdout)
10+
return result.returncode
11+
except subprocess.CalledProcessError as e:
12+
print(f"Error occurred: {e.stderr}", file=sys.stderr)
13+
return e.returncode
14+
15+
def trigger_workflow(tag_name):
16+
"""Trigger the GitHub Actions workflow using GitHub CLI."""
17+
# Set repository and branch
18+
repo = "GameAnalytics/GA-SDK-CPP-NEW"
19+
branch = "main"
20+
21+
# Construct the GitHub CLI command
22+
command = f'gh workflow run "Create Release" --repo {repo} --ref {branch} -f tag_name={tag_name}'
23+
print(f"Running command: {command}")
24+
25+
# Execute the command
26+
return_code = run_command(command)
27+
28+
if return_code == 0:
29+
print("Workflow triggered successfully.")
30+
else:
31+
print(f"Failed to trigger workflow. Return code: {return_code}")
32+
33+
def check_gh_cli_installed():
34+
"""Check if GitHub CLI (gh) is installed and available in the system path."""
35+
try:
36+
subprocess.run(['gh', '--version'], capture_output=True, check=True)
37+
return True
38+
except FileNotFoundError:
39+
return False
40+
41+
def validate_tag_name(tag_name):
42+
"""Validate that the tag name matches the format 'v1.0.0'."""
43+
pattern = r"^v\d+\.\d+\.\d+$"
44+
if re.match(pattern, tag_name):
45+
return True
46+
else:
47+
return False
48+
49+
def main():
50+
# Ensure GitHub CLI is installed
51+
if not check_gh_cli_installed():
52+
print("GitHub CLI (gh) is not installed. Please install it and try again.")
53+
sys.exit(1)
54+
55+
# Validate tag name passed as an argument
56+
if len(sys.argv) != 2:
57+
print("Usage: python trigger_workflow.py <tag_name>")
58+
sys.exit(1)
59+
60+
tag_name = sys.argv[1]
61+
62+
if not validate_tag_name(tag_name):
63+
print("Invalid tag name format. Please use the format 'v1.0.0'.")
64+
sys.exit(1)
65+
66+
# Trigger the workflow with validated tag name
67+
trigger_workflow(tag_name)
68+
69+
if __name__ == "__main__":
70+
main()

source/gameanalytics/GAValidator.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,6 @@ namespace gameanalytics
718718
{
719719
constexpr int64_t k_maxTs = 99999999999;
720720

721-
logging::GALogger::d("clientTs = %lld", clientTs);
722-
723721
if (clientTs < 0 || clientTs > k_maxTs)
724722
{
725723
return false;

0 commit comments

Comments
 (0)