Skip to content

Commit

Permalink
feat(init): cargo generate cpp project
Browse files Browse the repository at this point in the history
  • Loading branch information
pplmx committed Sep 3, 2022
0 parents commit 7439531
Show file tree
Hide file tree
Showing 26 changed files with 1,446 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
# Check for updates every Monday
schedule:
interval: "weekly"
open-pull-requests-limit: 10
32 changes: 32 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build Template
on:
push:
branches:
- main
pull_request:

jobs:
build:
runs-on: ubuntu-latest
env:
PROJECT_NAME: cxx-gh-example
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Run cargo generate
uses: cargo-generate/cargo-generate-action@v0.16.0
with:
name: ${{ env.PROJECT_NAME }}
subfolder: template
template_values_file: .github/workflows/template_values.toml
# - name: Install Rust toolchain
# uses: actions-rs/toolchain@v1
# with:
# toolchain: stable
# profile: minimal
# override: true
- name: Move to temp folder
run: |
mv $PROJECT_NAME ${{ runner.temp }}/
cd ${{ runner.temp }}/$PROJECT_NAME
# cargo check --tests
67 changes: 67 additions & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Synchronize the example with the template
on:
push:
branches: [ main ]

jobs:
synchronize_example:
runs-on: ubuntu-latest
env:
PROJECT_NAME: cxx-gh-example
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Run cargo generate
uses: cargo-generate/cargo-generate-action@v0.16.0
with:
name: ${{ env.PROJECT_NAME }}
subfolder: template
template_values_file: .github/workflows/template_values.toml

- name: Checkout old example
uses: actions/checkout@v3
with:
repository: cxx-gh/cxx-gh-example
path: old_example
ssh-key: ${{ secrets.GH_EXAMPLE_DEPLOY_SECRET }}

- name: move sources, mit license and CMakeLists.txt from old to new example
run: |
echo "pwd:"
pwd
echo "ls -al:"
ls -al
rm cxx-gh-example/src/main.cpp
rm cxx-gh-example/CMakeLists.txt
rm cxx-gh-example/LICENSE-MIT
cp old_example/src/* cxx-gh-example/src/
cp old_example/CMakeLists.txt cxx-gh-example/CMakeLists.txt
cp old_example/LICENSE-MIT cxx-gh-example/LICENSE-MIT
- name: update example
run: |
mkdir old_sources
mv old_example/src/* old_sources
cd old_example
rm -rf * .gitignore .github/
echo "ls ../cxx-gh-example:"
ls ../cxx-gh-example
echo "ls ../cxx-gh-example/src:"
ls ../cxx-gh-example/src
mv ../cxx-gh-example/* ../cxx-gh-example/.github ../cxx-gh-example/.gitignore .
echo "ls -al:"
ls -al
rm src/*
mv ../old_sources/* src
- name: commit example
run: |
cd old_example
git config user.name github-actions
git config user.email github-actions@github.com
git add .
if [ -n "$(git status --porcelain)" ]; then
git commit -m "automatic update" -m "from $GITHUB_REPOSITORY@$GITHUB_SHA"
git push
else
echo "nothing to commit";
fi
5 changes: 5 additions & 0 deletions .github/workflows/template_values.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[values]
gh-username = "cxx-gh"
project-description = "Example of Cxx GitHub template"
cmake-min-version = "3.23"
cxx-standard = "23"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
.vscode
.DS_Store
35 changes: 35 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Contributing

First off, thank you for considering contributing to Cxx GitHub Template.

If your contribution is not straightforward, please first discuss the change you
wish to make by creating a new issue before making the change.

One of the project goals is to be easy to understand so, especially for GitHub
Actions, try to keep things simple and to add comments whenever this is not
possible.

## Reporting issues

Before reporting an issue on the
[issue tracker](https://github.com/cxx-gh/template/issues),
please check that it has not already been reported by searching for some related
keywords.

Try to use a clear title, and describe your problem with complete sentences.

## Pull requests

Try to do one pull request per change.

## GitHub Actions

When we have to mix GitHub actions variables with the `{{ }}` liquid syntax,
GitHub actions variable are written in the format
`{{ "{{ github.variable " }}}}` instead of `{{ github.variable }}`.

Of course, when doing `cargo generate` the ugly version is replaced with the
expected one.

See [Continuous delivery](https://github.com/cxx-gh/template/blob/main/.github/workflows/cd.yml)
as an example.
21 changes: 21 additions & 0 deletions LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Mystic

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Cxx GitHub Template

A template for [cargo generate](https://github.com/cargo-generate/cargo-generate) that aims to be a starting point suitable for
the vast majority of cpp projects that will be hosted on GitHub.

See the project [website](https://cxx-gh.github.io).
44 changes: 44 additions & 0 deletions template/.github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

## Bug description

<!-- A clear and concise description of what the bug is. -->

- Would you like to work on a fix? [y/n]

## To Reproduce

Steps to reproduce the behavior:

1. ...
2. ...
3. ...
4. ...

<!-- Make sure you are able to reproduce the bug in the main branch, too. -->

## Expected behavior

<!-- A clear and concise description of what you expected to happen. -->

## Screenshots

<!-- If applicable, add screenshots to help explain your problem. -->

## Environment

<!-- Please fill the following information. -->

- OS: [e.g. Ubuntu 20.04]
- {{project-name}} version: [e.g. 0.1.0]

## Additional context

<!-- Add any other context about the problem here. -->
1 change: 1 addition & 0 deletions template/.github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blank_issues_enabled: true
28 changes: 28 additions & 0 deletions template/.github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''

---

## Motivations

<!--
If your feature request is related to a problem, please describe it.
-->

- Would you like to implement this feature? [y/n]

## Solution

<!-- Describe the solution you'd like. -->

## Alternatives

<!-- Describe any alternative solutions or features you've considered. -->

## Additional context

<!-- Add any other context or screenshots about the feature request here. -->
12 changes: 12 additions & 0 deletions template/.github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- Please explain the changes you made -->

<!--
Please, make sure:
- you have read the contributing guidelines:
https://github.com/{{gh-username}}/{{project-name}}/blob/main/docs/CONTRIBUTING.md
- you have formatted the code using rustfmt:
https://github.com/rust-lang/rustfmt
- you have checked that all tests pass, by running `cargo test --all`
- you have updated the changelog (if needed):
https://github.com/{{gh-username}}/{{project-name}}/blob/main/CHANGELOG.md
-->
15 changes: 15 additions & 0 deletions template/.github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2
updates:
- package-ecosystem: "cargo"
# Look for `Cargo.toml` and `Cargo.lock` in the root directory
directory: "/"
# Check for updates every Monday
schedule:
interval: "weekly"
open-pull-requests-limit: 10
- package-ecosystem: "github-actions"
directory: "/"
# Check for updates every Monday
schedule:
interval: "weekly"
open-pull-requests-limit: 10
30 changes: 30 additions & 0 deletions template/.github/workflows/audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Security audit

on:
schedule:
# Runs at 00:00 UTC everyday
- cron: '0 0 * * *'
push:
paths:
- '**/Cargo.toml'
- '**/Cargo.lock'
pull_request:
{% raw %}
jobs:
audit:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Ensure that the latest version of Cargo is installed
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- uses: Swatinem/rust-cache@v1
- uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
{% endraw %}
Loading

0 comments on commit 7439531

Please sign in to comment.