Skip to content

Commit

Permalink
CI: Add /make-notebooks command (JuliaLang#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaschaMann authored Apr 22, 2020
1 parent b644c47 commit fd829be
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/make-notebooks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: 'Generate Jupyter notebooks'

on:
issue_comment:
types: [created]

jobs:
format:
name: 'Generate Jupyter notebooks'
runs-on: ubuntu-latest
if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/make-notebooks')
steps:
- name: 'Checkout code'
run: |
PR_DATA="/tmp/pr.json"
jq -r ".issue.pull_request.url" "$GITHUB_EVENT_PATH" | \
xargs curl --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -o "$PR_DATA" --url
HEAD_REF=$(jq -r ".head.ref" "$PR_DATA")
HEAD_REPO=$(jq -r '.head.repo.clone_url | sub("https://"; "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@")' "$PR_DATA")
git clone $HEAD_REPO .
git checkout -b "$HEAD_REF" "origin/$HEAD_REF"
- name: 'Generate notebooks'
run: julia bin/generate-notebooks.jl

- name: 'Commit generated notebooks'
run: |
# Check if there is nothing to commit (i.e. no formatting changes made)
if [ -z "$(git status --porcelain)" ]; then
echo "Notebooks have already been generated."
exit 0
fi
# Setup the git user (required to commit anything)
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
# Commit the changes
git add .
git commit -m "Generate notebooks"
git push
2 changes: 1 addition & 1 deletion .github/workflows/notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
uses: julia-actions/setup-julia@v1

- name: Check Notebooks
run: ./bin/check_notebooks
run: ./bin/check-notebooks
2 changes: 1 addition & 1 deletion bin/check_notebooks → bin/check-notebooks
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ changed_files=$(git diff --name-only)
if [ ! -z "$changed_files" ]; then
echo "The following notebooks diverge from the auto-generated notebooks:"
echo "$changed_files"
echo "Please run bin/generate_notebooks.jl to update the notebooks"
echo "Please run bin/generate-notebooks.jl or comment `/make-notebooks` to update the notebooks"
git reset HEAD
exit 1
fi
Expand Down
File renamed without changes.

0 comments on commit fd829be

Please sign in to comment.