Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement CMake project #1

Merged
merged 21 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BasedOnStyle: Google
IndentWidth: 4
IncludeBlocks: Preserve
AllowShortFunctionsOnASingleLine: Empty
1 change: 1 addition & 0 deletions .distro/.fmf/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Empty file.
62 changes: 62 additions & 0 deletions .distro/cmake-template.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Name: cmake-template
Summary: CMake project template
Version: 0.0.0
Release: %autorelease
License: MIT
URL: https://github.com/LecrisUT/CMake-Template

Source: https://github.com/LecrisUT/CMake-Template/archive/refs/tags/v%{version}.tar.gz

BuildRequires: ninja-build
BuildRequires: cmake
BuildRequires: gcc-c++
BuildRequires: fmt-devel
BuildRequires: catch-devel
Requires: fmt

%description
CMake project template

%package devel
Summary: Development files for cmake-template
Requires: cmake-template%{?_isa} = %{version}-%{release}

%description devel
This package contains libraries and header files for developing
applications that use cmake-template.


%prep
%autosetup -n cmake-template-%{version}


%build
%cmake \
-DTEMPLATE_SHARED_LIBS=ON \
-DTEMPLATE_TESTS=ON
%cmake_build


%install
%cmake_install


%check
%ctest


%files
%doc README.md
%license LICENSE
%{_libdir}/libtemplate.so.*
%{_bindir}/hello

%files devel
%{_libdir}/libtemplate.so
%{_includedir}/template.h
%{_libdir}/cmake/Template
%{_libdir}/pkgconfig/template.pc


%changelog
%autochangelog
7 changes: 7 additions & 0 deletions .distro/plans/ctest.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
summary:
Test the bundled ctests
discover+:
how: fmf
path: test
execute:
how: tmt
4 changes: 4 additions & 0 deletions .distro/plans/main.fmf.dist-git
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
discover:
how: fmf
dist-git-source: true
dist-git-extract: cmake-template-*/
7 changes: 7 additions & 0 deletions .distro/plans/rpminspect.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plan:
import:
url: https://github.com/packit/tmt-plans
ref: main
name: /plans/rpminspect
environment:
RPMINSPECT_EXCLUDE: disttag
5 changes: 5 additions & 0 deletions .distro/plans/rpmlint.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
plan:
import:
url: https://github.com/packit/tmt-plans
ref: main
name: /plans/rpmlint
7 changes: 7 additions & 0 deletions .distro/plans/smoke.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
summary:
Basic smoke tests
discover:
how: fmf
filter: "tag: smoke"
execute:
how: tmt
9 changes: 9 additions & 0 deletions .distro/tests/smoke.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Common test variables
tag:
- smoke
tier: 0
path: /

# Define tests
/version:
test: hello
39 changes: 39 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI

on:
workflow_dispatch:
pull_request:
branches: [ main ]
push:
branches: [ main ]

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
pre-commit:
uses: ./.github/workflows/step_pre-commit.yaml

tests:
needs: [ pre-commit ]
uses: ./.github/workflows/step_test.yaml
Comment on lines +18 to +23
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal of these reusable CI is that they could be imported by other projects as well, assuming they have a similar structure, i.e. each project would only define the ci.yaml file and import the step workflows from (this) central project. I am planning to make one for executablebooks as well so they can have a centralized CI to manage.


static-analysis:
needs: [ pre-commit ]
uses: ./.github/workflows/step_static-analysis.yaml
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

pass:
needs: [ pre-commit, tests, static-analysis ]
runs-on: ubuntu-latest
steps:
- name: Check all CI jobs
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
if: always()
50 changes: 50 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: release
run-name: Release

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
- "v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+"

jobs:
tests:
uses: ./.github/workflows/step_test.yaml
pypi-wheel:
needs: [ tests ]
uses: ./.github/workflows/step_build-wheel.yaml
upload_pypi:
name: Upload to PyPI repository
needs: [ tests, pypi-wheel ]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/spglib/
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- name: Publish package to TestPyPI
if: ${{ contains(github.ref, 'rc') }}
# TODO: Maybe we can move this to main PyPI since it is marked rc
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository_url: https://test.pypi.org/legacy/
- name: Publish package to PyPI
if: ${{ !contains(github.ref, 'rc') }}
uses: pypa/gh-action-pypi-publish@release/v1
release:
needs: [ upload_pypi ]
name: Create release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: softprops/action-gh-release@v1
with:
name: Spglib ${{ github.ref_name }}
draft: true
prerelease: ${{ contains(github.ref, 'rc') }}
generate_release_notes: true
19 changes: 19 additions & 0 deletions .github/workflows/step_pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: pre-commit
run-name: Run pre-commits

on:
workflow_call:

permissions:
contents: read

jobs:
pre-commit:
name: Check pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: 3.x
- uses: pre-commit/[email protected]
37 changes: 37 additions & 0 deletions .github/workflows/step_static-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: static-analysis
on:
workflow_call:
secrets:
SONAR_TOKEN:
required: true
jobs:
sonar-cloud:
name: Analyze with SonarCloud
runs-on: ubuntu-latest
env:
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
steps:
- uses: actions/checkout@v4
- name: Set up Python for gcovr
uses: actions/setup-python@v4
with:
python-version: 3.x
- name: install gcovr
run: |
pip install gcovr
- name: Install sonar-scanner and build-wrapper
uses: SonarSource/sonarcloud-github-c-cpp@v2
- name: Run cmake/ctest with sonar build-wrapper
run: |
cmake --preset gcc-ci --fresh -G "Unix Makefiles"
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build --preset gcc-ci
ctest --preset gcc-ci
gcovr --sonarqube > coverage.xml
- name: Run sonar-scanner
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
sonar-scanner \
--define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" \
--define sonar.coverageReportPaths=coverage.xml
60 changes: 60 additions & 0 deletions .github/workflows/step_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: test
run-name: Run tests

on:
workflow_call:

permissions:
contents: read

jobs:
tests:
name: Check ${{ matrix.toolchain }} toolchain
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
container: ${{ !matrix.os && 'ghcr.io/lecrisut/dev-env:main' || '' }}
continue-on-error: ${{ matrix.experimental || false }}
strategy:
fail-fast: false
matrix:
toolchain: [ gcc, llvm, intel, windows, macos ]
include:
- os: windows-latest
toolchain: windows
experimental: true
- os: macos-latest
toolchain: macos
steps:
- name: Enable msvc toolchain on windows
uses: ilammy/msvc-dev-cmd@v1
if: contains(matrix.os, 'windows')
- name: Activate Intel compilers
run: |
source /opt/intel/oneapi/setvars.sh
printenv >> $GITHUB_ENV
echo $PATH >> $GITHUB_PATH
if: matrix.toolchain == 'intel'
- uses: actions/checkout@v4
- uses: lukka/get-cmake@latest
- name: Run CMake configuration for ${{ matrix.toolchain }} toolchain
uses: lukka/[email protected]
with:
workflowPreset: "${{ matrix.toolchain }}-ci"
- name: Get lcov data
run: |
lcov -c -d cmake-build-*/ -o coverage.info --include "$(pwd)/src/*"
# TODO: Disabled coverage on non-gcc toolchains. Not sure why it is broken
if: matrix.toolchain == 'gcc'
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: coverage.info
if: matrix.toolchain == 'gcc'
pass:
needs: [ tests ]
runs-on: ubuntu-latest
steps:
- name: Check test jobs
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
if: always()
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## CMake patterns
CMakeUserPresets.json
compile_commands.json

## Other common pattern
build/
# Jetbrains default
cmake-build-*/
Loading
Loading