Skip to content

Commit

Permalink
action: Don't fail on runs without KiCad changes
Browse files Browse the repository at this point in the history
  • Loading branch information
USA-RedDragon committed Jun 4, 2023
1 parent e8999c2 commit 162f714
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 60 deletions.
52 changes: 0 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ on:
types:
- opened
- synchronize
paths:
- kicad/*.kicad_pcb
- kicad/*.kicad_sch
- kicad/*.kicad_pro

jobs:
kiri-diff:
Expand Down Expand Up @@ -93,51 +89,3 @@ jobs:
- name: Kiri
uses: usa-reddragon/kiri-github-action@v1
```

### Requiring Kiri for PR merges

The `on.pull_request.paths` object is the typical method of filtering to only
run Kiri on PRs with KiCad file changes. Unfortunately, making a GitHub Action
required for merging means that the workflow must run for all PRs, even
those without KiCad changes.

```yaml
# .github/workflows/pr-kicad-diff.yaml
name: KiCad Pull Request Diff

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
pull_request:
types:
- opened
- synchronize
paths:
- kicad/*.kicad_pcb
- kicad/*.kicad_sch
- kicad/*.kicad_pro

jobs:
kiri-diff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
# If the PR hasn't changed any KiCad files, we don't need to run Kiri.
- name: Check for KiCad files
id: kicad-files
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: Kiri
uses: usa-reddragon/kiri-github-action@v1
if: steps.kicad-files.outputs.changed == 'true'
with:
project-file: kicad/productname.kicad_pro
```
27 changes: 19 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,20 @@ runs:
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
uses: docker://ghcr.io/usa-reddragon/kiri:v1.0.27
if: github.event_name != 'pull_request' || github.event.action != 'closed'
uses: docker://ghcr.io/usa-reddragon/kiri:v1.0.28
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 }}
Expand All @@ -75,13 +86,13 @@ runs:
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'
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'
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
Expand All @@ -93,7 +104,7 @@ runs:
fi
- name: Upload Kiri output
uses: actions/upload-artifact@v2
if: inputs.output-dir == '' && github.event_name == 'pull_request' && github.event.action != 'closed'
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 }}
Expand All @@ -112,14 +123,14 @@ runs:
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'
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'
if: github.event_name == 'pull_request' && github.event.action != 'closed' && steps.kicad-files.outputs.changed == 'true'
shell: bash
id: commit
run: |
Expand All @@ -131,7 +142,7 @@ runs:
env:
REPO: ${{ github.repository }}
- name: Create a comment with the link to the output
if: github.event_name == 'pull_request' && github.event.action != 'closed'
if: github.event_name == 'pull_request' && github.event.action != 'closed' && steps.kicad-files.outputs.changed == 'true'
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ github.event.pull_request.number }}
Expand Down

0 comments on commit 162f714

Please sign in to comment.