Write a JSON manifest file for pushed artifacts #32
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: 'Emscripten' | |
| env: | |
| LIBRARIES_BRANCH: libraries-OS-COMPILER | |
| NCINE_BRANCH: nCine-BRANCH_NAME-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] | |
| runs-on: 'ubuntu-24.04' | |
| steps: | |
| - name: 'Checkout Code' | |
| uses: actions/checkout@v4 | |
| - name: 'Install Emscripten SDK' | |
| run: | | |
| sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10 | |
| cd .. | |
| git clone https://github.com/emscripten-core/emsdk.git | |
| cd emsdk | |
| ./emsdk install latest | |
| ./emsdk activate latest | |
| - name: 'Download nCine-libraries, nCine Artifacts, and project data' | |
| run: | | |
| OS=emscripten | |
| CC=emcc | |
| BRANCH_NAME=$(git describe --tags --exact-match 2> /dev/null || git symbolic-ref -q --short HEAD || git rev-parse --short HEAD) | |
| 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-emscripten .. | |
| cd .. | |
| rm -rf nCine-libraries-artifacts | |
| NCINE_SOURCE_BRANCH=`echo $NCINE_SOURCE_BRANCH | sed 's/BRANCH_NAME/'"$BRANCH_NAME"'/'` | |
| NCINE_BRANCH=`echo $NCINE_BRANCH | sed 's/BRANCH_NAME/'"$NCINE_SOURCE_BRANCH"'/'` | |
| NCINE_BRANCH=`echo $NCINE_BRANCH | sed 's/OS/'"$OS"'/'` | |
| NCINE_BRANCH=`echo $NCINE_BRANCH | sed 's/COMPILER/'"$CC"'/'` | |
| git clone https://github.com/nCine/nCine-artifacts.git | |
| cd nCine-artifacts | |
| git checkout $NCINE_BRANCH | |
| NCINE_FILE=$(ls -t nCine-* | head -n 1) | |
| tar xpzf $NCINE_FILE | |
| mv nCine-*-Emscripten ../nCine | |
| cd .. | |
| rm -rf nCine-artifacts | |
| git clone https://github.com/$GITHUB_REPOSITORY-data.git | |
| - name: 'CMake Configuration' | |
| run: | | |
| PROJECT_NAME=${GITHUB_REPOSITORY##*/} | |
| source ../emsdk/emsdk_env.sh | |
| NCINE_DIRECTORY=$(pwd)/../nCine/cmake | |
| if [[ "${{ matrix.BuildType }}" == "BinDist" ]]; then | |
| emcmake cmake -B ../$PROJECT_NAME-build-${{ matrix.BuildType }} -D NCPROJECT_OPTIONS_PRESETS=${{ matrix.BuildType }} -D nCine_DIR=$NCINE_DIRECTORY | |
| else | |
| emcmake cmake -B ../$PROJECT_NAME-build-${{ matrix.BuildType }} -D CMAKE_BUILD_TYPE=${{ matrix.BuildType }} -D nCine_DIR=$NCINE_DIRECTORY | |
| 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 }} | |
| path: ${{ github.event.repository.name }}-job-artifacts/* | |
| Artifacts: | |
| needs: Build | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| BuildType: [BinDist] | |
| runs-on: 'ubuntu-24.04' | |
| concurrency: | |
| group: artifacts-emscripten-emcc | |
| 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 }} | |
| 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=emscripten | |
| CC=emcc | |
| 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 |