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

Add: Install, Pack (windows) and Release workflow #28

Merged
merged 4 commits into from
Dec 13, 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
146 changes: 146 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: Release

on:
release:
types:
- published

jobs:
source:
name: Source

runs-on: ubuntu-20.04

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Generate .version
run: |
cmake -DWRITE_VERSION=1 -P generate_version.cmake

- name: Create bundles
run: |
FOLDER_NAME=grfcodec-${{ github.event.release.tag_name }}

# Rename the folder to grfcodec-NNN
mkdir ${FOLDER_NAME}
find . -maxdepth 1 -not -name . -not -name .git -not -name ${FOLDER_NAME} -exec mv {} ${FOLDER_NAME}/ \;

mkdir -p build/bundles

echo "::group::Create tarball (xz) bundle"
tar --xz -cvf build/bundles/${FOLDER_NAME}-source.tar.xz ${FOLDER_NAME}
echo "::endgroup::"

echo "::group::Create zip bundle"
zip -9 -r build/bundles/${FOLDER_NAME}-source.zip ${FOLDER_NAME}
echo "::endgroup::"

- name: Store bundles
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload ${{ github.event.release.tag_name }} build/bundles/*

windows:
needs: source

strategy:
fail-fast: false
matrix:
arch: [x86, x64]

name: Windows (${{ matrix.arch }})

runs-on: windows-latest

steps:
- name: Prepare build dir for gh usage
shell: bash
run: |
git init build
cd build
git remote add origin ${{ github.event.repository.html_url }}

- name: Download source
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
cd build
gh release download ${{ github.event.release.tag_name }} -p "*.xz" -D ..

- name: Unpack source
shell: bash
run: |
tar --xz -xf *-source.tar.xz --strip-components=1

- name: Prepare cache key
id: key
shell: powershell
run: |
# Work around caching failure with GNU tar
New-Item -Type Junction -Path vcpkg -Target c:\vcpkg

Write-Output "image=$env:ImageOS-$env:ImageVersion" >> $env:GITHUB_OUTPUT

- name: Enable vcpkg cache
uses: actions/cache@v3
with:
path: vcpkg/installed
key: ${{ steps.key.outputs.image }}-vcpkg-${{ matrix.arch }}-1 # Increase the number whenever dependencies are modified
restore-keys: |
${{ steps.key.outputs.image }}-vcpkg-${{ matrix.arch }}

- name: Prepare vcpkg
shell: bash
run: |
vcpkg install --triplet=${{ matrix.arch }}-windows-static \
boost-bimap \
boost-date-time \
boost-foreach \
libpng \
# EOF

- name: Install MSVC problem matcher
uses: ammaraskar/msvc-problem-matcher@master

- name: Configure developer command prompt for ${{ matrix.arch }}
uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.arch }}

- name: Build
shell: bash
run: |
cd build

echo "::group::CMake"
cmake .. \
-GNinja \
-DVCPKG_TARGET_TRIPLET=${{ matrix.arch }}-windows-static \
-DCMAKE_TOOLCHAIN_FILE="c:\vcpkg\scripts\buildsystems\vcpkg.cmake" \
-DCMAKE_BUILD_TYPE=Release \
# EOF
echo "::endgroup::"

echo "::group::Build"
cmake --build .
echo "::endgroup::"

- name: Create bundles
shell: bash
run: |
cd build
echo "::group::Run CPack"
cpack
echo "::endgroup::"

- name: Store bundles
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
cd build
gh release upload ${{ github.event.release.tag_name }} bundles/*
49 changes: 43 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ if(MINGW)
endif()


find_package(Git REQUIRED)
find_package(PNG)
find_package(Boost REQUIRED)

Expand Down Expand Up @@ -84,12 +83,10 @@ include_directories("${GENERATED_BINARY_DIR}")
# Target to generate version.h
add_custom_target(version_header
COMMAND ${CMAKE_COMMAND}
-D GIT_EXECUTABLE=${GIT_EXECUTABLE}
-D INPUT_FILE=${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in
-D OUTPUT_FILE=${GENERATED_BINARY_DIR}/version.h
-DGENERATED_BINARY_DIR=${GENERATED_BINARY_DIR}
-DCPACK_BINARY_DIR=${CMAKE_BINARY_DIR}
-P "${CMAKE_CURRENT_SOURCE_DIR}/generate_version.cmake"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/generate_version.cmake"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
BYPRODUCTS "${GENERATED_BINARY_DIR}/version.h"
)

Expand All @@ -115,6 +112,7 @@ add_custom_target(palettes_header
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/ttdpal.h.in"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/pal2c.cmake"
BYPRODUCTS "${GENERATED_BINARY_DIR}/ttdpal.h"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)


Expand Down Expand Up @@ -146,3 +144,42 @@ endif()

# Add source files
add_subdirectory(src)


# Install files
include(GNUInstallDirs)

install(TARGETS
grfid
grfstrip
nforenum
grfcodec
DESTINATION ${CMAKE_INSTALL_BINDIR}
)

install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/changelog.txt
${CMAKE_CURRENT_SOURCE_DIR}/COPYING
DESTINATION ${CMAKE_INSTALL_DOCDIR}
)

add_subdirectory(docs)


# CPack
if(WIN32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(ARCHITECTURE "win64")
else()
set(ARCHITECTURE "win32")
endif()

set(CPACK_SYSTEM_NAME "${ARCHITECTURE}")
set(CPACK_STRIP_FILES YES)
set(CPACK_OUTPUT_FILE_PREFIX "bundles")
set(CPACK_PACKAGE_FILE_NAME "grfcodec-#CPACK_PACKAGE_VERSION#-windows-${CPACK_SYSTEM_NAME}")

set(CPACK_GENERATOR "ZIP")

include(CPack)
endif()
5 changes: 5 additions & 0 deletions CPackProperties.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Make the current version available to CPack
set(CPACK_PACKAGE_VERSION "@GIT_VERSION@")

# Name the output file with the correct version
string(REPLACE "#CPACK_PACKAGE_VERSION#" "${CPACK_PACKAGE_VERSION}" CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}")
23 changes: 23 additions & 0 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.5)

install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/grfcodec.1
${CMAKE_CURRENT_SOURCE_DIR}/grfid.1
${CMAKE_CURRENT_SOURCE_DIR}/grfstrip.1
${CMAKE_CURRENT_SOURCE_DIR}/nforenum.1
DESTINATION ${CMAKE_INSTALL_MANDIR}
)

install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/auto_correct.txt
${CMAKE_CURRENT_SOURCE_DIR}/commands.txt
${CMAKE_CURRENT_SOURCE_DIR}/grf.txt
${CMAKE_CURRENT_SOURCE_DIR}/grfcodec.txt
${CMAKE_CURRENT_SOURCE_DIR}/grftut.txt
${CMAKE_CURRENT_SOURCE_DIR}/nforenum.txt
${CMAKE_CURRENT_SOURCE_DIR}/readme.rpn.txt
${CMAKE_CURRENT_SOURCE_DIR}/readme.txt
${CMAKE_CURRENT_SOURCE_DIR}/sanity.txt
${CMAKE_CURRENT_SOURCE_DIR}/todo.txt
DESTINATION ${CMAKE_INSTALL_DOCDIR}
)
52 changes: 37 additions & 15 deletions generate_version.cmake
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --dirty=M
OUTPUT_VARIABLE GIT_VERSION
RESULT_VARIABLE GIT_DESCRIBE_RESULT
ERROR_VARIABLE GIT_DESCRIBE_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
find_package(Git QUIET)

execute_process(
COMMAND ${GIT_EXECUTABLE} show -s --pretty=%cd --date=short HEAD
OUTPUT_VARIABLE GIT_DATE
RESULT_VARIABLE GIT_SHOW_RESULT
ERROR_VARIABLE GIT_SHOW_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# .git may be a directory or a regular file
if(GIT_FOUND AND EXISTS ".git")
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --always --dirty=M
OUTPUT_VARIABLE GIT_VERSION
RESULT_VARIABLE GIT_DESCRIBE_RESULT
ERROR_VARIABLE GIT_DESCRIBE_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
)

configure_file(${INPUT_FILE} ${OUTPUT_FILE})
execute_process(
COMMAND ${GIT_EXECUTABLE} show -s --pretty=%cd --date=short HEAD
OUTPUT_VARIABLE GIT_DATE
RESULT_VARIABLE GIT_SHOW_RESULT
ERROR_VARIABLE GIT_SHOW_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
elseif(EXISTS ".version")
file(READ ".version" GIT_VERSION)
string(REPLACE "\n" "" GIT_VERSION "${GIT_VERSION}")
string(REPLACE "\t" ";" GIT_VERSION "${GIT_VERSION}")
list(GET GIT_VERSION 1 GIT_DATE)
list(GET GIT_VERSION 0 GIT_VERSION)
else()
message(WARNING "No version detected")
set(GIT_VERSION "unknown")
set(GIT_DATE "unknown")
endif()

if(WRITE_VERSION)
file(WRITE .version "${GIT_VERSION}\t${GIT_DATE}\n")
else()
message(STATUS "Generating version.h")
configure_file("src/version.h.in" "${GENERATED_BINARY_DIR}/version.h")

message(STATUS "Generating CPackProperties.cmake")
configure_file("CPackProperties.cmake.in" "${CPACK_BINARY_DIR}/CPackProperties.cmake" @ONLY)
endif()
Loading