From e5b4ca9b277ed7a3e75734d1b7d171deb5478461 Mon Sep 17 00:00:00 2001 From: Alexander Krikun Date: Sat, 8 Jan 2022 03:21:28 +0300 Subject: [PATCH] CI --- .github/workflows/main.yml | 204 +++++++++++++++++++++++++++++++++++++ build.sh | 62 +++++++++++ 2 files changed, 266 insertions(+) create mode 100644 .github/workflows/main.yml create mode 100644 build.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..dfb413f --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,204 @@ +on: + push: + branches: + - main + paths-ignore: + - '**/README.md' + - '**/LICENSE' + pull_request: + branches: + - main + paths-ignore: + - '**/README.md' + - '**/LICENSE' + workflow_dispatch: + paths-ignore: + - '**/README.md' + - '**/LICENSE' + +env: + DOCKER_USER_OPTION: '$UID:$GID' + +name: Build +jobs: + generate: + runs-on: ubuntu-latest + name: Generate + steps: + - name: Checkout + uses: actions/checkout@v2 + - uses: xanantis/docker-file-ownership-fix@v1 + - name: Run build script + run: | + chmod +x build.sh + ./build.sh + shell: bash + - name: Persist PCB gerbers + uses: actions/upload-artifact@v2 + with: + name: Nijuni_pcb_gerbers + path: gerbers/pcb + - name: Persist case gerbers + uses: actions/upload-artifact@v2 + with: + name: Nijuni_case_gerbers + path: gerbers/case + - name: Persist images + uses: actions/upload-artifact@v2 + with: + name: Nijuni_images + path: images + - name: Persist laser case files + uses: actions/upload-artifact@v2 + with: + name: Nijuni_laser_case_files + path: dxf + + + image_matrix: + runs-on: ubuntu-latest + name: PCB image matrix + needs: generate + outputs: + matrix: ${{ steps.setmatrix.outputs.matrix }} + steps: + - uses: actions/download-artifact@master + with: + name: Nijuni_images + path: images + - id: setmatrix + run: | + matrixArray=$(find ./images -name 'pcb*.png' | xargs -n 1 -i echo {} {} | sed 's# .*/# #') # Creates array of all PCB image files + # Start Generate JSON String + echo "$matrixArray" | \ + jq --slurp --raw-input 'split("\n")[:-1] | map(split(" "))' | \ + jq "map({\"filepath\": (.[0]), \"basename\": .[1] })" | \ + jq -sc "{ \"include\": .[] }" > tmp + cat ./tmp + # End Generate JSON String + matrixStringifiedObject=$(cat ./tmp) # Use this as jq @sh wasn't cooperating + echo "::set-output name=matrix::$matrixStringifiedObject" + + gerber_matrix: + runs-on: ubuntu-latest + name: Gerber matrix + needs: generate + outputs: + matrix: ${{ steps.setmatrix.outputs.matrix }} + steps: + - uses: actions/download-artifact@master + with: + name: Nijuni_gerbers + path: gerbers + - id: setmatrix + run: | + matrixArray=$(find ./gerbers/pcb -name '*.zip' | xargs -n 1 -i echo {} {} | sed 's# .*/# #') # Creates array of all PCB gerber files + # Start Generate JSON String + echo "$matrixArray" | \ + jq --slurp --raw-input 'split("\n")[:-1] | map(split(" "))' | \ + jq "map({\"filepath\": (.[0]), \"basename\": .[1] })" | \ + jq -sc "{ \"include\": .[] }" > tmp + cat ./tmp + # End Generate JSON String + matrixStringifiedObject=$(cat ./tmp) # Use this as jq @sh wasn't cooperating + echo "::set-output name=matrix::$matrixStringifiedObject" + + upload_pcb_gerbers: + runs-on: ubuntu-latest + name: Upload gerbers + needs: [generate, gerber_matrix] + strategy: + matrix: ${{fromJson(needs.gerber_matrix.outputs.matrix)}} + steps: + - uses: actions/download-artifact@master + with: + name: Nijuni_gerbers + path: gerbers + - name: Gets latest created release info + id: latest_release_info + uses: jossef/action-latest-release-info@v1.1.0 + env: + GITHUB_TOKEN: ${{ github.token }} + - name: Upload gerbers + uses: shogo82148/actions-upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + overwrite: true + upload_url: ${{ steps.latest_release_info.outputs.upload_url }} + asset_path: ${{ matrix.filepath }} + asset_name: ${{ matrix.basename }} + + upload_images: + runs-on: ubuntu-latest + name: Upload images + needs: [generate, image_matrix] + strategy: + matrix: ${{fromJson(needs.image_matrix.outputs.matrix)}} + steps: + - uses: actions/download-artifact@master + with: + name: Nijuni_images + path: images + - name: Gets latest created release info + id: latest_release_info + uses: jossef/action-latest-release-info@v1.1.0 + env: + GITHUB_TOKEN: ${{ github.token }} + - name: Upload images + uses: shogo82148/actions-upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + overwrite: true + upload_url: ${{ steps.latest_release_info.outputs.upload_url }} + asset_path: ${{ matrix.filepath }} + asset_name: ${{ matrix.basename }} + + upload_laser_case_files: + runs-on: ubuntu-latest + name: Upload case DXF files + needs: generate + steps: + - uses: actions/download-artifact@master + with: + name: Nijuni_laser_case_files + path: dxf + - name: Gets latest created release info + id: latest_release_info + uses: jossef/action-latest-release-info@v1.1.0 + env: + GITHUB_TOKEN: ${{ github.token }} + - name: Upload case files + uses: shogo82148/actions-upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + overwrite: true + upload_url: ${{ steps.latest_release_info.outputs.upload_url }} + asset_path: ./dxf/laser_case_files.zip + asset_name: laser_case_files.zip + + upload_gerber_case_files: + runs-on: ubuntu-latest + name: Upload case DXF files + needs: generate + steps: + - uses: actions/download-artifact@master + with: + name: Nijuni_gerber_case_files + path: gerbers/case + - name: Gets latest created release info + id: latest_release_info + uses: jossef/action-latest-release-info@v1.1.0 + env: + GITHUB_TOKEN: ${{ github.token }} + - name: Upload case files + uses: shogo82148/actions-upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + overwrite: true + upload_url: ${{ steps.latest_release_info.outputs.upload_url }} + asset_path: ./gerbers/case/gerber_case_files.zip + asset_name: gerber_case_files.zip \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..43631c8 --- /dev/null +++ b/build.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +container_cmd="docker run -v=$(pwd):/kikit -w=/kikit --rm" + +# Images +echo "Drawing image files" +mkdir -p images +for name in "pcb" "plate" "bottom" +do + for option in "$name"/*/ + do + short_option="$(basename "$option")" + file="$(find $option -type f -name '*.kicad_pcb')" + ${container_cmd} yaqwsx/kikit:nightly pcbdraw --style builtin:set-black-hasl.json "$file" images/"$name"_"$short_option".png >> /dev/null + ${container_cmd} yaqwsx/kikit:nightly pcbdraw --style builtin:set-black-hasl.json --back "$file" images/"$name"_"$short_option"_back.png >> /dev/null + done +done + +# Gerbers +echo "Generating gerbers" +mkdir -p gerbers +for name in "pcb" "plate" "bottom" +do + prefix="case" + if [[ "$name" == "pcb" ]]; then + prefix="pcb" + fi + mkdir -p gerbers/"$prefix" + for option in "$name"/*/ + do + if [[ "$name" == "plate" ]] && ! [[ "$option" =~ ^.*\/fr4.*$ ]]; then + continue + fi + short_option="$(basename "$option")" + file="$(find $option -type f -name '*.kicad_pcb')" + ${container_cmd} yaqwsx/kikit:nightly kikit fab jlcpcb --no-assembly "$file" gerbers/"$name"_"$short_option" --no-drc + mv gerbers/"$name"_"$short_option"/gerbers.zip gerbers/"$prefix"/"$name"_"$short_option"_gerbers.zip + rm -r gerbers/"$name"_"$short_option" + done +done + +# Plate/bottom dxf files +echo "Generating case DXF files" +mkdir -p dxf +for name in "plate" "bottom" +do +for option in "$name"/*/ + do + if [[ "$name" == "plate" ]] && [[ ! "$option" =~ ^.*\/laser.*$ ]]; then + continue + fi + short_option="$(basename "$option")" + file="$(find $option -type f -name '*.kicad_pcb')" + file_name=$(basename "$file" .kicad_pcb) + ${container_cmd} yaqwsx/kikit:nightly kikit export dxf "$file" dxf/"$name"_"$short_option" + mv dxf/"$name"_"$short_option"/"$file_name"-EdgeCuts.dxf dxf/"$name"_"$short_option".dxf + rm -r dxf/"$name"_"$short_option" + done +done + +zip -jr dxf/laser_case_files dxf/ + \ No newline at end of file