Move from Docker to TS/Node

This commit is contained in:
Federico Grandi
2019-12-10 20:50:40 +01:00
parent b1b499b985
commit bfb772f923
5 changed files with 97 additions and 40 deletions

61
src/entrypoint.sh Normal file
View File

@@ -0,0 +1,61 @@
#!/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"
}
add() {
if $INPUT_FORCE
then find $INPUT_PATH -name "$INPUT_PATTERN" | while read x; do git add -f $x; done
else find $INPUT_PATH -name "$INPUT_PATTERN" | while read x; do git add $x; done
fi
}
# This is needed to make the check work for untracked files
echo "Staging files in commit path..."
add
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
# Verify if the branch needs to be created
if ! git rev-parse --verify --quiet "${GITHUB_REF:11}"
then
echo "Creating branch..."
git branch "${GITHUB_REF:11}"
fi
# Switch to branch from current workflow run
echo "Switching branch..."
git checkout "${GITHUB_REF:11}"
echo "Adding files..."
add
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

10
src/main.ts Normal file
View File

@@ -0,0 +1,10 @@
import * as core from '@actions/core'
import * as exec from '@actions/exec'
const cwd = process.env.GITHUB_WORKSPACE || '/github/workspace'
try {
exec.exec('./entrypoint.sh', [], { cwd })
} catch (e) {
core.setFailed(e)
}