Skip to content

Commit 8ac5cfd

Browse files
committed
add: actions
1 parent 5442375 commit 8ac5cfd

File tree

5 files changed

+123
-35
lines changed

5 files changed

+123
-35
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# https://docs.github.com/en/actions/tutorials/create-actions/create-a-composite-action
2+
name: 'Build Binary and Export Env'
3+
description: |
4+
This action builds the binary.
5+
6+
inputs:
7+
preset:
8+
description: |
9+
The preset to use for building.
10+
11+
required: true
12+
13+
config:
14+
description: |
15+
The config to use for building.
16+
17+
required: true
18+
19+
target:
20+
description: |
21+
The target to use for building.
22+
23+
required: true
24+
25+
runs:
26+
using: composite
27+
steps:
28+
- name: 'Build'
29+
shell: pwsh
30+
run: |
31+
cmake --build `
32+
--preset ${{ inputs.preset }} `
33+
--config ${{ inputs.config }} `
34+
--target ${{ inputs.target }}
35+
36+
- name: 'Set PACKAGE_VERSION from env.bat'
37+
id: package-version
38+
shell: pwsh
39+
run: |
40+
$content = Get-Content -Raw build/env.bat
41+
echo "$content"
42+
$match = [regex]::Match($content, 'PACKAGE_VERSION=(.+)')
43+
$version = if ($match.Success) { $match.Groups[1].Value.Trim() } else { '0.0.0' }
44+
echo "PACKAGE_VERSION=$version" >> $env:GITHUB_OUTPUT
45+
46+
outputs:
47+
package-version:
48+
value: ${{ steps.package-version.outputs.PACKAGE_VERSION }}
49+
description: |
50+
The version of the package.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# https://docs.github.com/en/actions/tutorials/create-actions/create-a-composite-action
2+
name: 'Check Valid Semver Tag'
3+
description: |
4+
This action checks if the provided tag is a valid semver tag.
5+
6+
inputs:
7+
tag:
8+
description: |
9+
The tag to check.
10+
11+
required: true
12+
13+
runs:
14+
using: composite
15+
steps:
16+
- name: 'Check tag'
17+
id: check-tag
18+
shell: pwsh
19+
run: |
20+
$tag = "${{ inputs.tag }}"
21+
if ($tag -match '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(alpha|rc|beta|experimental)\.[1-9]\d*)?$') {
22+
Write-Host "Valid semver" -ForegroundColor Green
23+
echo "IS_VALID_SEMVER=true" >> $env:GITHUB_OUTPUT
24+
} else {
25+
Write-Host "Invalid semver" -ForegroundColor Red
26+
echo "IS_VALID_SEMVER=false" >> $env:GITHUB_OUTPUT
27+
}
28+
29+
outputs:
30+
is-valid-semver:
31+
value: ${{ steps.check-tag.outputs.IS_VALID_SEMVER }}
32+
description: |
33+
If the tag is a valid semver tag.

.github/actions/setup_and_configure_cmake/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ description: |
66
inputs:
77
version:
88
description: |
9-
What version to use for CMake setup
9+
The version to use for CMake setup.
1010
1111
default: '3.31.x'
1212
required: false
1313

1414
preset:
1515
description: |
16-
What preset to use for the CMake configuration
16+
The preset to use for the CMake configuration.
1717
1818
required: true
1919

.github/workflows/build_binary.yml

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,18 @@ jobs:
2424
with:
2525
fetch-depth: 0
2626

27-
- name: 'Setup CMake'
28-
uses: jwlawson/actions-setup-cmake@v2
27+
- name: 'Setup and configure CMake'
28+
uses: './.github/actions/setup_and_configure_cmake'
2929
with:
30-
cmake-version: '3.31.x'
31-
32-
- name: 'Configure CMake'
33-
run: |
34-
cmake --preset windows-vs-release
30+
preset: 'windows-vs-release'
3531

3632
- name: 'Build'
3733
id: build
38-
run: |
39-
cmake --build --preset windows-vs-release --config Release --target cpp_bindings_windows
40-
41-
- name: 'Set PACKAGE_VERSION from env.bat'
42-
id: version
43-
shell: pwsh
44-
run: |
45-
$content = Get-Content -Raw build/env.bat
46-
echo "$content"
47-
$m = [regex]::Match($content, 'PACKAGE_VERSION=(.+)')
48-
$v = if ($m.Success) { $m.Groups[1].Value.Trim() } else { '0.0.0' }
49-
echo "PACKAGE_VERSION=$v" >> $env:GITHUB_OUTPUT
34+
uses: './.github/actions/build_binary_and_export_env'
35+
with:
36+
preset: 'windows-vs-release'
37+
config: 'Release'
38+
target: 'cpp_bindings_windows'
5039

5140
- name: 'Copy DLL to stable path and upload artifact'
5241
shell: pwsh
@@ -63,31 +52,23 @@ jobs:
6352
name: cpp_bindings_windows
6453
path: build/out/cpp_bindings_windows.dll
6554

66-
- name: 'Check tag'
55+
- name: 'Check valid semver tag'
6756
id: check-tag
68-
shell: pwsh
69-
env:
70-
PACKAGE_VERSION: ${{ steps.version.outputs.PACKAGE_VERSION }}
71-
72-
run: |
73-
$v = $env:PACKAGE_VERSION
74-
if ($v -match '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(alpha|rc|beta|experimental)\.[1-9]\d*)?$') {
75-
echo "IS_VALID_PACKAGE_VERSION=true" >> $env:GITHUB_OUTPUT
76-
} else {
77-
echo "IS_VALID_PACKAGE_VERSION=false" >> $env:GITHUB_OUTPUT
78-
}
57+
uses: './.github/actions/check_valid_semver_tag'
58+
with:
59+
tag: ${{ steps.build.outputs.PACKAGE_VERSION }}
7960

8061
- name: 'Create GitHub Release'
8162
if: github.ref_type == 'tag' && steps.check-tag.outputs.IS_VALID_PACKAGE_VERSION == 'true'
8263
uses: softprops/action-gh-release@v2
8364
with:
84-
name: 'v${{ steps.version.outputs.PACKAGE_VERSION }}'
65+
name: 'v${{ steps.build.outputs.PACKAGE_VERSION }}'
8566
tag_name: ${{ github.ref_name }}
8667
generate_release_notes: true
8768
files: build/out/cpp_bindings_windows.dll
8869

8970
outputs:
90-
package_version: ${{ steps.version.outputs.PACKAGE_VERSION }}
71+
package_version: ${{ steps.build.outputs.PACKAGE_VERSION }}
9172
is_valid_package_version: ${{ steps.check-tag.outputs.IS_VALID_PACKAGE_VERSION }}
9273

9374
test-unit-cpp:

.github/workflows/on_tag.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax
2+
name: 'On Tag'
3+
description: |
4+
This workflow runs when a tag gets created.
5+
6+
on:
7+
push:
8+
branches: [ 'main' ]
9+
tags: [ '*' ]
10+
11+
jobs:
12+
run:
13+
name: 'Run'
14+
runs-on: windows-latest
15+
steps:
16+
- name: 'Checkout repository'
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: 'Setup and configure CMake'
22+
uses: './.github/actions/setup_and_configure_cmake'
23+
with:
24+
preset: 'windows-vs-release'

0 commit comments

Comments
 (0)