200 lines
6.4 KiB
YAML
200 lines
6.4 KiB
YAML
name: KiBot CI
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
tags:
|
|
- release/rev-**
|
|
branches:
|
|
- main
|
|
- dev
|
|
- review/rev-**
|
|
paths-ignore:
|
|
- '*.md'
|
|
|
|
env:
|
|
# KiBot Configuration
|
|
kibot_config: kibot/yaml/kibot_main.yaml
|
|
kibot_draft: false
|
|
kibot_log: kibot_run.log
|
|
|
|
# Update these to correspond to the KiCad version
|
|
kibot_group: "all_group"
|
|
kibot_tag: "v2_k9"
|
|
kicad_image: "kicad9_auto_full"
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
container: ghcr.io/inti-cmnb/${{ env.kicad_image }}
|
|
if: ${{ github.ref_type == 'tag' || !startsWith(github.event.head_commit.message, 'Merge pull request') }}
|
|
|
|
steps:
|
|
- name: Install NodeJS
|
|
run: |
|
|
apt-get update && apt -y install --no-install-recommends nodejs
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
sparse-checkout: null
|
|
|
|
- name: Dump Environment
|
|
continue-on-error: true
|
|
run: echo "${{ toJSON(env) }}"
|
|
|
|
- name: Dump Context
|
|
continue-on-error: true
|
|
shell: bash
|
|
run: echo "${{ toJSON(github) }}"
|
|
|
|
- name: Determine Release Stage
|
|
shell: bash
|
|
run: |
|
|
stage=unknown
|
|
if [ "${{ github.ref == 'refs/heads/dev' }}" = "true" ] ; then
|
|
if [ "${{ env.kibot_draft }}" = "true" ] ; then
|
|
stage=DRAFT
|
|
else
|
|
stage=WORKING
|
|
fi
|
|
else
|
|
if [ "${{ env.kibot_draft}}" == "true" ] ; then
|
|
echo "Error: kibot_draft is set outside of dev branch"
|
|
exit 1
|
|
fi
|
|
|
|
if [ "${{ startsWith(github.ref, 'refs/heads/review/rev-') }}" = "true" ] ; then
|
|
stage=REVIEW
|
|
elif [ "${{ github.ref_type == 'tag' }}" = "true" ] ; then
|
|
stage=RELEASE
|
|
else
|
|
echo "Error: could not determine release stage"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
echo "Release Stage: $stage"
|
|
echo "kibot_stage=$stage" > $GITHUB_ENV
|
|
|
|
- name: Setup KiBot Arguments
|
|
shell: bash
|
|
run: |
|
|
last_tag=$(git describe --tags --abbrev=0 || echo "NO_TAG")
|
|
echo "Last tag: ${last_tag}"
|
|
if [ "${{ github.ref_type }}" = "tag" ]; then
|
|
version_arg="-E RELEASE_STATE='RELEASE' -E REVISION='${last_tag##release/rev-}'"
|
|
echo "Overriding kibot_variant to 'RELEASE' for tag"
|
|
echo "kibot_variant=RELEASE" >> $GITHUB_ENV
|
|
else
|
|
version_arg="-E RELEASE_STATE='${{ env.kibot_stage }}' -E REVISION='${last_tag##release/rev-}+ (Unreleased)'"
|
|
echo "kibot_variant=${{ env.kibot_stage }}" >> $GITHUB_ENV
|
|
fi
|
|
|
|
case "$kibot_stage" in
|
|
"DRAFT")
|
|
additional_args="--skip-pre draw_fancy_stackup,erc,drc ${version_arg} --log ${{ env.kibot_log }} draft_group"
|
|
;;
|
|
"WORKING")
|
|
additional_args="--skip-pre erc,drc ${version_arg} --log ${{ env.kibot_log }} ${{ env.kibot_group }}"
|
|
;;
|
|
"REVIEW"|"RELEASE")
|
|
additional_args="${version_arg} --log ${{ env.kibot_log }} ${{ env.kibot_group }}"
|
|
;;
|
|
*)
|
|
echo "Unknown Stage: $kibot_stage"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
echo "version_arg=${version_arg}" >> $GITHUB_ENV
|
|
echo "additional_args=${additional_args}" >> $GITHUB_ENV
|
|
|
|
- name: Remove KiRi Files from Prior Revisions
|
|
shell: bash
|
|
run: '[ -d kiri ] && git rm -rf kiri/* || echo "No KiRi files to delete"'
|
|
|
|
- name: Retrieve Cached 3d Models
|
|
id: cache-models-restore
|
|
uses: actions/cache/restore@v4
|
|
with:
|
|
path: ~/3d_models
|
|
key: 3d_models
|
|
|
|
- name: Run KiBot (Outputs)
|
|
uses: inti-cmnb/kibot@${{ env.kibot_tag }}
|
|
env:
|
|
KIBOT_3D_MODELS: ~/3d_models
|
|
with:
|
|
additional_args: ${{ env.additional_args }}
|
|
config: ${{ env.kibot_config }}
|
|
cache3D: YES
|
|
|
|
- name: Save Cached 3d Models
|
|
id: cache-models-save
|
|
if: always()
|
|
uses: actions/cache/save@v4
|
|
with:
|
|
path: ~/3d_models
|
|
key: ${{ steps.cache-models-restore.outputs.cache-primary-key }}
|
|
|
|
- name: Pull latest changes
|
|
shell: bash
|
|
run: |
|
|
git config --global user.email "gitea-actions[bot]@users.noreply.git.asymworks.com"
|
|
git config --global user.name "Gitea Actions"
|
|
|
|
if [ "${{ github.ref_type }}" = "tag" ]; then
|
|
echo "Triggered by a tag, committing changes in detached HEAD state"
|
|
git add -A
|
|
git commit -m "[bot]: Update Outputs (release)"
|
|
|
|
DETACHED_COMMIT=$(git rev-parse HEAD)
|
|
echo "Checking out the main branch"
|
|
git fetch origin main
|
|
git checkout main
|
|
|
|
echo "Merging detached HEAD commit into main"
|
|
git merge --no-ff $DETACHED_COMMIT -m "[bot]: Merge release artifacts from workflow" -X theirs
|
|
echo "Pushing to main branch"
|
|
git push origin main
|
|
else
|
|
echo "Triggered by a branch, using the current branch"
|
|
git pull origin ${{ github.ref_name }} --tags --force
|
|
fi
|
|
|
|
- name: Discard changes to .kicad_pcb files and remove temp files
|
|
run: |
|
|
git checkout HEAD -- $(git ls-files "*.kicad_pcb")
|
|
git clean -f -e "panels/*" "*.kicad_pcb"
|
|
git clean -f -e "panels/*" "*.kicad_pro"
|
|
git clean -f -e "panels/*" "*.kicad_dru"
|
|
git clean -f -e "panels/*" "*.kicad_prl"
|
|
|
|
- name: Push Outputs
|
|
uses: stefanzweifel/git-auto-commit-action@v5
|
|
with:
|
|
branch: ${{ github.ref_name }}
|
|
commit_message: '[bot]: Update Outputs'
|
|
|
|
- name: Upload KiBot Log
|
|
if: ${{ always() }}
|
|
uses: christopherhx/gitea-upload-artifact@v4
|
|
with:
|
|
name: log_file_kibot
|
|
path: ${{ env.kibot_log }}
|
|
|
|
- name: Upload Drawing Notes Log
|
|
if: ${{ always() && env.kibot_stage != 'DRAFT' }}
|
|
uses: christopherhx/gitea-upload-artifact@v4
|
|
with:
|
|
name: log_file_notes
|
|
path: kibot_run_notes.log
|
|
|
|
- name: Upload README Log
|
|
if: ${{ always() && env.kibot_stage == 'DRAFT' }}
|
|
uses: christopherhx/gitea-upload-artifact@v4
|
|
with:
|
|
name: log_file_readme
|
|
path: kibot_run_readme.log
|