name: Notebook Check Pull Request on: pull_request_target: types: [opened, reopened] permissions: contents: read jobs: comment-welcome: permissions: contents: read pull-requests: write runs-on: ubuntu-latest steps: - name: Fetch pull request branch uses: actions/checkout@v4 with: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.event.pull_request.head.sha }} - name: Fetch base develop branch run: git fetch -u "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" develop:develop - name: Create message env: HEAD_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name }} HEAD_REF: ${{ github.event.pull_request.head.ref }} PR_NUM: ${{ github.event.pull_request.number }} run: | # Preview links and tool usage only needed for notebook changes. readarray -t changed_notebooks < <(git diff --name-only develop | grep '\.ipynb$' || true) if [[ ${#changed_notebooks[@]} == 0 ]]; then echo "No notebooks modified in this pull request." else msg="
git pull origin $HEAD_REF\n"
fi
echo "MESSAGE=$msg" >> $GITHUB_ENV
- name: Post comment
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_URL: ${{ github.event.pull_request.issue_url }}
run: |
# Env var defined in previous step. Escape string for JSON.
body="$(echo -n -e $MESSAGE | python3 -c 'import json,sys; print(json.dumps(sys.stdin.read()))')"
# Add comment to pull request.
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $GITHUB_TOKEN" \
"${ISSUE_URL}/comments" \
--data "{\"body\": $body}"