diff --git a/.github/workflows/check-demo-notebooks.yml b/.github/workflows/check-demo-notebooks.yml index 61284ca70b..0e8d848b3f 100644 --- a/.github/workflows/check-demo-notebooks.yml +++ b/.github/workflows/check-demo-notebooks.yml @@ -3,7 +3,7 @@ name: Check Demos Match Notebooks on: - pull_request_target: + pull_request: types: [opened, synchronize, reopened] paths: - 'demo/**' @@ -26,13 +26,18 @@ jobs: - name: Assert Notebooks Match id: assertNotebooksMatch run: git status | grep "nothing to commit, working tree clean" - - name: Comment On PR - uses: thollander/actions-comment-pull-request@v1 - if: always() && (steps.assertNotebooksMatch.outcome == 'failure') + - name: Get PR Number + if: always() + run: | + python -c "import os;print(os.environ['GITHUB_REF'].split('/')[2])" > pr_number.txt + echo "PR_NUMBER=$(cat pr_number.txt)" >> $GITHUB_ENV + - name: Upload PR Number + if: always() + run: | + python -c "import json; json.dump({'pr_number': ${{ env.PR_NUMBER }}}, open('metadata.json', 'w'))" + - name: Upload metadata + if: always() + uses: actions/upload-artifact@v3 with: - message: | - The demo notebooks don't match the run.py files. Please run this command from the root of the repo and then commit the changes: - ```bash - pip install nbformat && cd demo && python generate_notebooks.py - ``` - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + name: metadata.json + path: metadata.json \ No newline at end of file diff --git a/.github/workflows/comment-pr.yml b/.github/workflows/comment-pr.yml new file mode 100644 index 0000000000..bb2a869851 --- /dev/null +++ b/.github/workflows/comment-pr.yml @@ -0,0 +1,44 @@ +on: + workflow_run: + workflows: [Check Demos Match Notebooks] + types: [completed] + +jobs: + comment-on-failure: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install Python + uses: actions/setup-python@v3 + with: + python-version: '3.9' + - name: Install pip + run: python -m pip install requests + - name: Download metadata + run: python scripts/download_artifacts.py ${{github.event.workflow_run.id }} metadata.json ${{ secrets.COMMENT_TOKEN }} --owner ${{ github.repository_owner }} + - run: unzip metadata.json.zip + - name: Pipe metadata to env + run: echo "pr_number=$(python -c 'import json; print(json.load(open("metadata.json"))["pr_number"])')" >> $GITHUB_ENV + - name: Comment On Notebook check fail + if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.name == 'Check Demos Match Notebooks'}} + uses: thollander/actions-comment-pull-request@v2 + with: + message: | + The demo notebooks don't match the run.py files. Please run this command from the root of the repo and then commit the changes: + ```bash + pip install nbformat && cd demo && python generate_notebooks.py + ``` + comment_includes: The demo notebooks don't match the run.py files + GITHUB_TOKEN: ${{ secrets.COMMENT_TOKEN }} + pr_number: ${{ env.pr_number }} + comment_tag: notebook-check + - name: Comment On Notebook check fail + if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.name == 'Check Demos Match Notebooks'}} + uses: thollander/actions-comment-pull-request@v2 + with: + message: | + 🎉 The demo notebooks match the run.py files! 🎉 + comment_includes: The demo notebooks match the run.py files! + GITHUB_TOKEN: ${{ secrets.COMMENT_TOKEN }} + pr_number: ${{ env.pr_number }} + comment_tag: notebook-check \ No newline at end of file