diff --git a/.github/workflows/release_wheel.yml b/.github/workflows/release_wheel.yml index ae10b9b..fbc07ab 100644 --- a/.github/workflows/release_wheel.yml +++ b/.github/workflows/release_wheel.yml @@ -3,41 +3,103 @@ name: Build and release wheel on: push: branches: - - "master" + - "master" tags: - '[0-9]+.[0-9]+.[0-9]+' - '[0-9]+.[0-9]+.[0-9]+rc[x0-9]+' - - '[0-9]+.[0-9]+.[0-9]+-rc[x0-9]+' + - '[0-9]+.[0-9]+.[0-9]+-rc[x0-9]+' + pull_request: + release: + types: [published] + workflow_dispatch: defaults: run: shell: bash jobs: + prepare: + name: "Prepare" + runs-on: ubuntu-22.04 + outputs: + version: ${{ steps.get_version.outputs.VERSION }} + create_release: ${{ steps.check_release.outputs.CREATE_RELEASE }} + steps: + - name: Get the version + id: get_version + run: echo "VERSION=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT + - name: Check create release for tag + if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') + id: check_release + run: | + URL="https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.get_version.outputs.VERSION }}" + StatusCode=$(curl -o -I -L -s -w "%{http_code}" -X GET -G $URL) + if [ "$StatusCode" == 200 ]; then + echo "Release exists" + echo "CREATE_RELEASE=false" >> $GITHUB_OUTPUT + else + echo "Release does not exist" + echo "CREATE_RELEASE=true" >> $GITHUB_OUTPUT + fi build_wheel: + needs: [prepare] runs-on: ubuntu-22.04 steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Build wheel run: | cd .. - docker run -v ./Centre-Registry:/src -v ./whl:/whl registry.gitlab.com/clarin-eric/docker-alpine-wheeler:0.0.1-a6 - - name: Create release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ github.ref }} - release_name: ${{ github.ref }} - draft: false - prerelease: true - body_path: CHANGELOG.md - - name: Add to release - uses: shogo82148/actions-upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + docker run -v ./Centre-Registry:/src -v ./whl:/whl registry.gitlab.com/clarin-eric/docker-alpine-wheeler:0.0.1-a10 + - name: 'Tar wheeler output and changelog' + run: tar -cvf workspace.tar ../whl/*.whl ./CHANGELOG.md + - uses: actions/upload-artifact@v4 with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: /home/runner/work/Centre-Registry/whl/*.whl - asset_content_type: application/gzip + name: workspace + path: workspace.tar + retention-days: 1 + release: + name: "Release" + needs: [prepare, build_wheel] + # Run job for github releases and tag pushes (without github release) + if: github.event_name == 'release' || needs.prepare.outputs.create_release == 'true' + runs-on: ubuntu-22.04 + permissions: + contents: write + steps: + - name: 'Download workspace' + uses: actions/download-artifact@v4 + with: + name: workspace + - name: 'Untar workspace' + run: tar -xvf workspace.tar + # For github releases -> upload release package to existing release + # For tag pushes without github release -> create a github release with release package + - name: Create release + if: needs.prepare.outputs.create_release == 'true' + id: create_release + uses: ncipollo/release-action@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag: ${{ needs.prepare.outputs.version }} + name: ${{ needs.prepare.outputs.version }} + draft: false + prerelease: true + bodyFile: CHANGELOG.md + - name: Add to existing release + uses: shogo82148/actions-upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + # Pseudo-ternary expression: get "upload_url" from the release created above, or from github "release" event when release is pre-created + upload_url: ${{ needs.prepare.outputs.create_release == 'true' && steps.create_release.outputs.upload_url || github.event.release.upload_url }} + asset_path: ./whl/*.whl + asset_content_type: application/gzip + - uses: eregon/publish-release@v1 + if: needs.prepare.outputs.create_release == 'true' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + release_id: ${{ steps.create_release.outputs.id }} diff --git a/.travis.yml b/.travis.yml index ce9bf74..f29a270 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,7 +39,7 @@ env: addons: sauce_connect: true install: - - pip install -e 'centre-registry-app/' + - pip install -e . - pip install -r 'centre-registry-app/requirements_test.txt' script: - Centre-Registry-config/manage.py migrate diff --git a/CHANGELOG.md b/CHANGELOG.md index dfa21ca..aa44ad0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,18 +1,19 @@ # Changelog -## [3.0.1] - 28.03.2024 +## [3.0.1] - 25.04.2024 ### New features +- `api/all_centres_full` endpoint for CLARIN website - project root `.pytoml` building Centre Registry packages (`centre-registry-app`; `Centre-Registry-config`) into a single package - `.whl` build and distribution via release -- `api/all_centres_full` endpoint for main website consumption ### Changed features +- Fixed validation of geographical coordinates on administration interface. #79 - Updated dependencies: - Django 4.1.11 to Django 4.2.11 - django-debug-toolbar 4.2.0 to 4.3.0 - Jsonschema 4.19.1 to 4.21.1 - - lxml 4.9.3 to 4.9.4 + - lxml 4.9.3 to 5.2.1 - Selenium 4.13.0 to 4.19.0 - Added dependency on djangorestframework 3.15.1 diff --git a/Centre-Registry-config/pyproject.toml b/Centre-Registry-config/pyproject.toml index 05da36a..926f67c 100644 --- a/Centre-Registry-config/pyproject.toml +++ b/Centre-Registry-config/pyproject.toml @@ -14,14 +14,13 @@ maintainers = [ "Andre Moreira ", "" ] - packages = [ { include = "centre_registry_project" }, ] [tool.poetry.urls] changelog = "https://github.com/clarin-eric/Centre-Registry/blob/master/LICENSE.txt" -documentation = "https://trac.clarin.eu/wiki/Centre%20Registry" +documentation = "https://github.com/clarin-eric/Centre-Registry/" homepage = "https://centres.clarin.eu/" repository = "https://github.com/clarin-eric/Centre-Registry/" diff --git a/README.md b/README.md index 3f505e2..237335d 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ Gives a KML file (Keyhole Markup) with geographical information about Centres of use in mapping applications. For example: `api/KML/EBC` `api/model/M`, where M is one of the models in the administration interface `CentreType`, -`Centre`, `Contact`, `Consortium`, `FCSEndpoint`, `URLReference`, `MetadataFormat`, -`OAIPMHEndpoint`, `SAMLIdentityFederation`, `SAMLServiceProvider`: +`Centre`, `Contact`, `Consortium`, `FCSEndpoint`, `URLReference`, `Organisation`, +`OAIPMHEndpoint`, `OAIPMHEndpointSet`, `SAMLIdentityFederation`, `SAMLServiceProvider`: Gives a JSON representation of all data belonging to that model in the database. `api/all_centres_full`, for all Centres of any type with fully expanded relations into values diff --git a/centre-registry-app/centre_registry/models.py b/centre-registry-app/centre_registry/models.py index 6c55a82..f605c76 100644 --- a/centre-registry-app/centre_registry/models.py +++ b/centre-registry-app/centre_registry/models.py @@ -14,11 +14,17 @@ from django.db.models import CASCADE, PROTECT, SET_NULL, SET_DEFAULT, SET, DO_NOTHING +def raise_coordinate_validation_error(coordinate, exception): + raise ValidationError( + '{0} is not a valid Decimal Degree coordinate. '.format( + str(coordinate))) from exception + + def parse_decimal_degree(degree): """ Extracts a float decimal degree from a string. """ - return re_match(r'^[+\-]{0,1}[0-9]{1,3}\.[0-9]{1,8}$', degree).group(0) + return re_match(r'^[+\-]{0,1}[0-9]{1,3}\.[0-9]{1,18}$', degree).group(0) def is_valid_longitude(longitude): @@ -33,19 +39,22 @@ def is_valid_latitude(latitude): def validate_latitude(latitude): try: - if is_valid_longitude(parse_decimal_degree(latitude)): + if is_valid_latitude(parse_decimal_degree(latitude)): return + else: + raise_coordinate_validation_error(latitude) except Exception as exception: - raise ValidationError( - '{0} is not a valid Decimal Degree latitude. '.format( - str(latitude))) from exception + raise_coordinate_validation_error(latitude, exception) def validate_longitude(longitude): try: if is_valid_longitude(parse_decimal_degree(longitude)): return - except Exception as exception:import ast + else: + raise_coordinate_validation_error(longitude) + except Exception as exception: + raise_coordinate_validation_error(longitude, exception) class Contact(Model): diff --git a/centre-registry-app/centre_registry/serializers.py b/centre-registry-app/centre_registry/serializers.py index 7cff52a..5a5e18e 100644 --- a/centre-registry-app/centre_registry/serializers.py +++ b/centre-registry-app/centre_registry/serializers.py @@ -1,5 +1,6 @@ from rest_framework import serializers +from centre_registry.models import AssessmentDates from centre_registry.models import Centre from centre_registry.models import CentreType from centre_registry.models import Contact @@ -10,8 +11,7 @@ class CentreTypeSerializer(serializers.ModelSerializer): class Meta: model = CentreType - fields = '__all__' - + fields = ['type'] class ContactSerializer(serializers.ModelSerializer): class Meta: @@ -30,6 +30,13 @@ class Meta: model = Organisation fields = '__all__' +class AssessmentDatesSerializer(serializers.ModelSerializer): + type = CentreTypeSerializer(many=True) + + class Meta: + model = AssessmentDates + exclude = ['id'] + class CentreSerializer(serializers.ModelSerializer): type = CentreTypeSerializer(many=True) @@ -38,6 +45,7 @@ class CentreSerializer(serializers.ModelSerializer): monitoring_contacts = ContactSerializer(many=True) consortium = ConsortiumSerializer() organisation_fk = OrganisationSerializer() + assessmentdates = AssessmentDatesSerializer(many=True) class Meta: model = Centre diff --git a/centre-registry-app/pyproject.toml b/centre-registry-app/pyproject.toml index 0287510..47a0148 100644 --- a/centre-registry-app/pyproject.toml +++ b/centre-registry-app/pyproject.toml @@ -18,10 +18,9 @@ packages = [ { include = "centre_registry" }, ] - [tool.poetry.urls] changelog = "https://github.com/clarin-eric/Centre-Registry/blob/master/LICENSE.txt" -documentation = "https://trac.clarin.eu/wiki/Centre%20Registry" +documentation = "https://github.com/clarin-eric/Centre-Registry/" homepage = "https://centres.clarin.eu/" repository = "https://github.com/clarin-eric/Centre-Registry/" @@ -32,7 +31,7 @@ django-debug-toolbar = '4.3.0' djangorestframework = '3.15.1' [tool.poetry.group.test.dependencies] -lxml = '4.9.4' +lxml = '5.2.1' selenium = '4.19.0' jsonschema = '4.21.1' django-test-migrations = '1.3.0' diff --git a/pyproject.toml b/pyproject.toml index 5f30d22..d115d22 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "clarin_centre_registry" description = "CLARIN Centre Registry Django project configuration" -version = "3.0.1-rc" +version = "0.0.0dev" license = "../LICENSE.txt" authors = [ "Beatriz Sanchez Bribian", @@ -14,7 +14,6 @@ maintainers = [ "Andre Moreira ", "" ] - packages = [ { include = "centre_registry_project", from = "Centre-Registry-config" }, { include = "centre_registry", from = "centre-registry-app" }, @@ -22,7 +21,7 @@ packages = [ [tool.poetry.urls] changelog = "https://github.com/clarin-eric/Centre-Registry/blob/master/LICENSE.txt" -documentation = "https://trac.clarin.eu/wiki/Centre%20Registry" +documentation = "https://github.com/clarin-eric/Centre-Registry/" homepage = "https://centres.clarin.eu/" repository = "https://github.com/clarin-eric/Centre-Registry/" @@ -33,11 +32,23 @@ django-debug-toolbar = '4.3.0' djangorestframework = '3.15.1' [tool.poetry.group.test.dependencies] -lxml = '4.9.4' +lxml = '5.2.1' selenium = '4.19.0' jsonschema = '4.21.1' django-test-migrations = '1.3.0' +[tool.poetry-dynamic-versioning] +enable = true +vcs = "git" +pattern = "^(?P\\d+\\.\\d+\\.\\d+)(-?((?P[a-zA-Z]+)\\.?(?P\\d+)?))?" +format-jinja = """ + {%- if distance == 0 -%} + {{ serialize_pep440(base, stage, revision) }} + {%- else -%} + {{ serialize_pep440(base, stage, revision, dev=distance, metadata=[commit]) }} + {%- endif -%} +""" + [build-system] -requires = ["poetry-core>=1.0.0"] -build-backend = "poetry.core.masonry.api" +requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"] +build-backend = "poetry_dynamic_versioning.backend"