Skip to content
This repository was archived by the owner on Jun 21, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"env": {
"test": {
"presets": [
[
"@babel/preset-env",
{ "targets": { "esmodules": false, "node": "current" } }
],
"babel-preset-vite",
"@babel/preset-typescript"
]
}
}
}
46 changes: 46 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: release
on:
release:
types: [published]
jobs:
release:
runs-on: ubuntu-latest
container:
image: ghcr.io/commonknowledge/do-app-baseimage-django-node:364385f9d196a2bbe2d5faea025520cc0316501f
# Workaround for: https://github.com/actions/checkout/issues/211
options: --user 1001
volumes:
- "/home/runner/docker/.cache:/home/app/.cache"
env:
DATABASE_URL: postgres://postgres:postgres@db:5432/postgres
DEBUG: True
PY_IGNORE_IMPORTMISMATCH: 1
services:
db:
image: kartoza/postgis:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DBNAME: postgres
POSTGRES_HOSTNAME: postgres
POSTGRES_PORT: 5432
steps:
- uses: actions/checkout@v2
- name: setup git config
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
- uses: actions/cache@v2
with:
path: /home/runner/docker/.cache/poetry
key: do-app-baseimage-django-node:364385f9d196a2bbe2d5faea025520cc0316501f-poetry-${{ hashFiles('poetry.lock') }}
- run: make install
- run: .github/bin/wait-for-it.sh db:5432
- run: make lint
- run: make prepare-release
env:
GITHUB_REF: v1.0.1
- run: make release
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Ignore artifacts:
dist
build
static
node_modules
.*_cache
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"python.pythonPath": "/home/vscode/.cache/pypoetry/virtualenvs/groundwork-SsXfCHgY-py3.9/bin/python",
"python.pythonPath": "/home/vscode/.cache/pypoetry/virtualenvs/groundwork-django-SsXfCHgY-py3.9/bin/python",
"python.linting.pylintEnabled": false,
"python.linting.mypyEnabled": false,
"python.linting.banditEnabled": true,
Expand Down
47 changes: 37 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ migrate:
poetry run python manage.py migrate

.PHONY: bootstrap
bootstrap: install pre-commit-install migrate
bootstrap: poetry-download install pre-commit-install migrate
touch local.py


Expand Down Expand Up @@ -59,7 +59,7 @@ python-api-docs:
component-docs:
rm -rf docs/components
mkdir -p docs/components
cp pyck/**/docs/*.components.md docs/components/
cp groundwork/**/docs/*.components.md docs/components/

.PHONY: api-docs
api-docs: python-api-docs component-docs
Expand Down Expand Up @@ -88,31 +88,58 @@ test:
check-codestyle:
poetry run isort --diff --check-only --settings-path pyproject.toml ./
poetry run black --diff --check --config pyproject.toml ./
poetry run darglint --docstring-style google --verbosity 2 pyck
poetry run darglint --docstring-style google --verbosity 2 groundwork
yarn tsc --noemit
yarn prettier --check .

.PHONY: check-safety
check-safety:
poetry check
poetry run safety check --full-report
poetry run bandit -ll --recursive pyck tests
poetry run bandit -ll --recursive groundwork tests

.PHONY: lint
lint: check-codestyle check-safety test

.PHONY: ci
ci: lint
ci: lint build-docs build-js build-python
poetry run pytest
yarn test


#* Assets
#* Build & release flow

.PHONY: build
build:
.PHONY: set-release-version
set-release-version:
yarn version --new-version $$(poetry run python bin/get_release_version.py)
poetry version $$(poetry run python bin/get_release_version.py)

.PHONY: build-js
build-js:
yarn vite build --mode lib
yarn vite build --mode bundled
yarn vite build
yarn vite build --mode test-utils
rm -rf build/ts
yarn tsc
node bin/api-extractor.js

.PHONY: build-python
build-python: build-js
rm -rf groundwork/core/static
cp -r build/bundled groundwork/core/static
poetry build
rm -rf groundwork/core/static

.PHONY: prepare-release
prepare-release: clean-all set-release-version build-js build-python

.PHONY: release
release:
echo //registry.npmjs.org/:_authToken=$$NPM_TOKEN > ~/.npmrc
npm publish
poetry config pypi-token.pypi $$PYPI_TOKEN
poetry publish



#* Cleaning
Expand All @@ -123,7 +150,7 @@ pycache-remove:

.PHONY: build-remove
build-remove:
rm -rf build/ dist/ docs/api/ docs/components/ temp/
rm -rf build/ groundwork/core/static/ docs/api/ docs/components/ temp/

.PHONY: clean-all
clean-all: pycache-remove build-remove
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Pycommonknowledge
# Groundwork

An integrated Django and Javascript framework for people who build tools for organisers.

Expand Down
27 changes: 27 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Security

## 🔐 Reporting Security Issues

> Do not open issues that might have security implications!
> It is critical that security related issues are reported privately so we have time to address them before they become public knowledge.

Vulnerabilities can be reported by emailing core members:

- commonknowledge [developers@commonknowledge.coop](mailto:developers@commonknowledge.coop)

Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:

- Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
- Full paths of source file(s) related to the manifestation of the issue
- The location of the affected source code (tag/branch/commit or direct URL)
- Any special configuration required to reproduce the issue
- Environment (e.g. Linux / Windows / macOS)
- Step-by-step instructions to reproduce the issue
- Proof-of-concept or exploit code (if possible)
- Impact of the issue, including how an attacker might exploit the issue

This information will help us triage your report more quickly.

## Preferred Languages

We prefer all communications to be in English.
2 changes: 2 additions & 0 deletions __mocks__/mapbox-gl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class MockMap extends EventEmitter implements MockedMethods {
return this.options?.container as HTMLElement;
}

resize() {}

addLayer(layer: mapboxgl.AnyLayer): mapboxgl.Map {
this.layers.set(layer.id, layer);
return this as any;
Expand Down
58 changes: 58 additions & 0 deletions bin/api-extractor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const { ExtractorConfig, Extractor } = require("@microsoft/api-extractor");

const IGNORED_SYMBOLS = ["mapbox-gl"];

/**
* Rollup the d.ts files produced by typescript into single files to go with the rolled-up library.
*/
const invoke = (slug) => {
const packageJson = require("../package.json");
const peerDependencies = new Set([
...Object.keys(packageJson.peerDependencies),
...IGNORED_SYMBOLS,
]);

const config = ExtractorConfig.prepare({
configObject: {
mainEntryPointFilePath: `<projectFolder>/build/ts/frontend/index.${slug}.d.ts`,
bundledPackages: [
...Object.keys(packageJson.dependencies ?? {}),
...Object.keys(packageJson.devDependencies).filter(
(x) => !peerDependencies.has(x)
),
],
projectFolder: process.cwd(),
compiler: {
tsconfigFilePath: "<projectFolder>/tsconfig.json",
},
dtsRollup: {
enabled: true,
publicTrimmedFilePath: `<projectFolder>/build/${slug}/index.d.ts`,
},
apiReport: {
enabled: false,
reportFileName: "<unscopedPackageName>.api.md",
},
docModel: {
enabled: false,
},
tsdocMetadata: {
enabled: false,
},
},
configObjectFullPath: undefined,
packageJson,
packageJsonFullPath: require.resolve("../package.json"),
});

Extractor.invoke(config, {
localBuild: true,
showVerboseMessages: true,
});
};

// import * from 'groundwork-django/test-utils'
invoke("test-utils");

// import * from 'groundwork-django'
invoke("lib");
2 changes: 1 addition & 1 deletion bin/gendocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
django.setup()


modules = [app for app in settings.INSTALLED_APPS if app.startswith("pyck.")]
modules = [app for app in settings.INSTALLED_APPS if app.startswith("groundwork.")]
context = pdoc.Context()

modules = [pdoc.Module(mod, context=context) for mod in modules]
Expand Down
17 changes: 17 additions & 0 deletions bin/get_release_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os
import re
import sys


# Exp
def get_version(ref_name):
if ref_name:
ref_match = re.search(r"v(\d+)\.(\d+)\.(\d+)$", ref_name)
if ref_match is None:
return ()

return ref_match.groups()


if __name__ == "__main__":
print(".".join(get_version(os.getenv("GITHUB_REF_NAME"))))
10 changes: 8 additions & 2 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ We don't want to have an excessively prescriptive sense of what is 'in' and 'out

## New features and functionality

1. The first stage of adding a new module happens within an application that uses it. Use the convention of placing it in the `commonknowledge.experimental` package within your application repository to indicate to other people that it's in the process of being abstracted and that they should be mindful of these guidelines.
2. Remove any dependencies from application code outside the `commonknowledge` package. Start to think about how it can be tested in isolation (if it isn't already).
1. The first stage of adding a new module happens within an application that uses it. Use the convention of placing it in the `groundwork.experimental` package within your application repository to indicate to other people that it's in the process of being abstracted and that they should be mindful of these guidelines.
2. Remove any dependencies from application code outside the `groundwork` package. Start to think about how it can be tested in isolation (if it isn't already).
3. Open a feature request against this repository. Describe the new feature, include links to your implementation other repositories. If the application is publicly accessible, include links to it in the live app.
4. Discuss and refine the API with other contributors.
5. When the feature request is accepted, fork this repository (or create a feature branch if you have write access) and commit the feature implementation. Ensure that you have good test coverage of both Python and Javascript components and all public API methods are documented.
Expand All @@ -24,3 +24,9 @@ Some additional pointers:
## Improvements to documentation

Yes please!

## Releases

Releases are published to package managers when a release tag in `vX.X.X` format is published in GitHub.

We follow the [Semantic Versioning](https://semver.org/) spec for release numbers.
Loading