Write a JSON manifest file for pushed artifacts #42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 'Linux' | |
| env: | |
| LIBRARIES_BRANCH: libraries-OS-COMPILER | |
| NCINE_SOURCE_BRANCH: BRANCH_NAME | |
| DEPLOY_MESSAGE: | | |
| Push artifact from GitHub Actions build ${{ github.run_number }} with id ${{ github.run_id }} | |
| - PROJECT_NAME artifact from branch 'BRANCH_NAME' with commit id ${{ github.sha }} | |
| DEPLOY_BRANCH: PROJECT_NAME-BRANCH_NAME-OS-COMPILER | |
| on: [push, workflow_dispatch] | |
| jobs: | |
| Build: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| BuildType: [Debug, Release, BinDist] | |
| compiler: [gcc, clang] | |
| include: | |
| - compiler: gcc | |
| CC: gcc | |
| CXX: g++ | |
| - compiler: clang | |
| CC: clang | |
| CXX: clang++ | |
| runs-on: 'ubuntu-24.04' | |
| steps: | |
| - name: 'Checkout Code' | |
| uses: actions/checkout@v4 | |
| - name: 'Install nCine Build Dependencies' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libgl1-mesa-dev libopengl-dev libegl1-mesa-dev libglvnd-dev libxext-dev libxrandr-dev libwayland-dev | |
| - name: 'Download nCine-libraries, pmTracer, and project data' | |
| run: | | |
| OS=linux | |
| CC=${{ matrix.CC }} | |
| LIBRARIES_BRANCH=`echo $LIBRARIES_BRANCH | sed 's/OS/'"$OS"'/'` | |
| LIBRARIES_BRANCH=`echo $LIBRARIES_BRANCH | sed 's/COMPILER/'"$CC"'/'` | |
| cd .. | |
| git clone https://github.com/nCine/nCine-libraries-artifacts.git | |
| cd nCine-libraries-artifacts | |
| git checkout $LIBRARIES_BRANCH | |
| LIBRARIES_FILE=$(ls -t | head -n 1) && tar xpzf $LIBRARIES_FILE | |
| mv nCine-external .. | |
| cd .. | |
| rm -rf nCine-libraries-artifacts | |
| git clone https://github.com/encelo/pmTracer.git | |
| git clone https://github.com/$GITHUB_REPOSITORY-data.git | |
| - name: 'Download nCine source and data' | |
| run: | | |
| BRANCH_NAME=$(git describe --tags --exact-match 2> /dev/null || git symbolic-ref -q --short HEAD || git rev-parse --short HEAD) | |
| NCINE_SOURCE_BRANCH=`echo $NCINE_SOURCE_BRANCH | sed 's/BRANCH_NAME/'"$BRANCH_NAME"'/'` | |
| cd .. | |
| git clone https://github.com/nCine/nCine-data.git | |
| git clone https://github.com/nCine/nCine.git --branch $NCINE_SOURCE_BRANCH | |
| - name: 'CMake Configuration and Make of nCine as a static library' | |
| run: | | |
| cd ../nCine | |
| if [[ "${{ matrix.BuildType }}" == "BinDist" ]]; then | |
| NCINE_BUILD_TYPE=Release | |
| else | |
| NCINE_BUILD_TYPE=${{ matrix.BuildType }} | |
| fi | |
| CMAKE_ARGS="-B ../nCine-build-$NCINE_BUILD_TYPE -D CMAKE_BUILD_TYPE=$NCINE_BUILD_TYPE -D NCINE_DYNAMIC_LIBRARY=OFF -D NCINE_PREFERRED_BACKEND=SDL2 -D NCINE_WITH_SCENEGRAPH=OFF -D NCINE_WITH_THREADS=ON -D NCINE_WITH_WEBP=OFF -D NCINE_WITH_AUDIO=OFF -D NCINE_WITH_SCRIPTING_API=OFF -D NCINE_BUILD_TESTS=OFF" | |
| export CC= ${{ matrix.CC }} | |
| export CXX=${{ matrix.CXX }} | |
| CMAKE_ARGS="$CMAKE_ARGS -D CMAKE_PREFIX_PATH=$(pwd)/../nCine-external" | |
| cmake $CMAKE_ARGS | |
| cd .. | |
| make -j $(getconf _NPROCESSORS_ONLN) -C nCine-build-$NCINE_BUILD_TYPE | |
| - name: 'CMake Configuration' | |
| run: | | |
| PROJECT_NAME=${GITHUB_REPOSITORY##*/} | |
| export CC= ${{ matrix.CC }} | |
| export CXX=${{ matrix.CXX }} | |
| if [[ "${{ matrix.BuildType }}" == "BinDist" ]]; then | |
| cmake -B ../$PROJECT_NAME-build-${{ matrix.BuildType }} -D PMTRACER_ROOT=$(pwd)/../pmTracer -D NCPROJECT_OPTIONS_PRESETS=${{ matrix.BuildType }} -D CMAKE_INSTALL_PREFIX="" -D nCine_DIR=$(pwd)/../nCine-build-Release -D CMAKE_PREFIX_PATH=$(pwd)/../nCine-external | |
| else | |
| cmake -B ../$PROJECT_NAME-build-${{ matrix.BuildType }} -D PMTRACER_ROOT=$(pwd)/../pmTracer -D CMAKE_BUILD_TYPE=${{ matrix.BuildType }} -D nCine_DIR=$(pwd)/../nCine-build-${{ matrix.BuildType }} -D CMAKE_PREFIX_PATH=$(pwd)/../nCine-external | |
| fi | |
| - name: 'Make' | |
| run: | | |
| PROJECT_NAME=${GITHUB_REPOSITORY##*/} | |
| make -j $(getconf _NPROCESSORS_ONLN) -C ../$PROJECT_NAME-build-${{ matrix.BuildType }} | |
| - name: 'Package' | |
| if: matrix.BuildType == 'BinDist' | |
| run: | | |
| PROJECT_NAME=${GITHUB_REPOSITORY##*/} | |
| make package -C ../$PROJECT_NAME-build-${{ matrix.BuildType }} | |
| - name: 'Prepare GitHub Actions Artifact' | |
| if: matrix.BuildType == 'BinDist' | |
| run: | | |
| PROJECT_NAME=${GITHUB_REPOSITORY##*/} | |
| cd ../$PROJECT_NAME-build-${{ matrix.BuildType }}/ | |
| echo -e "include(CPackConfig.cmake)\nexecute_process(COMMAND \${CMAKE_COMMAND} -E echo_append \"\${CPACK_PACKAGE_FILE_NAME}\")" > package_file_name.cmake | |
| PACKAGE_FILE_NAME=$(cmake -P package_file_name.cmake) | |
| PACKAGE_EXT=tar.gz | |
| PACKAGE="$PACKAGE_FILE_NAME.$PACKAGE_EXT" | |
| # Generate a JSON manifest file | |
| MANIFEST="manifest.json" | |
| SIZE=$(stat -c %s "$PACKAGE") | |
| MTIME=$(stat -c %y "$PACKAGE") | |
| MTIME_ISO=$(date -u -d "$MTIME" +"%Y-%m-%dT%H:%M:%SZ") | |
| SHA256=$(sha256sum "$PACKAGE" | awk '{print $1}') | |
| cat > "$MANIFEST" <<EOF | |
| { | |
| "filename": "$PACKAGE", | |
| "size": $SIZE, | |
| "timestamp": "$MTIME_ISO", | |
| "sha256": "$SHA256", | |
| "git_revision": "$GITHUB_SHA" | |
| } | |
| EOF | |
| ARTIFACTS_DIR="$GITHUB_WORKSPACE/$PROJECT_NAME-job-artifacts" | |
| mkdir -p $ARTIFACTS_DIR | |
| cp -p $PACKAGE $ARTIFACTS_DIR | |
| cp -p $MANIFEST $ARTIFACTS_DIR | |
| echo "Contents of the $PROJECT_NAME-job-artifacts directory:" | |
| ls -l $ARTIFACTS_DIR | |
| echo "Contents of the manifest file:" | |
| cat $MANIFEST | |
| - name: 'Upload GitHub Actions Artifact' | |
| if: matrix.BuildType == 'BinDist' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ github.event.repository.name }}-job-artifacts-${{ matrix.BuildType }}-${{ matrix.compiler }} | |
| path: ${{ github.event.repository.name }}-job-artifacts/* | |
| Artifacts: | |
| needs: Build | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| BuildType: [BinDist] | |
| compiler: [gcc, clang] | |
| include: | |
| - compiler: gcc | |
| CC: gcc | |
| CXX: g++ | |
| - compiler: clang | |
| CC: clang | |
| CXX: clang++ | |
| runs-on: 'ubuntu-24.04' | |
| concurrency: | |
| group: artifacts-linux-${{ matrix.compiler }} | |
| cancel-in-progress: false | |
| steps: | |
| - name: 'Checkout Code' | |
| uses: actions/checkout@v4 | |
| - name: 'Unshallow Git Repository for Versioning' | |
| run: | | |
| git fetch --unshallow || true | |
| - name: 'Download GitHub Actions Artifact' | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: ${{ github.event.repository.name }}-job-artifacts-${{ matrix.BuildType }}-${{ matrix.compiler }} | |
| path: ${{ github.event.repository.name }}-job-artifacts | |
| - name: 'Push Artifacts' | |
| env: | |
| PUBLIC_REPO_TOKEN: ${{ secrets.PUBLIC_REPO_TOKEN }} | |
| run: | | |
| git config --global user.email "actions@github.com" | |
| git config --global user.name "GitHub Actions" | |
| PROJECT_NAME=${GITHUB_REPOSITORY##*/} | |
| BRANCH_NAME=$(git describe --tags --exact-match 2> /dev/null || git symbolic-ref -q --short HEAD || git rev-parse --short HEAD) | |
| DEPLOY_MESSAGE=`sed 's/PROJECT_NAME/'"$PROJECT_NAME"'/' <<< "$DEPLOY_MESSAGE"` | |
| DEPLOY_MESSAGE=`sed 's/BRANCH_NAME/'"$BRANCH_NAME"'/' <<< "$DEPLOY_MESSAGE"` | |
| OS=linux | |
| CC=${{ matrix.CC }} | |
| cd $PROJECT_NAME-job-artifacts | |
| MANIFEST=$(ls manifest*.json) | |
| PACKAGE=$(jq -r '.filename' "$MANIFEST") | |
| cd .. | |
| DEPLOY_BRANCH=`echo $DEPLOY_BRANCH | sed 's/PROJECT_NAME/'"$PROJECT_NAME"'/'` | |
| DEPLOY_BRANCH=`echo $DEPLOY_BRANCH | sed 's/BRANCH_NAME/'"$BRANCH_NAME"'/'` | |
| DEPLOY_BRANCH=`echo $DEPLOY_BRANCH | sed 's/OS/'"$OS"'/'` | |
| DEPLOY_BRANCH=`echo $DEPLOY_BRANCH | sed 's/COMPILER/'"$CC"'/'` | |
| git clone https://$PUBLIC_REPO_TOKEN@github.com/$GITHUB_REPOSITORY-artifacts.git >/dev/null 2>&1 | |
| cd $PROJECT_NAME-artifacts | |
| git checkout $DEPLOY_BRANCH || git checkout --orphan $DEPLOY_BRANCH | |
| git reset | |
| git clean -f | |
| git rm * || true | |
| mv -f ../$PROJECT_NAME-job-artifacts/$MANIFEST . | |
| mv -f ../$PROJECT_NAME-job-artifacts/$PACKAGE . | |
| git add $MANIFEST $PACKAGE | |
| git commit --amend -m "$DEPLOY_MESSAGE" || git commit -m "$DEPLOY_MESSAGE" | |
| git push --force || git push --set-upstream origin $DEPLOY_BRANCH |