workflow: rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS when: never - if: $CI_COMMIT_BRANCH variables: GIT_STRATEGY: clone GIT_SUBMODULE_STRATEGY: normal GIT_SUBMODULE_FORCE_HTTPS: "true" # GIT_SUBMODULE_UPDATE_FLAGS: --remote --merge stages: - gen_mech - gen_fab - release image: name: ghcr.io/inti-cmnb/kicad7_auto:1.6.3 .main_rules: rules: - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"' - if: $CI_COMMIT_BRANCH == "main" - if: $GITLAB_CI == 'false' .dev_rules: rules: - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "dev"' - if: $CI_COMMIT_BRANCH == "dev" .commands: get_files: - FILES=$(find . -name *$SEARCH -not -path "./.gitlab/*") get_dirs: - FILES=$(find . -name *$SEARCH -not -path "./.gitlab/*") - | if [[ $FILES == "" ]]; then DIRS="" else DIRS=$(dirname $FILES) fi sch_from_pro: - 'SCHEMS=$(for f in $FILES ; do echo "${f%.*}.kicad_sch"; done)' - 'SCHEMS=$(for f in $SCHEMS ; do echo "${f##**/}"; done)' dir_arr: - !reference [.commands, get_dirs] - END=$(wc -w <<< $DIRS) - dir_arr=($DIRS) kibot: - 'SEARCH=".kicad_pro"' - !reference [.commands, dir_arr] - !reference [.commands, sch_from_pro] - sch_arr=($SCHEMS) - | cd $CI_PROJECT_DIR for i in $(seq 1 $END) do if [[ ${dir_arr[i-1]} == "./Frame" ]]; then continue fi echo ${dir_arr[i-1]} echo ${sch_arr[i-1]} python3 $CI_PROJECT_DIR/.gitlab/.scripts/orig.py ${dir_arr[i-1]} kibot -e ${dir_arr[i-1]}/${sch_arr[i-1]} -c $CI_PROJECT_DIR/.gitlab/default.kibot.yaml -d $CI_PROJECT_DIR/Fabrication/${dir_arr[i-1]} -s $SUFFIX done - cd $CI_PROJECT_DIR panel: - 'SEARCH="_panel.json"' - !reference [.commands, get_dirs] - | cd $CI_PROJECT_DIR for d in $DIRS do echo $d JSON=$(find $d/*_panel.json) FILE=$(basename "${JSON}") NAME=$(echo "${FILE%.json}") PCB=$(find $d/*.kicad_pcb) mkdir $NAME kikit panelize -p $JSON $PCB $NAME/$NAME.kicad_pcb cp .gitlab/micromelon_default/micromelon_default.kicad_sch $NAME/$NAME.kicad_sch cp $d/fp-lib-table $NAME/ python3 .gitlab/.scripts/post_panel.py $NAME/$NAME.kicad_pro $PCB done - cd $CI_PROJECT_DIR neo: - 'SEARCH=".kicad_pro"' - !reference [.commands, get_dirs] - | for d in $DIRS do if [[ $d == "./Frame" ]]; then continue fi echo $d python3 $CI_PROJECT_DIR/.gitlab/.scripts/neo.py $d done git_tag: - | if [[ $GITLAB_CI == 'true' && $CI_COMMIT_BRANCH == "main" ]]; then echo "running git tag" git tag $CI_COMMIT_MESSAGE fi merge_libs: - | if [[ $GITLAB_CI == 'true' && $CI_COMMIT_BRANCH == "main" ]]; then git config --global user.name "KicadCi" git config --global user.email "andrew@micromelon.com.au" cd $CI_PROJECT_DIR for d in "libs/melonlib" "libs/melon3d" do cd $d if [ $d == "libs/melonlib" ] then TOKEN=$KI_LIB_TOKEN else TOKEN=$KI_LIB_3D_TOKEN fi REPO=$(basename $(git remote get-url origin)) cd $CI_PROJECT_DIR rm -rf $d rm -rf .git/modules/$d git submodule set-url $d https://ci_push:$TOKEN@gitlab.com/Micromelon/education/hardware/$REPO git submodule update --init --remote --merge $d cd $d git remote set-url origin https://ci_push:$TOKEN@gitlab.com/Micromelon/education/hardware/$REPO cd $CI_PROJECT_DIR done git submodule status for d in "libs/melonlib" "libs/melon3d" do cd $d if [ $(git rev-parse HEAD) != $(git rev-parse main) ] then CURR_B=$(git config -f $CI_PROJECT_DIR/.gitmodules submodule.$d.branch) echo CURR_B echo $CURR_B git checkout $CURR_B echo "about to commit" git commit --allow-empty -m "Merge" echo "about to push" git remote get-url origin git push -u origin HEAD:$CURR_B -o merge_request.create -o merge_request.remove_source_branch=false -o merge_request.merge_when_pipeline_succeeds -o merge_request.target=main fi cd $CI_PROJECT_DIR done fi output_mech: stage: gen_mech artifacts: when: always paths: - Fabrication/**/* variables: SUFF_MECH: run_erc,run_drc step script: - !reference [.commands, git_tag] - SUFFIX=$SUFF_MECH - !reference [.commands, kibot] outputs_dev: rules: - !reference [.dev_rules, rules] stage: gen_fab artifacts: when: always name: "$CI_PROJECT_TITLE-$CI_COMMIT_SHORT_SHA" paths: - Fabrication/**/* expire_in: 1 week variables: SUFF_SCH: run_drc print_sch SUFF_PCB: run_erc,update_xml,set_text_variables print_pcb script: - !reference [.commands, git_tag] - SUFFIX=$SUFF_SCH - !reference [.commands, kibot] - SUFFIX=$SUFF_PCB - !reference [.commands, kibot] outputs_all: extends: outputs_dev rules: - !reference [.main_rules, rules] variables: SUFF_SCH: run_drc sch SUFF_PCB: run_erc,update_xml,set_text_variables pcb script: - !reference [.commands, git_tag] - SUFFIX=$SUFF_SCH - !reference [.commands, kibot] - SUFFIX=$SUFF_PCB - !reference [.commands, panel] - !reference [.commands, kibot] - !reference [.commands, neo] - !reference [.commands, merge_libs] release_job: stage: release image: registry.gitlab.com/gitlab-org/release-cli:latest needs: - job: outputs_all artifacts: true rules: - if: $CI_COMMIT_TAG when: never # Do not run this job when a tag is created manually - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Run this job when commits are pushed or merged to the default branch script: - echo "running release_job for $TAG" artifacts: when: always name: "$CI_PROJECT_TITLE-$CI_COMMIT_MESSAGE" paths: - Fabrication/**/* expire_in: never release: # See https://docs.gitlab.com/ee/ci/yaml/#release for available properties tag_name: '$CI_COMMIT_MESSAGE' # The version is incremented per pipeline. description: '$CI_COMMIT_MESSAGE' ref: '$CI_COMMIT_SHA' # The tag is created from the pipeline SHA. assets: links: - name: All Fab url: "${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}/artifacts/download"