Linux fixes #1896
This file contains 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: build-emscripten | |
on: | |
push: | |
paths-ignore: | |
- '**/README.md' | |
pull_request: | |
paths-ignore: | |
- '**/README.md' | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
cancel-in-progress: true | |
env: | |
TARGET: "emscripten" | |
EMSDK_VERSION: "4.0.2" | |
USE_ARTIFACT: true | |
PTHREADS_ENABLED: 1 | |
DISABLE_WORKFLOW: "true" | |
jobs: | |
pre-check: | |
runs-on: ubuntu-latest | |
outputs: | |
workflow_disabled: ${{ steps.check-disabled.outputs.disabled }} | |
steps: | |
- name: Check if Workflow is disabled | |
id: check-disabled | |
shell: bash | |
run: | | |
if [ "${{ env.DISABLE_WORKFLOW }}" == "true" ]; then | |
echo "disabled=true" >> $GITHUB_ENV | |
echo "::set-output name=disabled::true" | |
else | |
echo "::set-output name=disabled::false" | |
fi | |
build-emscripten-platforms: | |
if: needs.pre-check.outputs.workflow_disabled != 'true' | |
needs: pre-check | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
ARCH: [32, 64] | |
steps: | |
- uses: actions/[email protected] | |
- name: Install Emscripten SDK (emsdk) | |
run: | | |
git clone https://github.com/emscripten-core/emsdk.git $HOME/emsdk | |
cd $HOME/emsdk | |
./emsdk install ${{ env.EMSDK_VERSION }} | |
./emsdk activate ${{ env.EMSDK_VERSION }} | |
echo "EMSDK_PATH=$HOME/emsdk" >> $GITHUB_ENV | |
echo "EMSCRIPTEN=$HOME/emsdk/upstream/emscripten" >> $GITHUB_ENV | |
echo 'export PATH="$HOME/emsdk:$HOME/emsdk/upstream/emscripten:$PATH"' >> $HOME/.bashrc | |
- name: Setup Emscripten Environment | |
run: | | |
source $HOME/emsdk/emsdk_env.sh | |
echo "Emscripten version: $(emcc --version)" | |
- name: Verify Emscripten Version | |
run: | | |
source $HOME/emsdk/emsdk_env.sh | |
emcc --version | |
- name: Setup Environment | |
run: | | |
echo "Setting up environment for Emscripten ${{ matrix.ARCH }} " | |
echo "ARCH=${{ matrix.ARCH }}" >> $GITHUB_ENV | |
- name: Scripts Calc Formula | |
run: ./scripts/calculate_formulas.sh | |
- name: Scripts Install | |
run: ./scripts/$TARGET/install.sh | |
- name: Determine Release | |
id: vars | |
shell: bash | |
run: | | |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then | |
echo "RELEASE=${{ github.ref_name }}" >> $GITHUB_ENV | |
elif [[ "${{ github.ref }}" == "refs/heads/master" ]]; then | |
echo "RELEASE=nightly" >> $GITHUB_ENV | |
elif [[ "${{ github.ref }}" == "refs/heads/bleeding" ]]; then | |
echo "RELEASE=latest" >> $GITHUB_ENV | |
else | |
echo "RELEASE=latest" >> $GITHUB_ENV | |
fi | |
- name: Download previous artifacts | |
uses: actions/github-script@v7 | |
if: env.USE_ARTIFACT == 'true' | |
with: | |
script: | | |
const fs = require('fs'); | |
const path = require('path'); | |
const outputDir = path.join(process.env.GITHUB_WORKSPACE, 'out'); | |
if (!fs.existsSync(outputDir)){ | |
fs.mkdirSync(outputDir); | |
} | |
const artifacts = await github.rest.actions.listArtifactsForRepo({ | |
owner: 'openframeworks', | |
repo: 'apothecary', | |
sort: 'created_at', | |
direction: 'desc', | |
per_page: 150 | |
}); | |
const target = process.env.TARGET; | |
const release = process.env.RELEASE; | |
const arch = process.env.ARCH; | |
const artifactName = `libs-${release}-${target}-${arch}`; | |
let count = 0; | |
const max = 1; | |
for (const artifact of artifacts.data.artifacts) { | |
const isArtifactMatch = artifact.name.includes(`libs-${release}-${target}-${arch}`) && !artifact.expired; | |
if (isArtifactMatch) { | |
const download = await github.rest.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: artifact.id, | |
archive_format: 'zip', | |
}); | |
const artifactPath = path.join(outputDir, `${artifact.name}.zip`); | |
fs.writeFileSync(artifactPath, Buffer.from(download.data)); | |
console.log(`Downloaded ${artifact.name} to ${artifactPath}`); | |
count++; | |
if (count >= max) { | |
break; | |
} | |
} | |
} | |
- name: Extract Artifacts to /out | |
if: env.USE_ARTIFACT == 'true' | |
run: | | |
mkdir -p out | |
if ls out/*.zip 1> /dev/null 2>&1; then | |
for zip in out/*.zip; do | |
echo "Extracting $zip..." | |
unzip -o "$zip" -d out/ | |
echo "Removing $zip..." | |
rm "$zip" | |
done | |
echo "First-level extraction and cleanup complete." | |
# Check and extract second-level zip files and remove them | |
if ls out/*.zip 1> /dev/null 2>&1; then | |
for nested_zip in out/*.zip; do | |
echo "Extracting nested zip $nested_zip..." | |
unzip -o "$nested_zip" -d out/ | |
echo "Removing $nested_zip..." | |
rm "$nested_zip" | |
done | |
echo "Second-level extraction and cleanup complete." | |
else | |
echo "No nested zip files found." | |
fi | |
else | |
echo "No zip files to extract." | |
fi | |
if ls out/*.tar.bz2 1> /dev/null 2>&1; then | |
for tarball in out/*.tar.bz2; do | |
echo "Extracting $tarball..." | |
tar -xjf "$tarball" -C out/ | |
done | |
echo ".tar.bz2 extraction complete." | |
rm -f out/*.tar.bz2 | |
else | |
echo "No .tar.bz2 files to extract." | |
fi | |
rm -f xout/*.tar.bz2 | |
rm -f out/*.tar.bz2 | |
- name: build | |
run: ./scripts/build.sh | |
env: | |
GA_CI_SECRET: ${{ secrets.CI_SECRET }} | |
ARCH: ${{ env.ARCH }} | |
- name: Package Binaries for Artifact | |
if: github.repository == 'openframeworks/apothecary' && github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/bleeding') && env.USE_ARTIFACT == 'true' | |
working-directory: ${{ env.GITHUB_WORKSPACE }} | |
run: | | |
scripts/artifact/artifact.sh | |
env: | |
ARCH: ${{ env.ARCH }} | |
- name: Upload Artifact | |
if: github.repository == 'openframeworks/apothecary' && github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/bleeding') && env.USE_ARTIFACT == 'true' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: libs-${{ env.RELEASE }}-emscripten-${{ env.ARCH }} | |
path: out/${{ env.FILENAME }} | |
retention-days: 31 | |
- name: Remove .tar.bz2 files | |
if: github.repository == 'openframeworks/apothecary' && github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/bleeding' || contains(github.ref, 'refs/tags/')) | |
run: | | |
echo "Removing .tar.bz2 files from out/ directory..." | |
rm -f out/*.tar.bz2 | |
rm -f xout/*.tar.bz2 | |
echo "Cleanup complete." | |
- name: Package | |
if: github.repository == 'openframeworks/apothecary' && github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/bleeding' || contains(github.ref, 'refs/tags/')) | |
working-directory: ${{ env.GITHUB_WORKSPACE }} | |
run: | | |
scripts/package.sh | |
env: | |
GA_CI_SECRET: ${{ secrets.CI_SECRET }} | |
ARCH: ${{ env.ARCH }} | |
- name: List output directory final | |
run: ls -lah out/ | |
- name: Update Release | |
if: github.repository == 'openframeworks/apothecary' && github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/bleeding') | |
uses: softprops/[email protected] | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
tag_name: ${{ env.RELEASE }} | |
files: out/openFrameworksLibs_${{ env.RELEASE }}_${{ env.TARGET }}_${{ env.ARCH }}.tar.bz2 | |
- name: Clean for | |
if: github.repository == 'openframeworks/apothecary' && github.event_name == 'push' | |
run: | | |
rm -f out/openFrameworksLibs_${{ env.RELEASE }}_${{ env.TARGET }}_${{ env.ARCH }}.tar.bz2 | |
- name: Package | |
if: github.repository == 'openframeworks/apothecary' && github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/bleeding' || contains(github.ref, 'refs/tags/')) | |
working-directory: ${{ env.GITHUB_WORKSPACE }} | |
run: | | |
scripts/package-individual.sh | |
env: | |
GA_CI_SECRET: ${{ secrets.CI_SECRET }} | |
ARCH: ${{ env.ARCH }} | |
- name: Upload to GitHub Release | |
if: github.repository == 'openframeworks/apothecary' && github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/bleeding') | |
uses: softprops/[email protected] | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
tag_name: "latest-modular" | |
files: out/*.tar.bz2 out/*.zip | |