From 3b1f4ab9496fad03db8b0178833172ec511b516c Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff Date: Thu, 15 Aug 2024 00:01:28 +0100 Subject: [PATCH] Add PR review action --- .github/review_pull_request.py | 21 +++++++++++++++++++ .github/workflows/pull_request.yaml | 32 +++++++++++++++++++++++++++++ .github/workflows/push.yaml | 2 +- 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 .github/review_pull_request.py create mode 100644 .github/workflows/pull_request.yaml diff --git a/.github/review_pull_request.py b/.github/review_pull_request.py new file mode 100644 index 0000000..a646b40 --- /dev/null +++ b/.github/review_pull_request.py @@ -0,0 +1,21 @@ +import pandas as pd +from policyengine_us_data.data_storage import STORAGE_FOLDER +from IPython.display import Markdown + +def main(): + df = pd.read_csv(STORAGE_FOLDER / "evaluation.csv") + + most_recent_rows = df[df.Date == df.Date.max()].sort_values(["Variable", "Time period"]).set_index(["Variable", "Time period"]).Total + second_most_recent_rows = df[df.Date == df.Date.sort_values().unique()[-2]].reset_index(drop=True).sort_values(["Variable", "Time period"]).set_index(["Variable", "Time period"]).Total + + diff = (most_recent_rows - second_most_recent_rows) + # Convert to df + diff = diff.reset_index() + table = diff.to_markdown(index=False) + + review_text = f"""## National projection changes\n\n{table}""" + + print(review_text) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml new file mode 100644 index 0000000..b6b910f --- /dev/null +++ b/.github/workflows/pull_request.yaml @@ -0,0 +1,32 @@ +name: Pull request + +on: + pull_request: + branches: + - main + +jobs: + build: + name: Build and test + runs-on: ubuntu-latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + + - name: Install dependencies + run: make install + + - name: Run tests + run: make test + + - name: Run evaluation + run: make evaluate + + - name: Add review comment + run: python .github/review_pull_request.py \ No newline at end of file diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index bb2ad24..a7332c2 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -29,4 +29,4 @@ jobs: run: make evaluate - name: Upload evaluation - run: python .github/upload_evaluation \ No newline at end of file + run: python .github/upload_evaluation.py \ No newline at end of file