Skip to content

Commit

Permalink
Refactoring Github Workflows
Browse files Browse the repository at this point in the history
Signed-off-by: Thibault Meyer <[email protected]>
  • Loading branch information
thibaultmeyer committed Oct 10, 2021
1 parent 2991c4c commit 56009f0
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 32 deletions.
29 changes: 4 additions & 25 deletions .github/workflows/cmake-debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@ name: CMake
on: [ push ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Debug

jobs:
build-linux:
name: Linux

# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest

strategy:
matrix:
target_arch: [ aarch64, arm, ppc64le, s390x, i686, x86_64 ]
target_arch: [ x86_64 ]

steps:
- name: Clone repository
Expand All @@ -27,35 +22,26 @@ jobs:
- name: Create Build Environment
run: |
sudo apt-get install valgrind libcunit1-dev
# Some projects don't allow in-source building, so create a separate build directory
# We'll use this as our working directory for all subsequent commands
cmake -E make_directory ${{github.workspace}}/build
- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
shell: bash
working-directory: ${{github.workspace}}/build
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE

- name: Build
working-directory: ${{github.workspace}}/build
shell: bash
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build . --config $BUILD_TYPE

- name: Test (With Valgrind)
working-directory: ${{github.workspace}}/build
shell: bash
# Execute the build. You can specify a specific target with "--target <NAME>"
run: VALGRIND_OPTS='--leak-check=full --leak-resolution=med --track-origins=yes --show-leak-kinds=all --vgdb=no' valgrind ./lib-snowflakeid-test SINGLE

- name: Test (Performance)
working-directory: ${{github.workspace}}/build
shell: bash
# Execute the build. You can specify a specific target with "--target <NAME>"
run: |
./lib-snowflakeid-test PERFORMANCE 5000
./lib-snowflakeid-test PERFORMANCE 100000
Expand All @@ -76,18 +62,11 @@ jobs:
uses: actions/checkout@v2

- name: Create Build Environment
run: |
# Some projects don't allow in-source building, so create a separate build directory
# We'll use this as our working directory for all subsequent commands
cmake -E make_directory ${{github.workspace}}/build
run: cmake -E make_directory ${{github.workspace}}/build

- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
shell: bash
working-directory: ${{github.workspace}}/build
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE

- name: Build
Expand Down
143 changes: 143 additions & 0 deletions .github/workflows/package-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
name: Package

on:
release:
types: [published]

env:
BUILD_TYPE: Release

jobs:
build-linux-ubuntu:
name: Ubuntu

runs-on: ubuntu-latest

steps:
- name: Clone repository
uses: actions/checkout@v2

- name: Create Build Environment
run: |
sudo apt-get update
sudo apt-get install jq \
gcc-aarch64-linux-gnu \
gcc-s390x-linux-gnu \
gcc-s390x-linux-gnu \
gcc-arm-linux-gnueabi \
gcc-arm-linux-gnueabihf
- name: DEB (x86_64)
shell: bash
run: |
mkdir -p ${{github.workspace}}/build-release-x86_64
cd ${{github.workspace}}/build-release-x86_64
cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_DEB=YES
cmake --build . --config $BUILD_TYPE
make package
- name: DEB (aarch64)
shell: bash
run: |
mkdir -p ${{github.workspace}}/build-release-aarch64
cd ${{github.workspace}}/build-release-aarch64
cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_DEB=YES -DARCHITECTURE=aarch64 -DCMAKE_C_COMPILER=/usr/bin/aarch64-linux-gnu-gcc
cmake --build . --config $BUILD_TYPE
make package
- name: DEB (s390x)
shell: bash
run: |
mkdir -p ${{github.workspace}}/build-release-s390x
cd ${{github.workspace}}/build-release-s390x
cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_DEB=YES -DARCHITECTURE=s390x -DCMAKE_C_COMPILER=/usr/bin/s390x-linux-gnu-gcc
cmake --build . --config $BUILD_TYPE
make package
- name: DEB (armel)
shell: bash
run: |
mkdir -p ${{github.workspace}}/build-release-armel
cd ${{github.workspace}}/build-release-armel
cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_DEB=YES -DARCHITECTURE=armel -DCMAKE_C_COMPILER=/usr/bin/arm-linux-gnueabi-gcc
cmake --build . --config $BUILD_TYPE
make package
- name: DEB (armhf)
shell: bash
run: |
mkdir -p ${{github.workspace}}/build-release-armhf
cd ${{github.workspace}}/build-release-armhf
cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_DEB=YES -DARCHITECTURE=armhf -DCMAKE_C_COMPILER=/usr/bin/arm-linux-gnueabihf-gcc
cmake --build . --config $BUILD_TYPE
make package
- name: Upload Generated DEB files to Release
shell: bash
run: |
export RELEASE_ID=`curl -H "Authorization: Bearer ${{secrets.GITHUB_TOKEN}}" https://api.github.com/repos/thibaultmeyer/libsnowflakeid/releases | jq '.[].id' | head -n1`
export FILE=`ls ${{github.workspace}}/build-release-x86_64/*.deb`
export FILE_BASENAME=`basename $FILE`
export FILE_SIZE=`find $FILE -printf "%s"`
curl --request POST -H "Authorization: Bearer ${{secrets.GITHUB_TOKEN}}" -H "Content-Type: application/octet-stream" -H "Content-Length: $FILE_SIZE" \
--data-binary @$FILE "https://uploads.github.com/repos/thibaultmeyer/libsnowflakeid/releases/$RELEASE_ID/assets?name=$FILE_BASENAME"
export FILE=`ls ${{github.workspace}}/build-release-aarch64/*.deb`
export FILE_BASENAME=`basename $FILE`
export FILE_SIZE=`find $FILE -printf "%s"`
curl --request POST -H "Authorization: Bearer ${{secrets.GITHUB_TOKEN}}" -H "Content-Type: application/octet-stream" -H "Content-Length: $FILE_SIZE" \
--data-binary @$FILE "https://uploads.github.com/repos/thibaultmeyer/libsnowflakeid/releases/$RELEASE_ID/assets?name=$FILE_BASENAME"
export FILE=`ls ${{github.workspace}}/build-release-s390x/*.deb`
export FILE_BASENAME=`basename $FILE`
export FILE_SIZE=`find $FILE -printf "%s"`
curl --request POST -H "Authorization: Bearer ${{secrets.GITHUB_TOKEN}}" -H "Content-Type: application/octet-stream" -H "Content-Length: $FILE_SIZE" \
--data-binary @$FILE "https://uploads.github.com/repos/thibaultmeyer/libsnowflakeid/releases/$RELEASE_ID/assets?name=$FILE_BASENAME"
export FILE=`ls ${{github.workspace}}/build-release-armel/*.deb`
export FILE_BASENAME=`basename $FILE`
export FILE_SIZE=`find $FILE -printf "%s"`
curl --request POST -H "Authorization: Bearer ${{secrets.GITHUB_TOKEN}}" -H "Content-Type: application/octet-stream" -H "Content-Length: $FILE_SIZE" \
--data-binary @$FILE "https://uploads.github.com/repos/thibaultmeyer/libsnowflakeid/releases/$RELEASE_ID/assets?name=$FILE_BASENAME"
export FILE=`ls ${{github.workspace}}/build-release-armhf/*.deb`
export FILE_BASENAME=`basename $FILE`
export FILE_SIZE=`find $FILE -printf "%s"`
curl --request POST -H "Authorization: Bearer ${{secrets.GITHUB_TOKEN}}" -H "Content-Type: application/octet-stream" -H "Content-Length: $FILE_SIZE" \
--data-binary @$FILE "https://uploads.github.com/repos/thibaultmeyer/libsnowflakeid/releases/$RELEASE_ID/assets?name=$FILE_BASENAME"
build-linux-centos:
name: CentOS

runs-on: ubuntu-latest
container: 'centos:latest'

steps:
- name: Clone repository
uses: actions/checkout@v2

- name: Create Build Environment
run: |
dnf -y group install "Development Tools"
dnf -y install jq gcc cmake
- name: RPM (x86_64)
shell: bash
run: |
mkdir -p ${{github.workspace}}/build-release-x86_64
cd ${{github.workspace}}/build-release-x86_64
cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_RPM=YES
cmake --build . --config $BUILD_TYPE
make package
- name: Upload Generated RPM file to Release
shell: bash
run: |
export RELEASE_ID=`curl -H "Authorization: Bearer ${{secrets.GITHUB_TOKEN}}" https://api.github.com/repos/thibaultmeyer/libsnowflakeid/releases | jq '.[].id' | head -n1`
export FILE=`ls ${{github.workspace}}/build-release-x86_64/*.rpm`
export FILE_BASENAME=`basename $FILE`
export FILE_SIZE=`find $FILE -printf "%s"`
curl --request POST -H "Authorization: Bearer ${{secrets.GITHUB_TOKEN}}" -H "Content-Type: application/octet-stream" -H "Content-Length: $FILE_SIZE" \
--data-binary @$FILE "https://uploads.github.com/repos/thibaultmeyer/libsnowflakeid/releases/$RELEASE_ID/assets?name=$FILE_BASENAME"
22 changes: 15 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,24 @@ INSTALL(TARGETS lib-snowflakeid-shared ARCHIVE DESTINATION lib LIBRARY DESTINATI
INSTALL(FILES ${CMAKE_SOURCE_DIR}/inc/snowflakeid.h DESTINATION include)

# Current architecture/operating system
IF (NOT DEFINED ARCHITECTURE)
EXEC_PROGRAM("uname -m" OUTPUT_VARIABLE ARCHITECTURE)
IF (LINUX)
EXEC_PROGRAM("awk -F= '$1==\"ID\" { print $2 ;}' /etc/os-release" OUTPUT_VARIABLE OPERATING_SYSTEM)
ENDIF(LINUX)
ENDIF(NOT DEFINED ARCHITECTURE)

IF (APPLE)
SET(OPERATING_SYSTEM "macos")
EXEC_PROGRAM("sw_vers -productVersion" OUTPUT_VARIABLE OPERATING_SYSTEM_VERSION)
SET(OPERATING_SYSTEM "macos_${OPERATING_SYSTEM_VERSION}")
ELSE()
IF (WIN32)
SET(OPERATING_SYSTEM "windows")
ELSE()
EXEC_PROGRAM("awk -F= '$1==\"ID\" { print $2 ;}' /etc/os-release" OUTPUT_VARIABLE OPERATING_SYSTEM)
EXEC_PROGRAM("awk -F= '$1==\"VERSION_ID\" { print $2 ;}' /etc/os-release" OUTPUT_VARIABLE OPERATING_SYSTEM_VERSION)

STRING(CONCAT OPERATING_SYSTEM ${OPERATING_SYSTEM} "_" ${OPERATING_SYSTEM_VERSION})
STRING(REPLACE "\"" "" OPERATING_SYSTEM ${OPERATING_SYSTEM})
ENDIF(WIN32)
ENDIF(APPLE)
IF (WIN32)
SET(OPERATING_SYSTEM "windows")
ENDIF(WIN32)

MESSAGE(STATUS "Architecture: ${ARCHITECTURE}")
MESSAGE(STATUS "Operating System: ${OPERATING_SYSTEM}")
Expand Down

0 comments on commit 56009f0

Please sign in to comment.