Skip to content

Commit

Permalink
ci: gen go and py example
Browse files Browse the repository at this point in the history
  • Loading branch information
pplmx committed Mar 27, 2024
1 parent a22919a commit dda9ba5
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 26 deletions.
74 changes: 65 additions & 9 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,87 @@ on:
branches: [ main ]

jobs:
cxx_example:
example_cxx:
runs-on: ubuntu-latest
env:
PROJECT_NAME: example
CXX_PROJECT_NAME: example_cxx
steps:
- uses: actions/checkout@v4

- name: Generate Example from Template
uses: cargo-generate/cargo-generate-action@v0.18.3
- name: Generate cxx_example from template/cxx
uses: cargo-generate/cargo-generate-action@v0.18.5
with:
name: ${{ env.PROJECT_NAME }}
subfolder: template/cxx
template_values_file: .github/workflows/template_values.toml
name: ${{ env.CXX_PROJECT_NAME }}
template: template/cxx
arguments: "--template-values-file .github/workflows/template_values.toml --verbose"

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.GH_EXAMPLE_DEPLOY_SECRET }}
external_repository: x-pt/${{ env.PROJECT_NAME }}
external_repository: x-pt/${{ env.CXX_PROJECT_NAME }}
publish_branch: main
publish_dir: ./${{ env.PROJECT_NAME }}
publish_dir: ./${{ env.CXX_PROJECT_NAME }}
# Set exclude_assets to empty for including the .github directory to deployment assets.
exclude_assets: ''
enable_jekyll: true
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
full_commit_message: "ci: :art: Cxx Sample"
force_orphan: true
example_go:
runs-on: ubuntu-latest
env:
GO_PROJECT_NAME: example_go
steps:
- uses: actions/checkout@v4

- name: Generate go_example from template/go
uses: cargo-generate/cargo-generate-action@v0.18.5
with:
name: ${{ env.GO_PROJECT_NAME }}
template: template/go
arguments: "--template-values-file .github/workflows/template_values.toml --verbose"

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.GH_EXAMPLE_DEPLOY_SECRET }}
external_repository: x-pt/${{ env.GO_PROJECT_NAME }}
publish_branch: main
publish_dir: ./${{ env.GO_PROJECT_NAME }}
# Set exclude_assets to empty for including the .github directory to deployment assets.
exclude_assets: ''
enable_jekyll: true
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
full_commit_message: "ci: :art: Go Sample"
force_orphan: true
example_py:
runs-on: ubuntu-latest
env:
PY_PROJECT_NAME: example_py
steps:
- uses: actions/checkout@v4

- name: Generate py_example from template/py
uses: cargo-generate/cargo-generate-action@v0.18.5
with:
name: ${{ env.PY_PROJECT_NAME }}
template: template/py
arguments: "--template-values-file .github/workflows/template_values.toml --verbose"

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.GH_EXAMPLE_DEPLOY_SECRET }}
external_repository: x-pt/${{ env.PY_PROJECT_NAME }}
publish_branch: main
publish_dir: ./${{ env.PY_PROJECT_NAME }}
# Set exclude_assets to empty for including the .github directory to deployment assets.
exclude_assets: ''
enable_jekyll: true
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
full_commit_message: "ci: :art: Py Sample"
force_orphan: true
20 changes: 15 additions & 5 deletions .github/workflows/template_values.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
[values]
gh_uname = "x-pt"
proj_description = "Example of Cxx GitHub template"
cmake_min_version = "3.20"

# cxx template values
cmake_min_version = "3.28"
cxx_proj_desc = "Example of Cxx GitHub template"
cxx_standard_version = "23"
cxx_standard_required = "OFF"
cxx_extensions = "OFF"
proj_type = "bin"
lib_type = "static"
bin_type = "static"
cxx_proj_type = "bin"
cxx_lib_type = "static"
cxx_bin_type = "static"

# go template values
go_proj_desc = "Example of Go GitHub template"
go_version = "1.21"

# python template values
py_proj_desc = "Example of Python GitHub template"
py_version = "3.12"
6 changes: 3 additions & 3 deletions template/cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ if(NOT MSVC)
endif()
endif()

{% if proj_type == "bin" -%}
{% if cxx_proj_type == "bin" -%}

add_executable(${PROJECT_NAME} ${SOURCES})

{% if bin_type == "static" -%}
{% if cxx_bin_type == "static" -%}

target_link_libraries(${PROJECT_NAME} PUBLIC "-static")

{%- endif %}

{%- elsif lib_type == "static" -%}
{%- elsif cxx_lib_type == "static" -%}

# static
add_library({{project-name}} src/library.cpp)
Expand Down
2 changes: 1 addition & 1 deletion template/cxx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ COPY . .
RUN cmake -B build && cmake --build build --target {{project-name}} --config Release --parallel 8

# DEPLOYING
{% if bin_type == "static" -%}
{% if cxx_bin_type == "static" -%}
FROM scratch
{%- else -%}
FROM rockylinux:9-minimal
Expand Down
12 changes: 6 additions & 6 deletions template/cxx/cargo-generate.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type = "string"
prompt = "GitHub username (or organization)?"
regex = "^[A-Za-z0-9][A-Za-z0-9-]{0,38}$"

[placeholders.proj_description]
[placeholders.cxx_proj_desc]
type = "string"
prompt = "Project description?"

Expand All @@ -32,26 +32,26 @@ prompt = "Enable compiler-specific features OR NOT?"
choices = ["ON", "OFF"]
default = "OFF"

[placeholders.proj_type]
[placeholders.cxx_proj_type]
type = "string"
prompt = "Which cxx project type?"
choices = ["bin", "lib"]
default = "bin"

[conditional.'proj_type == "bin"'.placeholders.bin_type]
[conditional.'cxx_proj_type == "bin"'.placeholders.cxx_bin_type]
type = "string"
prompt = "Which bin compile type?"
choices = ["static", "dynamic"]
default = "dynamic"

[conditional.'proj_type == "lib"'.placeholders.lib_type]
[conditional.'cxx_proj_type == "lib"'.placeholders.cxx_lib_type]
type = "string"
prompt = "Which lib type?"
choices = ["static", "shared"]
default = "shared"

[conditional.'proj_type == "bin"']
[conditional.'cxx_proj_type == "bin"']
ignore = ["src/library.h", "src/library.cpp"]

[conditional.'proj_type == "lib"']
[conditional.'cxx_proj_type == "lib"']
ignore = ["src/main.cpp", "Dockerfile", "docker-compose.yml", ".github/workflows/docker.yml"]
2 changes: 1 addition & 1 deletion template/go/cargo-generate.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type = "string"
prompt = "GitHub username (or organization)?"
regex = "^[A-Za-z0-9][A-Za-z0-9-]{0,38}$"

[placeholders.proj_desc]
[placeholders.go_proj_desc]
type = "string"
prompt = "Project description?"

Expand Down
2 changes: 1 addition & 1 deletion template/py/cargo-generate.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type = "string"
prompt = "GitHub username (or organization)?"
regex = "^[A-Za-z0-9][A-Za-z0-9-]{0,38}$"

[placeholders.proj_desc]
[placeholders.py_proj_desc]
type = "string"
prompt = "Project description?"

Expand Down

0 comments on commit dda9ba5

Please sign in to comment.