Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Use reusable workflow with pre-commit #1

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .commitlintrc.js → .commitlintrc.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
extends: [
'@commitlint/config-conventional'
],
Expand Down
124 changes: 10 additions & 114 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,122 +1,18 @@
name: linkedevents-ci
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
SECRET_KEY: topsecret123
POSTGRES_DB: test_linkedevents
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
DATABASE_URL: "postgis://postgres:postgres@localhost/test_linkedevents"
FIELD_ENCRYPTION_KEYS: c87a6669a1ded2834f1dfd0830d86ef6cdd20372ac83e8c7c23feffe87e6a051

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python: [3.9]
services:
postgres:
image: postgis/postgis:14-3.2-alpine
env:
# Note: not redundant, parent env is not applied to service
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test_linkedevents
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- name: Checkout
uses: actions/checkout@v3
with:
# Required by Sonar
fetch-depth: 0

- name: Update apt
run: sudo apt-get update

- name: psycopg2 prerequisites
run: sudo apt-get install libpq-dev

- name: System requirements for Django
run: sudo apt-get install gdal-bin gettext postgresql-client

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
cache: pip

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt -r requirements-dev.txt

- name: Configure sysctl limits
run: |
sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144

- name: Check migrations
run: |
python manage.py makemigrations --dry-run --check

- name: Apply migrations
run: |
python manage.py migrate

- name: Compile translations
run: |
django-admin compilemessages

- name: Check OpenAPI schema
run: |
python manage.py spectacular --lang en --validate --fail-on-warn --api-version v1

- name: Run Ruff lint
uses: astral-sh/ruff-action@v1
with:
version: 0.7.1

- name: Run Ruff format check
uses: astral-sh/ruff-action@v1
with:
version: 0.7.1
args: "format --check"

- name: Check commitlint
uses: wagoid/commitlint-github-action@0d749a1a91d4770e983a7b8f83d4a3f0e7e0874e # v5.4.4

# With pytest-cov use: --cov=.
# Some errors, skipping --doctest-modules for now
- name: Run tests
uses: liskin/gh-problem-matcher-wrap@v2
with:
linters: pytest
run: pytest -ra -vvv --cov=.

- name: Codecov
uses: codecov/codecov-action@v3

# Without this workaround Sonar reports a warning about an incorrect source path
- name: Override coverage report source path for Sonar
run: sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage.xml

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
common:
uses: tuomas777/.github/.github/workflows/ci-django-api.yml@reusable_workflow_precommit
secrets: inherit
with:
python-version: 3.9
postgres-major-version: 14
use-postgis: true
extra-commands: |
python manage.py spectacular --lang en --validate --fail-on-warn --api-version v1
2 changes: 1 addition & 1 deletion audit_log/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models
from django.utils.translation import gettext as _
from django.utils.translation import gettext_lazy as _


class AuditLogEntry(models.Model):
Expand Down
18 changes: 9 additions & 9 deletions helevents/templates/rest_framework/keyword_list.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<div class="panel panel-default">
<div class="panel-body">
<h2 id="using-keyword-endpoint">Using the keyword endpoint</h2>
<p>Here, categories for events are listed. Events in each category can be found at the
<p>Here, categories for events are listed. Events in each category can be found at the
<code>event</code> endpoint using the query parameter <code>keyword</code>. The common keywords
used in all events originate from the <a href="https://finto.fi/yso/en/">general Finnish ontology (yso)</a>,
hence the format <code>yso:p4354</code>. Default ordering is decreasing order by the number of events found.</p>
<p>The most common event categories are listed in the two keyword sets
<a href="https://api.hel.fi/linkedevents/v1/keyword_set/helsinki:topics/">helsinki:topics</a> and
<a href="https://api.hel.fi/linkedevents/v1/keyword_set/helsinki:audiences/">helsinki:audiences</a>,
<p>The most common event categories are listed in the two keyword sets
<a href="https://api.hel.fi/linkedevents/v1/keyword_set/helsinki:topics/">helsinki:topics</a> and
<a href="https://api.hel.fi/linkedevents/v1/keyword_set/helsinki:audiences/">helsinki:audiences</a>,
which list the YSO keywords that are present in most events to specify event main topic and audience.</p>

<h4 id="keyword-text">Keyword text</h4>
Expand All @@ -17,7 +17,7 @@ <h4 id="keyword-text">Keyword text</h4>
<p><a href="?text=lapset" title="json">See the result</a></p>

<h4 id="keyword-free-text">Free text</h4>
<p>While the previous search is looking for the keywords containg exact matches of the search string,
<p>While the previous search is looking for the keywords containg exact matches of the search string,
<code>free_text</code> retrieves keywords on the basis of similarity. Results are
sorted by similarity.</p>
<p>Example:</p>
Expand All @@ -31,22 +31,22 @@ <h4 id="keyword-source">Keyword source</h4>
<p><a href="?data_source=yso" title="json">See the result</a></p>

<h4 id="show-keywords-with-upcoming-events">Show only keywords with the upcoming events</h4>
<p>To show only the keywords which are used in the upcoming events supply the
<p>To show only the keywords which are used in the upcoming events supply the
<code>has_upcoming_events</code> query parameter.</p>
<p>For example:</p>
<pre><code>keyword/?has_upcoming_events=True</code></pre>
<p><a href="?has_upcoming_events=True" title="json">See the result</a></p>

<h4 id="showing-all-keyword">Showing all keywords</h4>
<p>By default, only those keywords which have listed events are
<p>By default, only those keywords which have listed events are
displayed. You may display keywords with zero <code>n_events</code> with the
query parameter <code>show_all_keywords</code>.</p>
<p>For example:</p>
<pre><code>keyword/?show_all_keywords=True</code></pre>
<p><a href="?show_all_keywords=True" title="json">See the result</a></p>

<h4 id="showing-deprecated-keyword">Showing deprecated keywords</h4>
<p>By default, deprecated keywords are not displayed. You may also display deprecated keywords with the
<p>By default, deprecated keywords are not displayed. You may also display deprecated keywords with the
query parameter <code>show_deprecated</code>.</p>
<p>For example:</p>
<pre><code>keyword/?show_deprecated=True</code></pre>
Expand Down
4 changes: 2 additions & 2 deletions helevents/templates/rest_framework/keyword_set_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<div class="panel-body">
<h2 id="using-keyword-set-endpoint">Using the keyword set endpoint</h2>
<p>Here, the preferred sets of common keywords are listed.</p>
<p>We recommend using the 20 piece keyword set <code>helsinki:topics</code> for general event grouping and
<code>helsinki:audiences</code> for sorting by target group. These sets are used by the City of Helsinki in
<p>We recommend using the 20 piece keyword set <code>helsinki:topics</code> for general event grouping and
<code>helsinki:audiences</code> for sorting by target group. These sets are used by the City of Helsinki in
categorizing the majority of events in the API.</p>

<h3 id="text">Search keyword sets</h3>
Expand Down
4 changes: 2 additions & 2 deletions helevents/templates/rest_framework/language_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ <h2 id="using-language-endpoint">Using the language endpoint</h2>
and <code>ar</code> are supported.</p>
<p>Events organized in or translated to a specific language can be found at the <code>event</code>
endpoint using the query parameter <code>language</code>.</p>

<h3 id="language-service-language">Language as service language</h3>
<p>To find out languages which can or cannot be used as service language in a registration,
<p>To find out languages which can or cannot be used as service language in a registration,
use the query parameter<code>service_language</code>.</p>
<p>Example:</p>
<pre><code>event/?service_language=true</code></pre>
Expand Down
4 changes: 2 additions & 2 deletions helevents/templates/rest_framework/organization_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ <h2 id="using-organization-endpoint">Using the organization endpoint</h2>
can be found at the <code>event</code> endpoint using the query parameter <code>publisher</code>.</p>

<h4 id="organization-child">Organization ancestors</h4>
<p>To find parent organization and all its ancestors for the given organization id use the query
<p>To find parent organization and all its ancestors for the given organization id use the query
parameter <code>child</code>.</p>
<p>Example:</p>
<pre><code>organization/?child=ahjo:100</code></pre>
<p><a href="?child=ahjo:100" title="json">See the result</a></p>

<h4 id="organization-parent">Organization descendants</h4>
<p>To find all suborganizations and their descendants for the given organization id use the query
<p>To find all suborganizations and their descendants for the given organization id use the query
parameter <code>parent</code>.</p>
<p>Example:</p>
<pre><code>organization/?parent=ahjo:100</code></pre>
Expand Down
4 changes: 2 additions & 2 deletions helevents/templates/rest_framework/registration_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ <h3 id="event-type">Event type</h4>
<p>Example:</p>
<pre><code>registration/?event_type=course</code></pre>
<p><a href="?event_type=course" title="json">See the result</a></p>

<h3 id="getting-detailed-data">Getting detailed data</h2>
<p>In the default case, event, keywords, locations, and other fields that
refer to separate resources are only displayed as simple references.</p>
<p>If you want to include the complete data from related resources in
the current response, use the keyword <code>include</code>.</p>
the current response, use the keyword <code>include</code>.</p>
<p><strong> Please note, however,
that including all the resources inlined in *every* event will result in a huge number
of duplicate data in the json, making the json very slow to generate and process and causing
Expand Down
44 changes: 22 additions & 22 deletions helevents/templates/rest_framework/root.html
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
<div class="panel panel-default">
<div class="panel-body">
<p> This Linked events API contains event data from the City of Helsinki, including
<a href="http://www.myhelsinki.fi/" title="Helsinki Marketing">Helsinki Marketing</a>,
<a href="https://www.hel.fi/helsinki/fi/kulttuuri-ja-vapaa-aika/kulttuuri/kulttuuritalot/" title="Kulke">Helsinki Cultural Centres</a>
<p> This Linked events API contains event data from the City of Helsinki, including
<a href="http://www.myhelsinki.fi/" title="Helsinki Marketing">Helsinki Marketing</a>,
<a href="https://www.hel.fi/helsinki/fi/kulttuuri-ja-vapaa-aika/kulttuuri/kulttuuritalot/" title="Kulke">Helsinki Cultural Centres</a>
and the <a href="http://www.helmet.fi/">Helmet metropolitan area public libraries</a>.</p>
<p> The API is developed by the
<a href="http://dev.hel.fi">City of Helsinki Open Software Development team</a>, who also provide
<p> The API is developed by the
<a href="http://dev.hel.fi">City of Helsinki Open Software Development team</a>, who also provide
the <a href="http://dev.hel.fi/apis/linked-events">complete API specifications</a>.
The location information is linked to the City of Helsinki registry of service units which contains
e.g. information about accessibility. In the API, you can search data by date or location as well
The location information is linked to the City of Helsinki registry of service units which contains
e.g. information about accessibility. In the API, you can search data by date or location as well
as bounding box.</p>

<h2>Data license</h2>
<p>Unless otherwise stated, the data is licensed using CC BY 4.0 license:
<a href="http://creativecommons.org/licenses/by/4.0/deed.fi">FI</a> |
<a href="http://creativecommons.org/licenses/by/4.0/deed.sv">SV</a> |
<a href="http://creativecommons.org/licenses/by/4.0/deed.en">EN</a>.</p>
<p>However, some images may only be used for marketing the specific event and may not be used outside this context.
<p>However, some images may only be used for marketing the specific event and may not be used outside this context.
These images are marked as <em>event_only</em> in the API. The <em>event_only</em> license is as follows:</p>
<h4>FI</h4>
<p>Helsingin kaupungilla on kuviin kaikki oikeudet. Mikäli rajapinnassa jaettavan kuvan tietojen
kohdassa <em>license</em> on merkintä <em>event_only</em>, saa kuvaa käyttää ainoastaan kuvan
tapahtumaa käsittelevään tiedotukseen ja viestintään. Kuvien käyttäminen tähän tarkoitukseen
on käyttäjälle ilmaista. Kuvan käyttö tai siirto muihin tarkoituksiin on kielletty. Kuvia
<p>Helsingin kaupungilla on kuviin kaikki oikeudet. Mikäli rajapinnassa jaettavan kuvan tietojen
kohdassa <em>license</em> on merkintä <em>event_only</em>, saa kuvaa käyttää ainoastaan kuvan
tapahtumaa käsittelevään tiedotukseen ja viestintään. Kuvien käyttäminen tähän tarkoitukseen
on käyttäjälle ilmaista. Kuvan käyttö tai siirto muihin tarkoituksiin on kielletty. Kuvia
käytettäessä on ehdottomasti mainittava kuvien lähde ja kuvaaja.</p>
<h4>SV</h4>
<p>Helsingfors stad äger alla rättigheter till bilderna. Om beteckningen <em>event_only</em>
förekommer under <em>license</em> i uppgifterna för en bild som delas i gränssnittet, får
bilden användas endast för informering eller kommunikation som gäller evenemanget på bilden.
Att använda bilderna för det här ändamålet är gratis. Att använda eller flytta bilden för
andra ändamål är förbjudet. Vid användning av bilder ska källan och fotografen absolut
<p>Helsingfors stad äger alla rättigheter till bilderna. Om beteckningen <em>event_only</em>
förekommer under <em>license</em> i uppgifterna för en bild som delas i gränssnittet, får
bilden användas endast för informering eller kommunikation som gäller evenemanget på bilden.
Att använda bilderna för det här ändamålet är gratis. Att använda eller flytta bilden för
andra ändamål är förbjudet. Vid användning av bilder ska källan och fotografen absolut
nämnas.</p>
<h4>EN</h4>
<p>The City of Helsinki reserves all rights to the images. If the data at <em>license</em> of an
image shared in the interface contains the text <em>event_only</em>, then the image can only
be used for information and communications connected to the event depicted in the image.
The images can be used free of charge for this purpose. To use or move the image for other
purposes is forbidden. The source and photographer must absolutely be mentioned when using
<p>The City of Helsinki reserves all rights to the images. If the data at <em>license</em> of an
image shared in the interface contains the text <em>event_only</em>, then the image can only
be used for information and communications connected to the event depicted in the image.
The images can be used free of charge for this purpose. To use or move the image for other
purposes is forbidden. The source and photographer must absolutely be mentioned when using
an image.</p>
</div>
</div>
Loading