Skip to content

Commit

Permalink
Added a github action to archive the library
Browse files Browse the repository at this point in the history
  • Loading branch information
nessan committed Jul 26, 2024
1 parent 0c83e04 commit 79e19d1
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 16 deletions.
6 changes: 0 additions & 6 deletions .editorconfig

This file was deleted.

56 changes: 56 additions & 0 deletions .github/workflows/archive.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Creates & releases a minimal archive of this library's core files and directories.
# This is useful for the standard CMake module `FetchContent` and friends.
name: Release library archive

# The files & directories we archive and the name for the archive.
# The git tag for the release is either 'current' or the relase tag like '2.1.2'
env:
archive_content: LICENSE CMakeLists.txt include
archive_name: ${{ github.event.repository.name }}.zip
archive_tag: ${{github.ref == 'refs/heads/main' && 'current' || github.ref}}

# We may overwrite the $archive_tag so need write permissions
permissions:
contents: write

# When is the workflow run?
on:
# Any push to the main branch that changes the content of the archive.
# TODO: Perhaps we can use the $archive_content variable here?
push:
branches:
- main
paths:
- "LICENSE"
- "CMakeLists.txt"
- "include/**"
# Any formal release
release:
types: [published]

# You can trigger the workflow manually (handy to debug the workflow).
workflow_dispatch:

# There is just a single job in the workflow
jobs:
archive:
name: Create and release an archive of the library's core files and directories.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Zip the important files and directories
run: |
echo "Creating archive '$archive_name' from: '$archive_content' ..."
echo "The git ref is: '${{github.ref}}'"
echo "The release tag: '${{env.archive_tag}}'"
zip -r $archive_name $archive_content
- name: Upload the archive to a release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{secrets.GITHUB_TOKEN}}
file: ${{env.archive_name}}
tag: ${{env.archive_tag}}
overwrite: true
body: "Latest minimal version of the library for CMake's module `FetchContent` and friends."
20 changes: 10 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
cmake_minimum_required(VERSION 3.24)

# Our C++ project ...
project(bit DESCRIPTION "C++ classes for linear algebra over GF(2)" LANGUAGES CXX)
project(bit DESCRIPTION "C++ classes for working in GF(2)" LANGUAGES CXX)

# Add a target for the "library" we are building (bit is header only -- hence INTERFACE)
# Also add an alias that prepends a "namespace" -- if clients use that to link to, they get better error messages
# Add a target for the "library" we are building (bit is header only -- hence INTERFACE).
# Also add an alias that prepends a "namespace" -- if clients use that to link to, they get better error messages.
add_library(bit INTERFACE)
add_library(bit::bit ALIAS bit)

# We use some C++20 features
# We use some C++20 features.
target_compile_features(bit INTERFACE cxx_std_20)

# Where to find the bit headers (e.g., how to resolve `#include <bit/bit.h>`).
target_include_directories(bit INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/>
$<INSTALL_INTERFACE:include/bit>)

# That's it unless we are developing the library instead of just using it!
# That's it unless we are developing the library instead of just using it.
if (PROJECT_IS_TOP_LEVEL)

# Append our local directory of CMake modules to the default ones searched by CMake
# Append our local directory of CMake modules to the default ones searched by CMake.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

# Prevent in-source builds for the example programs
# Prevent in-source builds for the example programs.
include(disable_in_source_builds)
disable_in_source_builds()

Expand All @@ -33,16 +33,16 @@ if (PROJECT_IS_TOP_LEVEL)
# Debug builds get the BIT_DEBUG flag set otherwise we set the BIT_NDEBUG flag
target_compile_definitions(bit INTERFACE $<IF:$<CONFIG:Debug>, BIT_DEBUG=1, BIT_NDEBUG=1>)

# For neatness, we want all the example executables to go in build/bin/.
# For neatness, we put the example executables in build/bin/.
include(GNUInstallDirs)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}")

# Our example programs also make use of our header-only utilities library.
# Our example programs use the header-only `utilities` library.
include(FetchContent)
FetchContent_Declare(utilities URL https://github.com/nessan/utilities/releases/download/current/utilities.zip)
FetchContent_MakeAvailable(utilities)

# Finally, we walk through the examples/ directory and build a target for each .cpp file with appropriate linkage.
# Walk through the examples/ directory and build a target for each .cpp file with appropriate linkage.
# We have a CMake module that makes that traversal straightforward.
include(add_executables)
add_executables(examples bit::bit utilities::utilities)
Expand Down

0 comments on commit 79e19d1

Please sign in to comment.