Build and Extract JSON #516
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: Build and Extract JSON | |
| on: | |
| schedule: | |
| - cron: "0 22 * * *" | |
| workflow_dispatch: | |
| inputs: | |
| runner: | |
| type: choice | |
| options: | |
| - ubuntu-24.04 | |
| - ubicloud-standard-16-ubuntu-2404 | |
| - ubicloud-standard-30-ubuntu-2404 | |
| default: ubuntu-24.04 | |
| description: The runner for this action | |
| required: true | |
| slicer: | |
| type: choice | |
| options: | |
| - all | |
| - OrcaSlicer | |
| - PrusaSlicer | |
| - BambuStudio | |
| - ElegooSlicer | |
| - QIDIStudio | |
| - CrealityPrint | |
| - AnycubicSlicerNext | |
| default: all | |
| description: Slicer to dump configs for | |
| required: true | |
| build-type: | |
| type: choice | |
| options: | |
| - all | |
| - nightly | |
| - latest_release | |
| default: all | |
| description: Build type to run | |
| required: true | |
| release-tag: | |
| type: string | |
| default: '' | |
| description: Optional release tag override for testing one version | |
| required: false | |
| disable-caching: | |
| type: boolean | |
| default: false | |
| description: Disable caching | |
| force-latest-release-rebuild: | |
| type: boolean | |
| default: false | |
| description: Force rebuilding latest_release even when the tag was already built | |
| permissions: | |
| contents: write | |
| jobs: | |
| build_slicers: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| slicer: | |
| - OrcaSlicer | |
| - PrusaSlicer | |
| - BambuStudio | |
| - ElegooSlicer | |
| # - QIDIStudio | |
| - CrealityPrint | |
| build-type: | |
| - nightly | |
| - latest_release | |
| include: | |
| - slicer: OrcaSlicer | |
| repo: OrcaSlicer/OrcaSlicer | |
| release_tag: '' | |
| - slicer: PrusaSlicer | |
| repo: prusa3d/PrusaSlicer | |
| release_tag: version_2.9.3 | |
| - slicer: BambuStudio | |
| repo: BambuLab/BambuStudio | |
| release_tag: v02.05.00.67 | |
| - slicer: ElegooSlicer | |
| repo: ELEGOO-3D/ElegooSlicer | |
| release_tag: '' | |
| # - slicer: QIDIStudio | |
| # repo: QIDITECH/QIDISlicer | |
| - slicer: CrealityPrint | |
| repo: CrealityOfficial/CrealityPrint | |
| release_tag: '' | |
| - slicer: AnycubicSlicerNext | |
| repo: ANYCUBIC-3D/AnycubicSlicerNext | |
| release_tag: '' | |
| runs-on: ${{ inputs.runner || 'ubuntu-24.04' }} | |
| env: | |
| DEPS_CACHE_KEY: '' | |
| BUILD_CACHE_REF: '' | |
| continue_build: 'true' | |
| latest_release_at_head: 'false' | |
| steps: | |
| - name: Apply dispatch filters | |
| run: | | |
| selected_slicer="${{ inputs.slicer || 'all' }}" | |
| selected_build_type="${{ inputs.build-type || 'all' }}" | |
| if [[ "$selected_slicer" != "all" && "$selected_slicer" != "${{ matrix.slicer }}" ]]; then | |
| echo "Skipping ${{ matrix.slicer }} because slicer filter is $selected_slicer." | |
| echo "continue_build=false" >> "$GITHUB_ENV" | |
| exit 0 | |
| fi | |
| if [[ "$selected_build_type" != "all" && "$selected_build_type" != "${{ matrix.build-type }}" ]]; then | |
| echo "Skipping ${{ matrix.build-type }} because build-type filter is $selected_build_type." | |
| echo "continue_build=false" >> "$GITHUB_ENV" | |
| exit 0 | |
| fi | |
| - name: Checkout repository | |
| if: env.continue_build == 'true' | |
| uses: actions/checkout@v4 | |
| - name: Setup | |
| if: env.continue_build == 'true' | |
| run: | | |
| set -euo pipefail | |
| git clone https://github.com/${{ matrix.repo }} slicer-src --depth 1 -- | |
| latest_release_tag="${{ inputs.release-tag || matrix.release_tag }}" | |
| if [[ -z "$latest_release_tag" ]]; then | |
| latest_release_json=$(curl -fsSL "https://api.github.com/repos/${{ matrix.repo }}/releases/latest") | |
| latest_release_tag=$(echo "$latest_release_json" | jq -r '.tag_name') | |
| else | |
| latest_release_json=$(curl -fsSL "https://api.github.com/repos/${{ matrix.repo }}/releases/tags/${latest_release_tag}" || echo '{}') | |
| fi | |
| latest_release_hash=$(curl -fsSL "https://api.github.com/repos/${{ matrix.repo }}/commits/refs/tags/${latest_release_tag}" | jq -r '.sha') | |
| upstream_published_at=$(echo "$latest_release_json" | jq -r '.published_at // empty') | |
| head_hash=$(curl -fsSL "https://api.github.com/repos/${{ matrix.repo }}/commits/HEAD" | jq -r '.sha') | |
| latest_stored_tag=$(jq -r '.latest // empty' "slicers/${{ matrix.slicer }}/out/_index.json" 2>/dev/null || true) | |
| release_config_present=$(jq -r --arg tag "$latest_release_tag" '(.versions[$tag].config? != null)' "slicers/${{ matrix.slicer }}/out/_index.json" 2>/dev/null || echo false) | |
| echo latest_release_tag=$latest_release_tag | |
| echo latest_release_hash=$latest_release_hash | |
| echo latest_stored_tag=$latest_stored_tag | |
| echo release_config_present=$release_config_present | |
| echo upstream_published_at=$upstream_published_at | |
| echo head_hash=$head_hash | |
| echo "latest_release_tag=$latest_release_tag" >> "$GITHUB_ENV" | |
| echo "latest_release_hash=$latest_release_hash" >> "$GITHUB_ENV" | |
| echo "upstream_published_at=$upstream_published_at" >> "$GITHUB_ENV" | |
| echo "head_hash=$head_hash" >> "$GITHUB_ENV" | |
| if [[ "$release_config_present" != "true" ]] || [[ "${{ inputs.force-latest-release-rebuild || false }}" == "true" ]]; then | |
| git -C slicer-src fetch origin refs/tags/$latest_release_tag | |
| if [[ "$head_hash" == "$latest_release_hash" ]]; then | |
| echo "Latest release found at HEAD" | |
| latest_release_at_head=true | |
| echo "latest_release_at_head=true" >> "$GITHUB_ENV" | |
| fi | |
| elif [[ "${{ matrix.build-type }}" == "latest_release" ]]; then | |
| echo "The latest release has already been built. Exiting..." | |
| echo "continue_build=false" >> "$GITHUB_ENV" | |
| exit 0 | |
| fi | |
| if [[ "${{ matrix.build-type }}" == "latest_release" ]] && [[ "${latest_release_at_head:-false}" == "true" ]] && [[ "${{ inputs.build-type || 'all' }}" != "latest_release" ]]; then | |
| echo "The latest release is at the HEAD of the repo. The nightly build will generate release files. Exiting..." | |
| echo "continue_build=false" >> "$GITHUB_ENV" | |
| exit 0 | |
| fi | |
| mkdir -p slicer-out | |
| if [[ "${{ matrix.build-type }}" == "nightly" ]]; then | |
| build_ref_hash="$head_hash" | |
| version_dir="nightly" | |
| else | |
| build_ref_hash="$latest_release_hash" | |
| version_dir="$latest_release_tag" | |
| fi | |
| echo "BUILD_CACHE_REF=${{ matrix.build-type }}-${build_ref_hash}" >> "$GITHUB_ENV" | |
| cat > slicer-out/config.sh <<EOF | |
| build_type=${{ matrix.build-type }} | |
| version_dir=$version_dir | |
| tag=$latest_release_tag | |
| slicer=${{ matrix.slicer }} | |
| repo=${{ matrix.repo }} | |
| latest_release_at_head=${latest_release_at_head:-false} | |
| upstream_ref=$build_ref_hash | |
| upstream_published_at=$upstream_published_at | |
| created_at=$(date -u +%Y-%m-%dT%H:%M:%SZ) | |
| workflow_run_url=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| EOF | |
| - name: Finalize Setup | |
| if: env.continue_build == 'true' | |
| env: | |
| build_ref: ${{ matrix.build-type == 'latest_release' && 'FETCH_HEAD' || 'HEAD' }} | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y xvfb | |
| git -C slicer-src checkout ${{ env.build_ref }} | |
| ./tools/apply_versioned_patches.sh "${{ matrix.slicer }}" "${{ matrix.build-type == 'nightly' && 'nightly' || env.latest_release_tag }}" dump | |
| - name: Install dependencies | |
| if: env.continue_build == 'true' | |
| run: | | |
| ./slicers/${{ matrix.slicer }}/steps/install-deps.sh | |
| - name: Get dependencies cache key | |
| if: env.continue_build == 'true' | |
| run: | | |
| cd slicer-src | |
| echo "DEPS_CACHE_KEY=$(git log -1 --pretty="format:%H" -- deps)" >> $GITHUB_ENV | |
| - name: Cache built dependencies | |
| if: env.continue_build == 'true' && !inputs.disable-caching | |
| id: cache-build-deps | |
| uses: actions/cache@v4 | |
| with: | |
| path: slicer-src/deps/build | |
| key: ${{ runner.os }}-${{ matrix.slicer }}-x86-64-build-deps-${{ env.DEPS_CACHE_KEY }}-${{ hashFiles(format('slicers/{0}/steps/build-deps.sh', matrix.slicer)) }} | |
| - name: Build dependencies | |
| if: env.continue_build == 'true' && (inputs.disable-caching || steps.cache-build-deps.outputs.cache-hit != 'true') | |
| run: | | |
| ./slicers/${{ matrix.slicer }}/steps/build-deps.sh | |
| - name: Cache built slicer | |
| if: env.continue_build == 'true' && !inputs.disable-caching | |
| id: cache-build-slicer | |
| uses: actions/cache@v4 | |
| with: | |
| path: slicer-src/build | |
| key: ${{ runner.os }}-${{ matrix.slicer }}-build-slicer-${{ env.BUILD_CACHE_REF }}-${{ hashFiles('slicer-src/src/libslic3r/PrintConfig.cpp', 'slicer-src/src/slic3r/GUI/Tab.cpp', 'tools/apply_versioned_patches.sh', format('slicers/{0}/patches/**/*.patch', matrix.slicer)) }} | |
| - name: Build slicer | |
| if: env.continue_build == 'true' && (inputs.disable-caching || steps.cache-build-slicer.outputs.cache-hit != 'true') | |
| run: | | |
| ./slicers/${{ matrix.slicer }}/steps/build.sh | |
| - name: Run slicer | |
| if: env.continue_build == 'true' | |
| run: | | |
| ./slicers/${{ matrix.slicer }}/steps/run.sh | |
| - name: Upload extracted JSON files | |
| if: env.continue_build == 'true' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: configs-${{ matrix.slicer }}-${{ matrix.build-type }} | |
| path: slicer-out/* | |
| commit_artifacts: | |
| needs: build_slicers | |
| runs-on: ubuntu-24.04 | |
| if: success() || failure() | |
| concurrency: | |
| group: slicer-out-${{ github.ref_name }} | |
| cancel-in-progress: false | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref_name }} | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Commit extracted configs | |
| run: | | |
| set -euo pipefail | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| for folder in artifacts/configs-*; do | |
| [[ -d "$folder" ]] || continue | |
| echo "Begin processing $folder" | |
| source "$folder/config.sh" | |
| rm "$folder/config.sh" | |
| target="slicers/$slicer/out/$version_dir" | |
| mkdir -p "$target" | |
| cp -rf "$folder"/* "$target" || true | |
| ./tools/update_slicer_index.py \ | |
| --index "slicers/$slicer/out/_index.json" \ | |
| --version "$version_dir" \ | |
| --kind config \ | |
| --created-at "$created_at" \ | |
| --upstream-ref "$upstream_ref" \ | |
| --upstream-published-at "$upstream_published_at" \ | |
| --source-repo "$repo" \ | |
| --workflow-run-url "$workflow_run_url" \ | |
| $([[ "$version_dir" != "nightly" ]] && echo --latest) | |
| if [[ "$build_type" == "nightly" && "$latest_release_at_head" == "true" ]]; then | |
| release_target="slicers/$slicer/out/$tag" | |
| mkdir -p "$release_target" | |
| cp -rf "$target"/* "$release_target" || true | |
| ./tools/update_slicer_index.py \ | |
| --index "slicers/$slicer/out/_index.json" \ | |
| --version "$tag" \ | |
| --latest \ | |
| --kind config \ | |
| --created-at "$created_at" \ | |
| --upstream-ref "$upstream_ref" \ | |
| --upstream-published-at "$upstream_published_at" \ | |
| --source-repo "$repo" \ | |
| --workflow-run-url "$workflow_run_url" | |
| fi | |
| git add "slicers/$slicer/out" | |
| if git diff --cached --quiet; then | |
| echo "No config changes for $slicer $version_dir." | |
| else | |
| git commit -m "chore(${slicer,,}): dump configuration of ${version_dir} @ ${upstream_ref:0:12}" | |
| fi | |
| done | |
| git pull --rebase origin "${GITHUB_REF_NAME}" | |
| git push origin "HEAD:${GITHUB_REF_NAME}" |