From 9034cbc607a16a14d1350cafa08b05cd0eba6728 Mon Sep 17 00:00:00 2001 From: Federico Grandi Date: Tue, 17 Sep 2019 18:50:21 +0200 Subject: [PATCH] Add core files --- Dockerfile | 14 ++++++++++++++ action.yml | 28 ++++++++++++++++++++++++++++ entrypoint.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 Dockerfile create mode 100644 action.yml create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f1331bf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM alpine/git:1.0.7 + +LABEL "com.github.actions.name"="Add & Commit" +LABEL "com.github.actions.description"="Add & commit files from a path directly from GitHub Actions" +LABEL "com.github.actions.icon"="git-commit" +LABEL "com.github.actions.color"="black" + +LABEL "repository"="https://github.com/EndBug/add-and-commit" +LABEL "homepage"="https://github.com/EndBug/add-and-commit" +LABEL "maintainer"="Federico Grandi " + +COPY entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["sh", "/entrypoint.sh"] diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..100673f --- /dev/null +++ b/action.yml @@ -0,0 +1,28 @@ +name: 'Add & Commit' +description: 'Add & commit files from a path directly from GitHub Actions' + +inputs: + author_name: + description: 'The name of the user that will be displayed as the author of the commit' + required: true + default: 'Add & Commit GitHub Action' + author_email: + description: 'The email of the user that will be displayed as the author of the commit' + required: true + default: 'actions@github.com' + message: + description: 'The message for the commit' + required: true + default: 'Commit from GitHub Actions' + path: + description: 'The path to stage files from' + required: true + default: './**/*.*' + +runs: + using: 'docker' + image: 'Dockerfile' + +branding: + icon: 'git-commit' + color: black \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..fb5a599 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,48 @@ +#!/bin/sh +set -eu + +# Set up .netrc file with GitHub credentials +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 "Add & Commit GitHub Action" +} + +# This is needed to make the check work for untracked files +echo "Staging files in commit path..." +git add "${INPUT_PATH}" + +echo "Checking for uncommitted changes in the git working tree..." +# This section only runs if there have been file changes +if ! git diff --cached --exit-code +then + git_setup + + git fetch + + # Switch to branch from current Workflow run + echo "Creating and switching branch..." + git branch "${GITHUB_REF:11}" + git checkout "${GITHUB_REF:11}" + + echo "Adding files..." + git add "${INPUT_PATH}" + + echo "Creating commit..." + git commit -m "$INPUT_MESSAGE" --author="$INPUT_AUTHOR_NAME <$INPUT_AUTHOR_EMAIL>" + + echo "Pushing to repo..." + git push --set-upstream origin "${GITHUB_REF:11}" +else + echo "Working tree clean. Nothing to commit." +fi