Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Morsey187 committed Dec 16, 2023
0 parents commit c7204ed
Show file tree
Hide file tree
Showing 27 changed files with 1,059 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[run]
branch = True
include = wagtail_defender/*
omit = */migrations/*,*/tests/*

[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover

# Don't complain about missing debug-only code:
def __repr__
if self\.debug

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError

# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:

ignore_errors = True
24 changes: 24 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
root = true

[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf

[Makefile]
indent_style = tab

[*.py]
max_line_length = 88

[*.{html,rst,md}]
indent_size = 4

[*.{js,ts,tsx,json,yml,yaml,css,scss}]
indent_size = 2

[*.md]
trim_trailing_whitespace = false
26 changes: 26 additions & 0 deletions .github/scripts/report_nightly_build_failure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
Called by GH Actions when the nightly build fails.
This reports an error to the #nightly-build-failures Slack channel.
"""
import os

import requests


if "SLACK_WEBHOOK_URL" in os.environ:
print("Reporting to #nightly-build-failures slack channel")
response = requests.post(
os.environ["SLACK_WEBHOOK_URL"],
json={
"text": "A Nightly build failed. See https://github.com/Morsey187/wagtail-defender/actions/runs/"
+ os.environ["GITHUB_RUN_ID"],
},
)

print("Slack responded with:", response)

else:
print(
"Unable to report to #nightly-build-failures slack channel because SLACK_WEBHOOK_URL is not set"
)
35 changes: 35 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Nightly Wagtail Test

on:
schedule:
- cron: '0 1 * * *'
# At 01:00, daily
workflow_dispatch:

jobs:
nightly-wagtail-test:
runs-on: ubuntu-latest
env:
WEBHOOK_EXISTS: ${{ secrets.SLACK_WEBHOOK_URL != '' }}

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'

- run: git clone https://github.com/wagtail/wagtail.git

- run: python -m pip install flit
- run: flit install --deps production --extras testing
- run: python -m pip install ./wagtail

- run: python testmanage.py test

- name: Report failure
run: |
python -m pip install requests
python ./.github/scripts/report_nightly_build_failure.py
if: ${{ failure() && env.WEBHOOK_EXISTS == 'true' }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
51 changes: 51 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# See https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
# for a detailed guide
name: Publish to PyPI

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read # to fetch code (actions/checkout)
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flit
python -m flit install --symlink
- name: Build
run: python -m flit build

- uses: actions/upload-artifact@v3
with:
path: ./dist

publish:
needs: build
runs-on: ubuntu-latest
permissions:
contents: none
id-token: write # required for trusted publishing
environment: publish
steps:
- uses: actions/download-artifact@v3

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: artifact/
print-hash: true
83 changes: 83 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: defender CI

on:
push:
branches:
- main
- 'stable/**'

pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: '3.8'
- uses: pre-commit/action@v3.0.0

test-sqlite:
runs-on: ubuntu-latest
needs: lint
strategy:
matrix:
python: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install .[ci]
- name: Test
run: tox
env:
DB: sqlite

test-postgres:
runs-on: ubuntu-latest
needs: lint
strategy:
matrix:
python: ['3.8', '3.9', '3.10', '3.11', '3.12']

services:
postgres:
image: ${{ matrix.postgres || 'postgres:11' }}
env:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install .[ci]
- name: Test
run: tox
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/wagtail_defender
DB: postgres
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
__pycache__/
*.py[co]
/build
/dist
/wagtail_defender.egg-info
/.coverage
/htmlcov
/.tox
/.venv
/venv
/.vscode
/site
/test_wagtail_defender.db
/node_modules
/test-static
/test-media
44 changes: 44 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
ci:
autofix_prs: false

default_language_version:
python: python3

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-json
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
- id: check-yaml
args: ['--unsafe']
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
language_version: python3
args: ['--target-version', 'py38']
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies: [black==23.9.1]
- repo: https://github.com/pycqa/isort
# isort config is in setup.cfg
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
# flake8 config is in setup.cfg
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-comprehensions
42 changes: 42 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# defender Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.1.0] - 2023-12-16

### Added

- ...

### Changed

- ...

### Removed

- ...

<!-- TEMPLATE - keep below to copy for new releases -->
<!--
## [x.y.z] - YYYY-MM-DD
### Added
- ...
### Changed
- ...
### Removed
- ...
-->
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Contributing to defender
Loading

0 comments on commit c7204ed

Please sign in to comment.