Skip to content

Commit

Permalink
Make CI use fetch_diff
Browse files Browse the repository at this point in the history
  • Loading branch information
gaymeowing committed Aug 17, 2024
1 parent cc8c76a commit 18b78fb
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 18 deletions.
84 changes: 84 additions & 0 deletions .github/actions/fetch_diff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: setup-rokit
description: GitHub action to install and run rokit; a toolchain manager.
author: kalrnlo

inputs:
a:
description: "a commit hash to get the diff between `a `and `b`"
required: false
default: ""
b:
description: "a commit hash to get the diff between `a` and `b`"
required: false
default: ""
event_name:
description: the `github.event_name` that triggered the workflow
required: false
default: "${{ github.event_name }}"
event:
description: the event object that triggered the workflow
default: ${{ github.event }}
required: false
token:
description: "GitHub token via `github.token`"
default: "${{ github.token }}"
required: false

runs:
using: "composite"
outputs:
diff: ${{ steps.main.outputs.diff }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: ${{ inputs.event_name == "pull_request" && 2 || 0 }}

- name: Get A
shell: bash
id: a
run: |
if [ "${{ inputs.a }}" == "" ] then
case "${{ inputs.event_name }}" in
push)
echo "b=${{ inputs.event.commits[0].id }}" >> $GITHUB_OUTPUT
;;
pull_request)
echo "b=${{ inputs.event.base_ref }}" >> $GITHUB_OUTPUT
;;
esac
else
echo "b=${{ inputs.a }}" >> $GITHUB_OUTPUT
fi
- name: Get B
shell: bash
id: b
run: |
if [ "${{ inputs.b }}" == "" ] then
case "${{ inputs.event_name }}" in
push)
echo "b=${{ inputs.event.commits[-1].id }}" >> $GITHUB_OUTPUT
;;
pull_request)
echo "b=${{ inputs.event.head_ref }}" >> $GITHUB_OUTPUT
;;
esac
else
echo "b=${{ inputs.b }}" >> $GITHUB_OUTPUT
fi
- name: Create diff
shell: bash
id: main
env:
GITHUB_TOKEN: ${{ inputs.token }}
a: ${{ steps.a.outputs.a }}
b: ${{ steps.b.outputs.b }}
run: |
diff = git diff --name-only --diff-filter=d "${{ steps.b.outputs.b }}~1" "${{ steps.a.outputs.a }}"
echo "diff=$diff" >> $GITHUB_OUTPUT
echo diff >> .diff
branding:
icon: link-2
color: blue
19 changes: 1 addition & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,11 @@ jobs:
runner-os: macos-14

steps:
- uses: ./.github/actions/fetch_diff.yml
- uses: CompeyDev/[email protected]
- uses: actions/checkout@v4
with:
fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }}

- name: Install Toolchain
run: rokit install --no-trust-check

- name: Fetch Diff
shell: bash
run: |
case '${{ github.event_name }}' in
push)
firstCommit='${{ github.event.commits[0].id }}'
lastCommit='${{ github.event.commits[-1].id }}'
;;
pull_request)
firstCommit='${{ github.event.base_ref }}'
lastCommit='${{ github.event.head_ref }}'
;;
esac
git diff --name-only --output=".diff" --diff-filter=d "${firstCommit}~1" "${lastCommit}"
- name: Run test runner
run: lune run scripts/test_runner all

0 comments on commit 18b78fb

Please sign in to comment.