-
Notifications
You must be signed in to change notification settings - Fork 0
174 lines (149 loc) · 6.03 KB
/
cad-export.yml
File metadata and controls
174 lines (149 loc) · 6.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# .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
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: Install FreeCAD
run: |
sudo add-apt-repository -y ppa:freecad-maintainers/freecad-stable
sudo apt-get update
sudo apt-get install -y freecad
echo "FreeCAD version:"
freecad --version || freecadcmd --version || echo "Version check not available"
- 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: |
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."