diff --git a/.github/workflows/main.yaml b/.github/workflows/build.yaml similarity index 54% rename from .github/workflows/main.yaml rename to .github/workflows/build.yaml index 9a814fe7..c3eb49dc 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/build.yaml @@ -1,25 +1,33 @@ -name: Test python +name: Build and test -on: [ push ] +on: + workflow_call: + inputs: + oarepo: + description: OARepo version (11, 12, ...) + required: true + default: 11 + type: string jobs: build: runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ "3.9", "3.10" ] services: - redis: - # Docker Hub image - image: redis - # Set health checks to wait until redis has started + postgres: + image: postgres + env: + POSTGRES_PASSWORD: postgres options: >- - --health-cmd "redis-cli ping" + --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 ports: - - 6379:6379 - strategy: - matrix: - python-version: [ "3.9", "3.10" ] + - 5432:5432 + steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} @@ -46,25 +54,26 @@ jobs: - name: Runs Opensearch uses: ankane/setup-opensearch@v1 + with: + plugins: analysis-icu - - name: Install dependencies - run: | - python -m pip install --upgrade pip wheel setuptools - pip install -e '.[devs]' - pip list + - name: Start Redis + uses: supercharge/redis-github-action@1.7.0 + with: + redis-version: ${{ matrix.redis-version }} - - name: Test with pytest + - name: Run tests run: | - pip install -e '.[tests]' - pip uninstall -y uritemplate.py || true - pip uninstall -y uritemplate || true - pip install -U uritemplate - pytest tests - + ./run-tests.sh + - name: Build package to publish run: | - python setup.py sdist bdist_wheel + .venv/bin/python setup.py sdist bdist_wheel + + - name: Freeze packages + run: | + .venv/bin/pip freeze > requirements.txt - name: Archive production artifacts uses: actions/upload-artifact@v3 @@ -72,25 +81,8 @@ jobs: name: dist path: dist - deploy: - runs-on: ubuntu-latest - needs: build - steps: - - name: Use built artifacts - uses: actions/download-artifact@v3 - with: - name: dist - path: dist - - - name: List files - run: | - ls -la - ls -la dist - - - name: Publish package - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') - uses: pypa/gh-action-pypi-publish@release/v1 + - name: Archive production artifacts + uses: actions/upload-artifact@v3 with: - skip_existing: true - user: __token__ - password: ${{ secrets.PYPI_PASSWORD }} + name: requirements.txt + path: requirements.txt diff --git a/.github/workflows/manual.yaml b/.github/workflows/manual.yaml new file mode 100644 index 00000000..e05df2cf --- /dev/null +++ b/.github/workflows/manual.yaml @@ -0,0 +1,15 @@ +name: Dispatch + +on: + workflow_dispatch: + inputs: + oarepo: + description: OARepo version (11, 12, ...) + required: true + default: 11 + +jobs: + build: + uses: ./.github/workflows/build.yaml + with: + oarepo: ${{ github.event.inputs.oarepo }} diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml new file mode 100644 index 00000000..fad9a87e --- /dev/null +++ b/.github/workflows/push.yaml @@ -0,0 +1,36 @@ +name: Build, test and publish + +on: push + +permissions: + id-token: write + contents: read + +jobs: + build: + uses: ./.github/workflows/build.yaml + with: + oarepo: 11 + + publish: + runs-on: ubuntu-latest + needs: build + steps: + - name: Use built artifacts + uses: actions/download-artifact@v3 + with: + name: dist + path: dist + + - name: List files + run: | + ls -la + ls -la dist + + - name: Publish package + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + uses: pypa/gh-action-pypi-publish@release/v1 + with: + skip_existing: true + user: __token__ + password: ${{ secrets.PYPI_PASSWORD }} diff --git a/oarepo_ui/resources/components.py b/oarepo_ui/resources/components.py index 7df5153f..9ec1db46 100644 --- a/oarepo_ui/resources/components.py +++ b/oarepo_ui/resources/components.py @@ -1,6 +1,8 @@ from flask import current_app from invenio_i18n.ext import current_i18n from invenio_records_resources.services.records.components import ServiceComponent +from invenio_records_resources.proxies import current_service_registry +from oarepo_runtime.datastreams.utils import get_file_service_for_record_service class BabelComponent(ServiceComponent): @@ -70,3 +72,18 @@ def fill_permissions(self, resource, record, extra_context, identity): identity, record, ) + + +class FilesComponent(ServiceComponent): + def before_ui_edit( + self, *, record, resource, extra_context, identity, **kwargs + ): + file_service = get_file_service_for_record_service( + resource.api_service, record=record) + files = file_service.list_files(identity, record['id']) + extra_context["files"] = files.to_dict() + + def before_ui_detail( + self, **kwargs + ): + self.before_ui_edit(**kwargs) \ No newline at end of file diff --git a/run-tests.sh b/run-tests.sh new file mode 100755 index 00000000..bd0e31ba --- /dev/null +++ b/run-tests.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +set -e + +OAREPO_VERSION="${OAREPO_VERSION:-11}" +OAREPO_VERSION_MAX=$((OAREPO_VERSION+1)) + + +VENV=".venv" + +if test -d $VENV ; then + rm -rf $VENV +fi + +python3 -m venv $VENV +. $VENV/bin/activate +pip install -U setuptools pip wheel + +pip install "oarepo>=${OAREPO_VERSION},<${OAREPO_VERSION_MAX}" +pip install -e ".[tests]" + +pip uninstall -y uritemplate +pip install uritemplate + +invenio index destroy --force --yes-i-know || true + +pytest tests diff --git a/setup.cfg b/setup.cfg index d45831c7..90de75db 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = oarepo-ui -version = 5.0.80 +version = 5.0.81 description = UI module for invenio 3.5+ long_description = file: README.md long_description_content_type = text/markdown