Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add /style and /swig magic comments #576

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/actions/apply-style/checkout.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

###
# Attempt to find the branch of the PR from the detached head state
##

echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "Attempting to find branch that matches commit..."

# Get the current commit SHA
current_commit_sha=$(git rev-parse HEAD)
# List all branches containing the current commit SHA
branches=$(git branch -r --contains $current_commit_sha)

# Loop over the string split by whitespace
branch=""
num_branches_found=0
for _possible_branch in $branches; do
# Skip items that start with "pull/"
if [[ $_possible_branch == pull/* ]]; then
continue
fi
if [[ $_possible_branch == origin/* ]]; then
_possible_branch=$(echo "$_possible_branch" | sed 's/origin\///')
fi
echo "Possible Branch: $_possible_branch"
branch=$_possible_branch
num_branches_found=$((num_branches_found+1))
done

if [ "$num_branches_found" -ne 1 ]; then
echo "Error: Unable to find a single branch that matched git sha $current_commit_sha"
exit 1
fi

echo "Found branch: $branch"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

git checkout $branch

git submodule update --init --recursive
28 changes: 28 additions & 0 deletions .github/workflows/check-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,37 @@ name: Checks - formatting
on:
pull_request:
workflow_dispatch:
issue_comment:
types: [created]

jobs:
apply_format:
if: startsWith(github.event.comment.body, '/style')
runs-on: ubuntu-latest
steps:
# Checkout the GitHub created reference for the PR.
# The only way to do this is by using the "issue" number
# but that is really the PR number in this context.
# This is due to using an `issue_comment` event which
# is due to the GitHub Actions API that does not have
# a `pull_request_comment` event or something similar.
# This leaves us in a detached head state which is corrected
# in `apply-style/checkout.sh`
- name: Checkout pull request
uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.issue.number }}/head

- name: Checkout the right git ref
run: ./.github/actions/apply-style/checkout.sh

- name: Download the git diff from format_check
uses: actions/download-artifact@v4
with:
name: format.patch

format_check:
if: ${{ github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
container:
image: ghcr.io/llnl/sundials_spack_cache:llvm-17.0.4-h4lflucc3v2vage45opbo2didtcuigsn.spack
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/check-spelling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,37 @@ name: Checks - spelling
on:
pull_request:
workflow_dispatch:
issue_comment:
types: [created]

jobs:
apply_spelling:
if: startsWith(github.event.comment.body, '/style')
runs-on: ubuntu-latest
steps:
# Checkout the GitHub created reference for the PR.
# The only way to do this is by using the "issue" number
# but that is really the PR number in this context.
# This is due to using an `issue_comment` event which
# is due to the GitHub Actions API that does not have
# a `pull_request_comment` event or something similar.
# This leaves us in a detached head state which is corrected
# in `apply-style/checkout.sh`
- name: Checkout pull request
uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.issue.number }}/head

- name: Checkout the right git ref
run: ./.github/actions/apply-style/checkout.sh

- name: Download the git diff from spelling_check
uses: actions/download-artifact@v4
with:
name: spelling.patch

spelling_check:
if: ${{ github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
steps:
- name: Install python3-pip
Expand Down
31 changes: 29 additions & 2 deletions .github/workflows/check-swig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,46 @@ name: Checks - swig
on:
pull_request:
workflow_dispatch:
issue_comment:
types: [created]

jobs:
swig:
apply_swig:
if: startsWith(github.event.comment.body, '/swig')
runs-on: ubuntu-latest
steps:
# Checkout the GitHub created reference for the PR.
# The only way to do this is by using the "issue" number
# but that is really the PR number in this context.
# This is due to using an `issue_comment` event which
# is due to the GitHub Actions API that does not have
# a `pull_request_comment` event or something similar.
# This leaves us in a detached head state which is corrected
# in `apply-style/checkout.sh`
- name: Checkout pull request
uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.issue.number }}/head

- name: Checkout the right git ref
run: ./.github/actions/apply-style/checkout.sh

- name: Download the git diff from swig_check
uses: actions/download-artifact@v4
with:
name: swig.patch

swig:
if: ${{ github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
steps:
- name: Install swig
run: |
git clone https://github.com/sundials-codes/swig
cd swig
./autogen.sh
./configure --prefix=/usr/
make
make
sudo make install
swig -version

Expand Down
Loading