Skip to content

Commit

Permalink
Merge pull request #121 from wp-media/develop
Browse files Browse the repository at this point in the history
Release the new release note message on Slack containing the release note body
  • Loading branch information
MathieuLamiot authored Sep 6, 2024
2 parents 921defa + 9853dd8 commit 9731bb0
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 13 deletions.
116 changes: 105 additions & 11 deletions .github/workflows/ci-on_pr_main_bash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
name: CI Script - Python Lint and tests

on:
push:
branches:
- 'develop'
- 'master'
pull_request:
branches:
- 'develop'
Expand All @@ -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
Expand All @@ -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
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
12 changes: 12 additions & 0 deletions .github/workflows/pr-template-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: 'PR Template Checker'
on:
pull_request:
types: [edited, opened, synchronize, reopened]

jobs:
task-check:
runs-on: ubuntu-latest
steps:
- uses: wp-media/pr-checklist-action@master
with:
repo-token: "${{ secrets.PR_TEMPLATE_TOKEN }}"
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
freezegun==1.2.2
pytest-cov==5.0.0
diff-cover==9.1.1
4 changes: 3 additions & 1 deletion sources/handlers/GithubReleaseHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 9731bb0

Please sign in to comment.