forked from leoheck/kiri-docker
-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
182 lines (182 loc) · 7.88 KB
/
action.yml
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
175
176
177
178
179
180
181
182
name: Kiri KiCad Diff Action
description: An action using Kiri to diff KiCad projects in CI
branding:
icon: 'eye'
color: 'gray-dark'
inputs:
project-file:
description: Path to the KiCad project file
output-dir:
description: Change output folder path/name
remove:
description: Remove generated folder before running it
archive:
description: Archive generated files
pcb-page-frame:
description: Disable page frame for PCB
force-layout-view:
description: Force starting with the Layout view selected
skip-kicad6-schematics:
description: Skip ploting Kicad 6 schematics (.kicad.sch)
skip-cache:
description: Skip usage of -cache.lib on plotgitsch
older:
description: Show commits starting from this one
newer:
description: Show commits up to this one
last:
description: Show last N commits
all:
description: Include all commits even if schematics/layout don't have changes
extra-args:
description: Extra arguments to pass to Kiri
kiri-debug:
description: Enable debug mode for Kiri
outputs: {}
runs:
using: composite
steps:
- name: Get number of commits in PR
if: github.event_name == 'pull_request' && (github.event_name == 'pull_request' && github.event.action != 'closed')
id: pr
shell: bash
run: |
# Set DEFAULT_LAST to the number of commits in the PR if ${{ inputs.last }} is not set. The minimum is 2.
if [ -z "${{ inputs.last }}" ]; then
# Un-shallow, but don't fail if it's already unshallow
git fetch --unshallow || true
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
# Deepen topic branch; checkout topic branch
git fetch origin ${{ github.event.pull_request.head.ref }} --depth=$(( ${{ github.event.pull_request.commits }} + 1 ))
git checkout ${{ github.event.pull_request.head.ref }}
# Fetch main for common origin
git fetch origin main:main
COUNT=$(git rev-list --count ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }})
echo "DEFAULT_LAST=\"${COUNT}\"" >> $GITHUB_ENV
else
echo "DEFAULT_LAST=\"${{ inputs.last }}\"" >> $GITHUB_ENV
fi
# If the PR hasn't changed any KiCad files, we don't need to run Kiri.
- name: Check for KiCad files
id: kicad-files
if: github.event_name == 'pull_request' && github.event.action != 'closed'
shell: bash
run: |
if git diff --name-only ${{ github.event.pull_request.base.sha }} | grep -q '\.kicad\(_pro\|_sch\|_pcb\)\?$'; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi
- name: Run Kiri
# The __KIRI VERSION__ below will be replaced by the semver version of the action
# This is done by the release action and propagated to the tags
uses: docker://ghcr.io/usa-reddragon/kiri:__KIRI_VERSION__
if: github.event_name == 'pull_request' && github.event.action != 'closed' && steps.kicad-files.outputs.changed == 'true'
env:
KIRI_PROJECT_FILE: ${{ inputs.project-file }}
KIRI_OUTPUT_DIR: ${{ inputs.output-dir }}
KIRI_REMOVE: ${{ inputs.remove }}
KIRI_ARCHIVE: ${{ inputs.archive }}
KIRI_PCB_PAGE_FRAME: ${{ inputs.pcb-page-frame }}
KIRI_FORCE_LAYOUT_VIEW: ${{ inputs.force-layout-view }}
KIRI_SKIP_KICAD6_SCHEMATICS: ${{ inputs.skip-kicad6-schematics }}
KIRI_SKIP_CACHE: ${{ inputs.skip-cache }}
KIRI_OLDER: ${{ inputs.older }}
KIRI_NEWER: ${{ inputs.newer }}
KIRI_LAST: ${{ steps.pr.outputs.DEFAULT_LAST }}
KIRI_ALL: ${{ inputs.all }}
KIRI_DEBUG: ${{ inputs.kiri-debug }}
KIRI_TAG: ${{ inputs.kiri-tag }}
with:
args: ${{ inputs.extra-args }}
- name: Upload Kiri custom output
uses: actions/upload-artifact@v2
if: inputs.output-dir != '' && github.event_name == 'pull_request' && github.event.action != 'closed' && steps.kicad-files.outputs.changed == 'true'
with:
name: kiri-output
path: ${{ inputs.output-dir }}
- name: Get Kiri output directory
id: kiri-output
if : inputs.output-dir == '' && github.event_name == 'pull_request' && github.event.action != 'closed' && steps.kicad-files.outputs.changed == 'true'
shell: bash
run: |
# If output-dir is not set, the output directory is in the same folder as the project file, in the folder .kiri
# If the project file is not set, the output directory is simply .kiri
if [ -z "${{ inputs.project-file }}" ]; then
echo "output-dir=.kiri" >> $GITHUB_OUTPUT
else
echo "output-dir=$(dirname ${{ inputs.project-file }})/.kiri" >> $GITHUB_OUTPUT
fi
- name: Upload Kiri output
uses: actions/upload-artifact@v2
if: inputs.output-dir == '' && github.event_name == 'pull_request' && github.event.action != 'closed' && steps.kicad-files.outputs.changed == 'true'
with:
name: kiri-output
path: ${{ steps.kiri-output.outputs.output-dir }}
- name: Checkout gh-pages branch
if: github.event_name == 'pull_request'
uses: actions/checkout@v3
with:
ref: gh-pages
fetch-depth: 0
path: gh-pages
- name: Setup git config for gh-pages branch
if: github.event_name == 'pull_request'
shell: bash
run: |
cd gh-pages
git config --local user.email github-actions@github.com
git config --local user.name github-actions
- name: Copy the output to a subdirectory of the gh-pages branch
if: github.event_name == 'pull_request' && github.event.action != 'closed' && steps.kicad-files.outputs.changed == 'true'
shell: bash
run: |
rm -rf gh-pages/pr-previews/${{ github.event.pull_request.number }}
mkdir -p gh-pages/pr-previews/${{ github.event.pull_request.number }}
cp -r ${{ steps.kiri-output.outputs.output-dir }}/* gh-pages/pr-previews/${{ github.event.pull_request.number }}
- name: Commit and push the changes
if: github.event_name == 'pull_request' && github.event.action != 'closed' && steps.kicad-files.outputs.changed == 'true'
shell: bash
id: commit
run: |
cd gh-pages
git add -A
git commit -m "Update Kiri output for PR #${{ github.event.pull_request.number }}"
git push origin gh-pages
echo "repository_name=${REPO##*/}" >> $GITHUB_OUTPUT
env:
REPO: ${{ github.repository }}
- name: Create a comment with the link to the output
if: github.event_name == 'pull_request' && github.event.action != 'closed' && steps.kicad-files.outputs.changed == 'true'
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
Kiri diff output is available at https://${{ github.repository_owner }}.github.io/${{ steps.commit.outputs.repository_name }}/pr-previews/${{ github.event.pull_request.number }}/web/index.html
- name: Delete pr-previews/${{ github.event.pull_request.number }}
id: delete
shell: bash
if: github.event_name == 'pull_request' && github.event.action == 'closed'
run: |
cd gh-pages
rm -rf pr-previews/${{ github.event.pull_request.number }}
if [ -n "$(git status --porcelain pr-previews/${{ github.event.pull_request.number }})" ]; then
git add -A
echo "deleted=true" >> $GITHUB_OUTPUT
else
echo "deleted=false" >> $GITHUB_OUTPUT
fi
- name: Commit and push
if: steps.delete.outputs.deleted == 'true' && github.event_name == 'pull_request' && github.event.action == 'closed'
shell: bash
run: |
cd gh-pages
git commit -m "Delete Kiri output for PR #${{ github.event.pull_request.number }}"
git push origin gh-pages
- name: Create a comment on the PR
if: steps.delete.outputs.deleted == 'true' && github.event_name == 'pull_request' && github.event.action == 'closed'
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
Kiri diff output has been deleted.