Skip to content

Commit

Permalink
Initial push from working repo
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBaker0 committed Jul 21, 2024
1 parent e06e15b commit 694d2ea
Show file tree
Hide file tree
Showing 17 changed files with 565 additions and 0 deletions.
Empty file added .Dockerignore
Empty file.
26 changes: 26 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Integration Test
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Version and Update Item
id: version-update-item
uses: provena/version-update-item-action@main
with:
offline_token: ${{ secrets.PROVENA_OFFLINE_TOKEN }}
domain: "dev.rrap-is.com"
realm_name: "rrap"
item_id: "10378.1/1925572"
version_reason: "Testing GitHub Action which can version and update items"
update_reason: "Updating git custom attributes, as well as source URL."
attribute_updates: |
{
"user_metadata": {
"git_hash": "${{ github.sha }}",
"git_branch": "${{ github.ref_name }}",
"git_release": "${{ github.ref_type == 'tag' && github.ref_name || '' }}"
},
"source_url": "https://github.com/${{ github.repository }}"
}
18 changes: 18 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Lint
on: [push, pull_request]
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: "3.7"

- uses: actions/checkout@v1

- name: Lint
run: |
pip install flake8
flake8 main.py
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.tokens.json
.offline_token
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"python.testing.pytestArgs": [
"."
],
"python.analysis.diagnosticMode": "workspace",
"mypy.runUsingActiveInterpreter": true,
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
}
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM python:3-slim AS builder

# Just dependencies to minimise rebuilds
COPY requirements.txt /app

# We are installing a dependency here directly into our app source dir
RUN pip install --target=/app -r requirements.txt

ADD . /app
WORKDIR /app

# A distroless container image with Python and some basics like SSL certificates
# https://github.com/GoogleContainerTools/distroless
FROM gcr.io/distroless/python3-debian10
COPY --from=builder /app /app
WORKDIR /app
ENV PYTHONPATH /app
CMD ["/app/main.py"]
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

The MIT License (MIT)

Copyright (c) 2018 GitHub, Inc. and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# version-update-item-action

Docker GitHub action which produces a new version of an existing registry item, and updates metadata attributes if supplied.
32 changes: 32 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: "Update Provena registry item"
description: "Creates a new version of an existing item in a Provena deployment, providing a reason and an optional set of attribute updates."
author: "Peter Baker"
inputs:
offline_token:
description: "Offline token which is suitable for the specified provena domain, realm and client."
required: true
secret: true
domain:
description: "The base domain for the provena deployment"
required: true
realm_name:
description: "The realm name for the keycloak instance for this deployment - contact administrator if unsure."
required: true
item_id:
description: "The id of the item to create a new version for."
required: true
version_reason:
description: "What reason should be provided for the creation of the new version?"
required: true
update_reason:
description: "What reason should be provided for the update of metadata attributes?"
required: false
attribute_updates:
description: "Would you like to apply a set of updates after versioning? If so this JSON will be merged with the updated item domain info and an update applied. Please ensure this is a valid serialised JSON string."
required: false
outputs:
new_id:
description: "The ID of the new version of the item"
runs:
using: "docker"
image: "Dockerfile"
26 changes: 26 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from pydantic import BaseSettings
from logging import WARNING


class GithubInputs(BaseSettings):
# The offline token to use for the client auth
input_offline_token: str
# The domain for the provena deployment
input_domain: str
# The auth realm name
input_realm_name: str
# The item id to create new version for
input_item_id: str
# The reason to provide
input_version_reason: str
# The reason to provide
input_update_reason: str | None
# The set of attribute updates to apply after versioning, if any
input_attribute_updates: str | None
# The log level to display - defaults to WARNING - see https://docs.python.org/3/library/logging.html#levels
input_log_level: int = WARNING

# use .env file optionally for local testing
class Config:
env_file = ".env"
env_file_encoding = "utf-8"
2 changes: 2 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mypy
pytest
20 changes: 20 additions & 0 deletions logging_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import logging
import sys

def setup_logger(name : str, level: int = logging.INFO) -> logging.Logger:
"""Function to setup as many loggers as you want"""

formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')

# Console handler
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setFormatter(formatter)

# Create logger and set level
logger = logging.getLogger(name)
logger.setLevel(level)

# Add handlers to logger
logger.addHandler(console_handler)

return logger
Loading

0 comments on commit 694d2ea

Please sign in to comment.