Step export testing #52
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
| # .github/workflows/cad-export.yml | |
| # | |
| # Automatically generates STEP files from FreeCAD designs when PRs are opened | |
| # or updated. Exports are committed back to the branch in the appropriate | |
| # STEP_FILES folder. | |
| # | |
| # Directory structure expected: | |
| # */CAD_INTERNAL/FREECAD_FILES/*.FCStd - Source files (triggers export) | |
| # */CAD_INTERNAL/STEP_FILES/*.step - Export destination | |
| # | |
| # Requirements: | |
| # - Git LFS must be configured in the repo for *.step files | |
| # - .gitattributes should contain: *.step filter=lfs diff=lfs merge=lfs -text | |
| name: CAD Export | |
| on: | |
| pull_request: | |
| branches: [main, develop] | |
| paths: | |
| - '**/CAD_INTERNAL/FREECAD_FILES/**/*.FCStd' | |
| workflow_dispatch: | |
| inputs: | |
| export_all: | |
| description: 'Export all designs (not just changed files)' | |
| required: false | |
| default: 'false' | |
| type: boolean | |
| # Prevent concurrent runs on the same PR (avoids commit conflicts) | |
| concurrency: | |
| group: cad-export-${{ github.head_ref || github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| export-step: | |
| name: Export STEP files | |
| runs-on: ubuntu-latest | |
| # Required for committing back to the branch | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| # Removing old installation code as installing a version from 2024... | |
| # sudo add-apt-repository -y ppa:freecad-maintainers/freecad-stable | |
| # sudo apt-get update | |
| # sudo apt-get install -y freecad | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| lfs: true | |
| fetch-depth: 0 | |
| ref: ${{ github.head_ref }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Git LFS | |
| run: | | |
| git lfs install | |
| git lfs track "*.step" | |
| git lfs track "*.STEP" | |
| echo "Git LFS configured" | |
| - name: Check Python Information | |
| run: | | |
| python –version | |
| - name: Install FreeCAD | |
| run: | | |
| sudo snap install -y freecad | |
| - name: Identify changed CAD files | |
| id: changed-files | |
| run: | | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ inputs.export_all }}" == "true" ]]; then | |
| FILES=$(find . -path "*/CAD_INTERNAL/FREECAD_FILES/*.FCStd" -type f | tr '\n' ' ') | |
| else | |
| FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD -- 'CAD_INTERNAL/FREECAD_FILES/Assemblies/*.FCStd' | tr '\n' ' ') | |
| fi | |
| echo "files=$FILES" >> $GITHUB_OUTPUT | |
| echo "Found CAD files to export: $FILES" | |
| if [ -z "$FILES" ]; then | |
| echo "No .FCStd files to process" | |
| echo "has_files=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_files=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Export STEP files | |
| if: steps.changed-files.outputs.has_files == 'true' | |
| run: | | |
| echo | |
| freecadcmd .github/scripts/export_step.py ${{ steps.changed-files.outputs.files }} | |
| - name: Generate export summary | |
| if: steps.changed-files.outputs.has_files == 'true' | |
| run: | | |
| echo "## 📦 STEP Export Summary" > export_summary.md | |
| echo "" >> export_summary.md | |
| echo "| Source File | Export | Size |" >> export_summary.md | |
| echo "|-------------|--------|------|" >> export_summary.md | |
| for step_file in $(find . -path "*/CAD_INTERNAL/STEP_FILES/*.step" -type f 2>/dev/null); do | |
| if [ -f "$step_file" ]; then | |
| filename=$(basename "$step_file") | |
| source_name="${filename%.step}.FCStd" | |
| size=$(du -h "$step_file" | cut -f1) | |
| relative_path="${step_file#./}" | |
| echo "| \`$source_name\` | \`$relative_path\` | $size |" >> export_summary.md | |
| fi | |
| done | |
| echo "" >> export_summary.md | |
| echo "_Generated by GitHub Actions on $(date -u '+%Y-%m-%d %H:%M UTC')_" >> export_summary.md | |
| cat export_summary.md | |
| - name: Commit STEP files | |
| if: steps.changed-files.outputs.has_files == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add .gitattributes 2>/dev/null || true | |
| find . -path "*/CAD_INTERNAL/STEP_FILES/*.step" -type f -exec git add {} \; | |
| if git diff --staged --quiet; then | |
| echo "No STEP file changes to commit" | |
| else | |
| git commit -m "Auto-generate STEP exports [skip ci]" | |
| git push | |
| echo "Committed and pushed STEP exports" | |
| fi | |
| - name: Collect STEP files for artefact | |
| if: steps.changed-files.outputs.has_files == 'true' | |
| run: | | |
| mkdir -p step_artefacts | |
| find . -path "*/CAD_INTERNAL/STEP_FILES/*.step" -exec cp {} step_artefacts/ \; 2>/dev/null || true | |
| ls -la step_artefacts/ || echo "No files collected" | |
| - name: Upload STEP artefacts | |
| if: steps.changed-files.outputs.has_files == 'true' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: step-exports | |
| path: step_artefacts/ | |
| if-no-files-found: ignore | |
| retention-days: 30 | |
| - name: Comment on PR | |
| if: github.event_name == 'pull_request' && steps.changed-files.outputs.has_files == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| let summary = ''; | |
| try { | |
| summary = fs.readFileSync('export_summary.md', 'utf8'); | |
| } catch (e) { | |
| summary = '## 📦 STEP Export\n\nSTEP files have been exported and committed to this branch.'; | |
| } | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: summary | |
| }); | |
| - name: No files to export | |
| if: steps.changed-files.outputs.has_files != 'true' | |
| run: | | |
| echo "No FreeCAD files found that require export." | |
| echo "This workflow runs when .FCStd files in CAD_INTERNAL/FREECAD_FILES/ are changed." |