Skip to content

Commit

Permalink
github workflows (#106)
Browse files Browse the repository at this point in the history
Component for adding file metadata to extra context for detail & edit pages
  • Loading branch information
mesemus authored Nov 14, 2023
1 parent eb9ea3d commit c535d33
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 46 deletions.
82 changes: 37 additions & 45 deletions .github/workflows/main.yaml → .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
Expand All @@ -46,51 +54,35 @@ 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/[email protected]
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
with:
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
15 changes: 15 additions & 0 deletions .github/workflows/manual.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
36 changes: 36 additions & 0 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
17 changes: 17 additions & 0 deletions oarepo_ui/resources/components.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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)
27 changes: 27 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit c535d33

Please sign in to comment.