From fd829bea4f2df2bde49da21547aa8d3e7d561fd7 Mon Sep 17 00:00:00 2001 From: Sascha Mann Date: Wed, 22 Apr 2020 23:55:52 +0200 Subject: [PATCH] CI: Add `/make-notebooks` command (#228) --- .github/workflows/make-notebooks.yml | 44 +++++++++++++++++++ .github/workflows/notebooks.yml | 2 +- bin/{check_notebooks => check-notebooks} | 2 +- ...ate_notebooks.jl => generate-notebooks.jl} | 0 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/make-notebooks.yml rename bin/{check_notebooks => check-notebooks} (83%) rename bin/{generate_notebooks.jl => generate-notebooks.jl} (100%) diff --git a/.github/workflows/make-notebooks.yml b/.github/workflows/make-notebooks.yml new file mode 100644 index 0000000000000..55f336f837647 --- /dev/null +++ b/.github/workflows/make-notebooks.yml @@ -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 diff --git a/.github/workflows/notebooks.yml b/.github/workflows/notebooks.yml index 2944aa53bb31e..29253d4def64c 100644 --- a/.github/workflows/notebooks.yml +++ b/.github/workflows/notebooks.yml @@ -15,4 +15,4 @@ jobs: uses: julia-actions/setup-julia@v1 - name: Check Notebooks - run: ./bin/check_notebooks + run: ./bin/check-notebooks diff --git a/bin/check_notebooks b/bin/check-notebooks similarity index 83% rename from bin/check_notebooks rename to bin/check-notebooks index 9c8939a7ac094..c8569f10a501b 100755 --- a/bin/check_notebooks +++ b/bin/check-notebooks @@ -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 diff --git a/bin/generate_notebooks.jl b/bin/generate-notebooks.jl similarity index 100% rename from bin/generate_notebooks.jl rename to bin/generate-notebooks.jl