Skip to content

Commit 885dc4c

Browse files
author
Vladyslav Rehan
committed
Try to add distribution management
1 parent 1357d13 commit 885dc4c

44 files changed

Lines changed: 1357 additions & 186 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/cd.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Continuous deployment
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v[0-9]+.[0-9]+.?[0-9]*.?[0-9]*'
7+
8+
jobs:
9+
build:
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
include:
15+
- os: ubuntu-latest
16+
script: ubuntu.sh
17+
- os: windows-latest
18+
script: windows.bat
19+
- os: macos-latest
20+
script: darwin.sh
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
submodules: true
26+
27+
- name: Build and deploy
28+
run: ./cicd/${{ matrix.script }} pack
29+
30+
- name: Upload
31+
uses: actions/upload-artifact@v4
32+
with:
33+
path: ./build/packaging/out/*
34+
name: ${{ matrix.os }}-packed-artifacts
35+
36+
release:
37+
runs-on: ubuntu-latest
38+
needs: build
39+
40+
steps:
41+
- name: Download artifacts
42+
uses: actions/download-artifact@v4
43+
with:
44+
merge-multiple: true
45+
path: packages
46+
47+
- name: Make release
48+
uses: softprops/action-gh-release@v2
49+
with:
50+
files: packages/*
51+
draft: false
52+
prerelease: false
53+
make_latest: true

.github/workflows/ci.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Continuous integration
2+
3+
on:
4+
push:
5+
branches: [ "develop" ]
6+
pull_request:
7+
branches: [ "develop" ]
8+
9+
jobs:
10+
build:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
include:
16+
- os: ubuntu-latest
17+
script: ubuntu.sh
18+
- os: windows-latest
19+
script: windows.bat
20+
- os: macos-latest
21+
script: darwin.sh
22+
steps:
23+
- uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
submodules: true
27+
28+
29+
- name: Build and test
30+
run: ./cicd/${{ matrix.script }} test

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "cmake/cmake-scripts"]
2+
path = cmake/cmake-scripts
3+
url = https://github.com/Dolfost/cmake-scripts.git

CMakeLists.txt

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,17 @@
1-
cmake_minimum_required(VERSION 3.12)
1+
cmake_minimum_required(VERSION 3.25)
22

3-
# project setup
4-
set(CMAKE_COLOR_DIAGNOSTICS ON)
5-
list(APPEND CMAKE_MESSAGE_CONTEXT "snake")
6-
project(snake
7-
LANGUAGES CXX)
3+
list(APPEND CMAKE_MODULE_PATH
4+
"${CMAKE_CURRENT_LIST_DIR}/cmake"
5+
)
86

9-
set (CMAKE_CXX_STANDARD 11)
7+
include(cmake-scripts/gitversion)
8+
gitversion()
109

11-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
10+
project(snake-cpp
11+
LANGUAGES CXX
12+
VERSION ${GIT_VERSION_TAG}
13+
)
1214

13-
set(datafolder "${CMAKE_SOURCE_DIR}/data")
14-
set(helpfile "${CMAKE_SOURCE_DIR}/data/help.pad.window")
15+
add_subdirectory(src)
1516

16-
# make target
17-
add_executable(snake
18-
./src/main.cpp)
19-
20-
# libraries
21-
file(GLOB coreSrc CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/src/include/core/*.cpp")
22-
add_library(snakecore
23-
${coreSrc})
24-
25-
file(GLOB gameSrc CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/src/include/game/*.cpp")
26-
add_library(snakegame
27-
${gameSrc})
28-
29-
file(GLOB snakeSrc CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/src/include/snake/*.cpp")
30-
add_library(snakesnake
31-
${snakeSrc})
32-
33-
# linking libs to game
34-
target_link_libraries(snake PRIVATE snakecore snakegame snakesnake ncurses)
35-
36-
37-
message(CHECK_START "Searching for data folder ${datafolder}")
38-
if (EXISTS ${datafolder})
39-
message(CHECK_PASS "found")
40-
else()
41-
message(CHECK_FAIL "not found. Creating it...")
42-
file(MAKE_DIRECTORY ${datafolder})
43-
endif()
44-
45-
message(CHECK_START "Searching for help file ${helpfile}")
46-
if (EXISTS ${helpfile})
47-
message(CHECK_PASS "found")
48-
else()
49-
message(CHECK_FAIL "not found. You should consider to generate it with ./build/snake --build-help-pad")
50-
endif()
17+
add_subdirectory(packaging)

cicd/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
##### Platform-agnostic CI/CD
2+
This is a platform-agnostic set of scripts for continuous integration and
3+
deployment. There is host-specific setup scripts in directory with this
4+
README.md which handle setting up the host system before calling CMake script
5+
in `cmake/<task>.cmake`. Each of setup scripts accepts one argument from shell,
6+
namely the task name. Then it examines it and decides what dependencies to
7+
install to satisfy `cmake/<task>.cmake` requirements and sets environment
8+
variable `REPO` to the full path to repository root and
9+
`TARTAN_CONFIGURATION_OPTIONS` to valid cmake configuration options.
10+
Corresponding CMake scripts use it for running commands.
11+
12+
###### Synopsis
13+
```
14+
ubuntu.sh <task>
15+
darwin.sh <task>
16+
windows.bat <task>
17+
```
18+
where `<task>` is in `cmake/<task>.cmake`.

cicd/cmake/pack.cmake

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
message("==>> Configuring...")
2+
execute_process( # configuration
3+
COMMAND "${CMAKE_COMMAND}" $ENV{CONFIGURATION_OPTIONS} -B build -S .
4+
-DCMAKE_BUILD_TYPE=Release
5+
WORKING_DIRECTORY "$ENV{REPO}"
6+
COMMAND_ERROR_IS_FATAL ANY
7+
)
8+
9+
file(MAKE_DIRECTORY "$ENV{REPO}/build")
10+
11+
message("==>> Building...")
12+
execute_process( # building
13+
COMMAND "${CMAKE_COMMAND}" --build build
14+
WORKING_DIRECTORY "$ENV{REPO}"
15+
COMMAND_ERROR_IS_FATAL ANY
16+
)
17+
18+
message("==>> Packaging for ${CMAKE_SYSTEM_NAME}...")
19+
execute_process( # test
20+
COMMAND "${CMAKE_CPACK_COMMAND}"
21+
WORKING_DIRECTORY "$ENV{REPO}/build"
22+
RESULT_VARIABLE CODE
23+
)

cicd/cmake/test.cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
message("==>> Configuring...")
2+
execute_process( # configuration
3+
COMMAND "${CMAKE_COMMAND}" $ENV{CONFIGURATION_OPTIONS} -B build -S .
4+
-DCMAKE_BUILD_TYPE=Release
5+
WORKING_DIRECTORY "$ENV{REPO}"
6+
COMMAND_ERROR_IS_FATAL ANY
7+
)
8+
9+
file(MAKE_DIRECTORY "$ENV{REPO}/build")
10+
11+
message("==>> Building...")
12+
execute_process( # building
13+
COMMAND "${CMAKE_COMMAND}" --build build
14+
WORKING_DIRECTORY "$ENV{REPO}"
15+
COMMAND_ERROR_IS_FATAL ANY
16+
)
17+
18+
message("==>> Testing...")
19+
execute_process( # test
20+
COMMAND "${CMAKE_CTEST_COMMAND}"
21+
WORKING_DIRECTORY "$ENV{REPO}/build"
22+
)
23+
24+
if(NOT ${CODE} STREQUAL "0")
25+
message(FATAL_ERROR "==>> Tests failed.")
26+
else()
27+
message("==>> Tests completed successfully!")
28+
endif()

cicd/darwin.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env sh
2+
3+
if [ -z "$1" ]; then
4+
echo "No operation specified!"
5+
exit 1
6+
fi
7+
8+
case "$1" in
9+
'docs'|'pack')
10+
brewformulas=" ncurses"
11+
brewcasks=""
12+
;;
13+
esac
14+
15+
# installing homebrew
16+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
17+
eval "$(/opt/homebrew/bin/brew shellenv)"
18+
19+
# installing dependencies
20+
brew install --formula cmake git $brewformulas
21+
brew install --cask $brewcasks
22+
23+
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
24+
export REPO="$SCRIPT_DIR/.."
25+
26+
cmake -P "$SCRIPT_DIR/cmake/$1.cmake"

cicd/ubuntu.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env sh
2+
3+
if [ -z "$1" ]; then
4+
echo "No operation specified!"
5+
exit 1
6+
fi
7+
8+
aptdeps="cmake git"
9+
case "$1" in
10+
'docs'|'pack')
11+
aptdeps="$aptdeps libncurses-dev"
12+
;;
13+
esac
14+
15+
# installing dependencies
16+
sudo apt install $aptdeps
17+
18+
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
19+
export REPO="$SCRIPT_DIR/.."
20+
21+
cmake -P "$SCRIPT_DIR/cmake/$1.cmake"

cicd/windows.bat

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
ECHO OFF
2+
3+
IF [%1] == [] ECHO "No operation specified!" & EXIT 1
4+
5+
REM install chocolatey
6+
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
7+
8+
REM figure out dependencies
9+
SET "chocodeps=mingw"
10+
REM install dependencies
11+
IF "%chocodeps%" == "" (
12+
ECHO "No packages specified to install."
13+
) ELSE (
14+
choco install %chocodeps%
15+
)
16+
17+
SET "SCRIPT_DIR=%~dp0"
18+
SET "REPO=%SCRIPT_DIR%.."
19+
SET "CONFIGURATION_OPTIONS=-G MinGW Makefiles"
20+
21+
cmake -P "%SCRIPT_DIR%cmake\%1.cmake"

0 commit comments

Comments
 (0)