Skip to content

Commit 9034cbc

Browse files
committed
Add core files
0 parents  commit 9034cbc

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM alpine/git:1.0.7
2+
3+
LABEL "com.github.actions.name"="Add & Commit"
4+
LABEL "com.github.actions.description"="Add & commit files from a path directly from GitHub Actions"
5+
LABEL "com.github.actions.icon"="git-commit"
6+
LABEL "com.github.actions.color"="black"
7+
8+
LABEL "repository"="https://github.com/EndBug/add-and-commit"
9+
LABEL "homepage"="https://github.com/EndBug/add-and-commit"
10+
LABEL "maintainer"="Federico Grandi <[email protected]>"
11+
12+
COPY entrypoint.sh /entrypoint.sh
13+
14+
ENTRYPOINT ["sh", "/entrypoint.sh"]

action.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: 'Add & Commit'
2+
description: 'Add & commit files from a path directly from GitHub Actions'
3+
4+
inputs:
5+
author_name:
6+
description: 'The name of the user that will be displayed as the author of the commit'
7+
required: true
8+
default: 'Add & Commit GitHub Action'
9+
author_email:
10+
description: 'The email of the user that will be displayed as the author of the commit'
11+
required: true
12+
default: '[email protected]'
13+
message:
14+
description: 'The message for the commit'
15+
required: true
16+
default: 'Commit from GitHub Actions'
17+
path:
18+
description: 'The path to stage files from'
19+
required: true
20+
default: './**/*.*'
21+
22+
runs:
23+
using: 'docker'
24+
image: 'Dockerfile'
25+
26+
branding:
27+
icon: 'git-commit'
28+
color: black

entrypoint.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
# Set up .netrc file with GitHub credentials
5+
git_setup ( ) {
6+
cat <<- EOF > $HOME/.netrc
7+
machine github.com
8+
login $GITHUB_ACTOR
9+
password $GITHUB_TOKEN
10+
11+
machine api.github.com
12+
login $GITHUB_ACTOR
13+
password $GITHUB_TOKEN
14+
EOF
15+
chmod 600 $HOME/.netrc
16+
17+
git config --global user.email "[email protected]"
18+
git config --global user.name "Add & Commit GitHub Action"
19+
}
20+
21+
# This is needed to make the check work for untracked files
22+
echo "Staging files in commit path..."
23+
git add "${INPUT_PATH}"
24+
25+
echo "Checking for uncommitted changes in the git working tree..."
26+
# This section only runs if there have been file changes
27+
if ! git diff --cached --exit-code
28+
then
29+
git_setup
30+
31+
git fetch
32+
33+
# Switch to branch from current Workflow run
34+
echo "Creating and switching branch..."
35+
git branch "${GITHUB_REF:11}"
36+
git checkout "${GITHUB_REF:11}"
37+
38+
echo "Adding files..."
39+
git add "${INPUT_PATH}"
40+
41+
echo "Creating commit..."
42+
git commit -m "$INPUT_MESSAGE" --author="$INPUT_AUTHOR_NAME <$INPUT_AUTHOR_EMAIL>"
43+
44+
echo "Pushing to repo..."
45+
git push --set-upstream origin "${GITHUB_REF:11}"
46+
else
47+
echo "Working tree clean. Nothing to commit."
48+
fi

0 commit comments

Comments
 (0)