Skip to content

fix tutorials

fix tutorials #183

Workflow file for this run

name: build & test
on:
push:
branches: main
paths:
- '**.py'
- '**.go'
- 'ORIGINALVOXEL-3.obj'
- .github/workflows/build-test.yml
- requirements.txt
pull_request:
paths:
- '**.py'
- '**.go'
- 'ORIGINALVOXEL-3.obj'
- .github/workflows/build-test.yml
- requirements.txt
workflow_dispatch:
inputs:
jobs:
build-test-go-versions:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.18]
test-path:
- ./tutorials/conversion_obj_step
- ./tutorials/conversion_obj_stl
- ./tutorials/get_mass_volume
- ./samples/convert_file
- ./samples/file_density
- ./samples/file_mass
- ./samples/file_volume
- ./samples/file_center_of_mass
- ./samples/file_surface_area
steps:
- uses: actions/checkout@v3
with:
lfs: true
- name: Set up Go ${{ matrix.go-version }}
uses: actions/[email protected]
with:
go-version: ${{ matrix.go-version }}
- name: Run scripts
shell: bash
run: |
FILE=$(find ${{ matrix.test-path }} -name "*.go")
go run $FILE
env:
KITTYCAD_API_TOKEN: ${{secrets.KITTYCAD_API_TOKEN}}
build-test-python-versions:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9]
test-path:
- ./tutorials/conversion_obj_step
- ./tutorials/conversion_obj_stl
- ./tutorials/get_mass_volume
- ./tutorials/getting_started
- ./samples/convert_file
- ./samples/file_density
- ./samples/file_mass
- ./samples/file_volume
- ./samples/file_center_of_mass
- ./samples/file_surface_area
steps:
- uses: actions/checkout@v3
with:
lfs: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
shell: bash
run: |
pip install -r requirements.txt
- name: Run scripts
shell: bash
run: |
FILE=$(find ${{ matrix.test-path }} -name "*.py")
python $FILE
env:
KITTYCAD_API_TOKEN: ${{secrets.KITTYCAD_API_TOKEN}}
build-test-js-versions:
runs-on: ubuntu-latest
strategy:
matrix:
node: [16, 18]
test-path:
- ./samples/convert_file
- ./samples/file_density
- ./samples/file_mass
- ./samples/file_volume
- ./samples/file_center_of_mass
- ./samples/file_surface_area
steps:
- uses: actions/checkout@v3
with:
lfs: true
- name: Set up node ${{ matrix.python-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: 'yarn'
- run: yarn install
- name: Run scripts
shell: bash
run: |
FILE=$(find ${{ matrix.test-path }} -name "*.js")
node $FILE
env:
KITTYCAD_TOKEN: ${{secrets.KITTYCAD_API_TOKEN}}
commit-script-outputs:
# Using the python script to commit the output of the scripts
# The go scripts should have the same output
# This implicitly makes python the source of truth for the outputs
needs: [build-test-python-versions]
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
lfs: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
shell: bash
run: |
pip install -r requirements.txt
- name: remove previous outputs
shell: bash
run: |
rm -rf tutorials/**/*output.{stl,obj,step,json}
rm -rf samples/**/*output.{stl,obj,step,json}
- name: test outputs
run: |
files=( "./tutorials/conversion_obj_step"
"./tutorials/conversion_obj_stl"
"./tutorials/get_mass_volume"
"./tutorials/getting_started"
"./samples/convert_file"
"./samples/file_density"
"./samples/file_mass"
"./samples/file_volume"
"./samples/file_center_of_mass"
"./samples/file_surface_area"
)
for FILE in "${files[@]}"
do
FULL_FILE=$(find $FILE -name "*.py")
python $FULL_FILE
mv output.* $FILE
OUTPUT_FILE=$(find $FILE -name output.*)
if [[ $OUTPUT_FILE == *.step ]]
# current date is added to step file, meaning there will always be a diff, clamping this to a consistent date to prevent this
then
sed -i 's/20..-..-..T..:..:../2022-00-00T00:00:00/g' $OUTPUT_FILE
fi
if [ $(find $FILE -maxdepth 2 -name 'output.*' -print -quit ) ]; then
echo "$FILE output was created."
else
echo "better luck next time $FILE output was NOT created"
exit 1
fi
echo "done $FILE"
done
echo "all done"
env:
KITTYCAD_API_TOKEN: ${{secrets.KITTYCAD_API_TOKEN}}
- name: stage outputs
run: |
git add "tutorials/**/*output.*"
git add "samples/**/*output.*"
- name: git status
run: git status
- name: Check for modified files
id: git-check
run: echo ::set-output name=modified::$(if git diff-index --ignore-submodules --quiet HEAD --; then echo "false"; else echo "true"; fi)
- name: Commit changes, if any
if: steps.git-check.outputs.modified == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git remote set-url origin https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
git fetch origin
git commit -am "Updating script outputs"
git push origin ${{github.event.pull_request.head.ref }}