diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9bea433 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +.DS_Store diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cfd542a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM node:lts-alpine3.9 +RUN apk update && apk add --no-cache bash git openssh +COPY entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/LICENSE b/LICENSE index eb05c02..45f5732 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 noah +Copyright (c) 2020 noah UG Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -14,7 +14,7 @@ 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 +FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 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 diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..28cdf0e --- /dev/null +++ b/action.yml @@ -0,0 +1,30 @@ +name: Django Action +description: Automatically runs some django tasks. + +author: Conrad Großer + +inputs: + output_path: + description: Output path for the generated data scheme + required: false + default: "./" + commit_message: + description: Commit message of the changed data + required: false + default: "Added data schema" + file_pattern: + description: File pattern used for `git add` command + required: false + default: "*" + pip_path: + description: Path relative to the repository root, where the requirements.txt is located + required: false + default: "requirements.txt" + +runs: + using: "docker" + image: "Dockerfile" + +branding: + icon: "book" + color: "green" diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..c15741f --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# e is for exiting the script automatically if a command fails, u is for exiting if a variable is not set +# x would be for showing the commands before they are executed +set -eu + +# FUNCTIONS +# Function for setting up git env in the docker container (copied from https://github.com/stefanzweifel/git-auto-commit-action/blob/master/entrypoint.sh) +_git_setup ( ) { + cat <<- EOF > $HOME/.netrc + machine github.com + login $GITHUB_ACTOR + password $GITHUB_TOKEN + machine api.github.com + login $GITHUB_ACTOR + password $GITHUB_TOKEN +EOF + chmod 600 $HOME/.netrc + + git config --global user.email "actions@github.com" + git config --global user.name "GitHub Action" +} + +# Checks if any files are changed +_git_changed() { + [[ -n "$(git status -s)" ]] +} + +# PROGRAM +echo "Installing dependencies..." +pip install -r $pip_path +pip install django-extensions pyparsing pydot +echo "Creating data model..." +python manage.py graph_models -a -g-o $output_path + +# To keep runtime good, just continue if something was changed +if _git_changed; +then + # Calling method to configure the git environemnt + _git_setup + echo "Commiting and pushing changes..." + # Add changes to git + git add "${INPUT_FILE_PATTERN}" || echo "Problem adding your files with pattern ${INPUT_FILE_PATTERN}" + # Commit and push changes back + git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" ${INPUT_COMMIT_OPTIONS:+"$INPUT_COMMIT_OPTIONS"} + git push origin + echo "Changes pushed successfully." +else + echo "Nothing to commit. Exiting." +fi