From ff4df39d5f235e54d086302b25956d027ea3a287 Mon Sep 17 00:00:00 2001 From: Mathieu Lamiot Date: Thu, 8 Aug 2024 14:44:24 +0200 Subject: [PATCH 1/6] Test the pr template checker --- .github/workflows/test-pr-template.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/workflows/test-pr-template.yml diff --git a/.github/workflows/test-pr-template.yml b/.github/workflows/test-pr-template.yml new file mode 100644 index 0000000..bbc6791 --- /dev/null +++ b/.github/workflows/test-pr-template.yml @@ -0,0 +1,12 @@ +name: 'PR TaskList Completed Checker' +on: + pull_request: + types: [edited, opened, synchronize, reopened] + +jobs: + task-check: + runs-on: ubuntu-latest + steps: + - uses: wp-media/pr-checklist-action@test/adaptation-to-WPMedia-template + with: + repo-token: "${{ secrets.PR_TEMPLATE_TOKEN }}" \ No newline at end of file From 157ef8c8ee258b61ff707a911c9014156abc87fc Mon Sep 17 00:00:00 2001 From: Mathieu Lamiot Date: Thu, 22 Aug 2024 17:26:00 +0200 Subject: [PATCH 2/6] target the new branch for PR checker --- .github/workflows/test-pr-template.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-pr-template.yml b/.github/workflows/test-pr-template.yml index bbc6791..232087d 100644 --- a/.github/workflows/test-pr-template.yml +++ b/.github/workflows/test-pr-template.yml @@ -7,6 +7,6 @@ jobs: task-check: runs-on: ubuntu-latest steps: - - uses: wp-media/pr-checklist-action@test/adaptation-to-WPMedia-template + - uses: wp-media/pr-checklist-action@enhancement/update-for-PR-template-august-2024 with: repo-token: "${{ secrets.PR_TEMPLATE_TOKEN }}" \ No newline at end of file From 549ee2423c5d59709d29c45dd183c99eb79482cd Mon Sep 17 00:00:00 2001 From: Mathieu Lamiot Date: Mon, 26 Aug 2024 08:59:33 +0200 Subject: [PATCH 3/6] Update test-pr-template.yml --- .github/workflows/test-pr-template.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-pr-template.yml b/.github/workflows/test-pr-template.yml index 232087d..e8ed28b 100644 --- a/.github/workflows/test-pr-template.yml +++ b/.github/workflows/test-pr-template.yml @@ -7,6 +7,6 @@ jobs: task-check: runs-on: ubuntu-latest steps: - - uses: wp-media/pr-checklist-action@enhancement/update-for-PR-template-august-2024 + - uses: wp-media/pr-checklist-action@master with: - repo-token: "${{ secrets.PR_TEMPLATE_TOKEN }}" \ No newline at end of file + repo-token: "${{ secrets.PR_TEMPLATE_TOKEN }}" From 262698506ae71ae223749fa7958959f1c5c8086e Mon Sep 17 00:00:00 2001 From: Mathieu Lamiot Date: Mon, 26 Aug 2024 09:13:11 +0200 Subject: [PATCH 4/6] Fix GH action PR template check name --- .../workflows/{test-pr-template.yml => pr-template-checker.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{test-pr-template.yml => pr-template-checker.yml} (86%) diff --git a/.github/workflows/test-pr-template.yml b/.github/workflows/pr-template-checker.yml similarity index 86% rename from .github/workflows/test-pr-template.yml rename to .github/workflows/pr-template-checker.yml index e8ed28b..117497a 100644 --- a/.github/workflows/test-pr-template.yml +++ b/.github/workflows/pr-template-checker.yml @@ -1,4 +1,4 @@ -name: 'PR TaskList Completed Checker' +name: 'PR Template Checker' on: pull_request: types: [edited, opened, synchronize, reopened] From 45ca6dfa3cb7f5cdcb7eec74c9ec1311ac71a282 Mon Sep 17 00:00:00 2001 From: Mathieu Lamiot Date: Tue, 27 Aug 2024 15:16:23 +0200 Subject: [PATCH 5/6] add diff-cover to CI --- .github/workflows/ci-on_pr_main_bash.yml | 116 ++++++++++++++++++++--- requirements.txt | 4 +- 2 files changed, 108 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci-on_pr_main_bash.yml b/.github/workflows/ci-on_pr_main_bash.yml index c3fe5c0..6e4d9c7 100644 --- a/.github/workflows/ci-on_pr_main_bash.yml +++ b/.github/workflows/ci-on_pr_main_bash.yml @@ -4,10 +4,6 @@ name: CI Script - Python Lint and tests on: - push: - branches: - - 'develop' - - 'master' pull_request: branches: - 'develop' @@ -26,8 +22,26 @@ env: TBTT_NOTION_API_KEY: e jobs: - lint-and-test: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + cache: "pip" + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Run lint script + run: | + ./scripts/lint.sh + shell: bash + + tests: runs-on: ubuntu-latest strategy: fail-fast: false @@ -43,10 +57,90 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - python -m pip install flake8 pytest - - name: Run ci-on_pr_main script + pip install -r requirements.txt + + - name: Run pytest run: | - chmod +x ./scripts/ci-on_pr_main.sh - ./scripts/ci-on_pr_main.sh - shell: bash \ No newline at end of file + pytest -m "not staging_env" --cov=. --cov-report=xml + shell: bash + + - name: Upload coverage report + uses: actions/upload-artifact@v3 + with: + name: coverage-report-${{ github.run_id }} + path: coverage.xml + retention-days: 1 + + coverage: + runs-on: ubuntu-latest + needs: tests + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch all history for all branches + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + cache: "pip" + + - name: Download coverage report + uses: actions/download-artifact@v3 + with: + name: coverage-report-${{ github.run_id }} + + - name: Install dependencies + run: pip install git+https://github.com/MathieuLamiot/diff_cover + + - name: Generate diff-coverage report + if: github.event_name == 'pull_request' + run: | + diff-cover coverage.xml --compare-branch=origin/${{ github.base_ref }} --markdown-report diff-cover-report.md --exclude test*.py --fail-under=50 --expand_coverage_report + echo "DIFF_COVER_EXIT_STATUS=$?" >> $GITHUB_ENV + shell: bash + + - name: Delete previous diff-cover reports + uses: actions/github-script@v6 + with: + script: | + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number + }); + + for (const comment of comments) { + if (comment.user.login === 'github-actions[bot]' && comment.body.includes('# Diff Coverage')) { + console.log(`Deleting comment with ID: ${comment.id}`); + await github.rest.issues.deleteComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: comment.id + }); + } + } + env: + GITHUB_TOKEN: ${{ secrets.DIFF_COVER_COMMENT }} + + - name: Post diff-cover report to PR + if: github.event_name == 'pull_request' + uses: actions/github-script@v6 + with: + script: | + const fs = require('fs'); + const comment = fs.readFileSync('diff-cover-report.md', 'utf8'); + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: comment, + }); + - name: Fail job if coverage is below threshold + if: github.event_name == 'pull_request' + run: | + if [[ "${{ env.DIFF_COVER_EXIT_STATUS }}" -ne 0 ]]; then + echo "Coverage below threshold; failing the job." + exit 1 + fi + shell: bash \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 297bcbe..f2fa7aa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -50,4 +50,6 @@ Werkzeug==2.3.6 wrapt==1.15.0 yarl==1.9.2 flask-slacksigauth==1.0.9 -freezegun==1.2.2 \ No newline at end of file +freezegun==1.2.2 +pytest-cov==5.0.0 +diff-cover==9.1.1 \ No newline at end of file From 9853dd8ddd48566bb8966114db6eb7b93dc2595c Mon Sep 17 00:00:00 2001 From: Mathieu Lamiot Date: Fri, 6 Sep 2024 20:48:32 +0200 Subject: [PATCH 6/6] Add Release note body to the Slack message on Github release --- sources/handlers/GithubReleaseHandler.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sources/handlers/GithubReleaseHandler.py b/sources/handlers/GithubReleaseHandler.py index 438c1a5..9ccc15c 100644 --- a/sources/handlers/GithubReleaseHandler.py +++ b/sources/handlers/GithubReleaseHandler.py @@ -33,7 +33,9 @@ def process_release(self, app_context, release_params): # Send a message to Slack text = "The draft release note for " + repository_readable_name + " " + release_params.version - text += " is available on <" + notion_url + "|Notion>. " + text += " is available on <" + notion_url + "|Notion>." + text += "\n" + text += release_params.body blocks = self.slack_message_factory.get_release_note_review_blocks(text)