Skip to content

Commit

Permalink
Add push_token option
Browse files Browse the repository at this point in the history
  • Loading branch information
drdanz committed Sep 6, 2019
1 parent 1ded802 commit 2ad5c41
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ The name of the development branch (default `devel`).

### `allow_ff`

Allow fast forward merge (default `false`). If not enabled, merges will use `--no-ff`.
Allow fast forward merge (default `false`). If not enabled, merges will use
`--no-ff`.

### `allow_forks`

Expand All @@ -75,3 +76,21 @@ User name for git commits (default `GitHub Nightly Merge Action`).
### `user_email`

User email for git commits (default `actions@github.com`).

### `push_token`

Environment variable containing the token to use for push (default
`GITHUB_TOKEN`).
Useful for pushing on protected branches.
Using a secret to store this variable value is strongly recommended, since this
value will be printed in the logs.
The `GITHUB_TOKEN` is still used for API calls, therefore both token should be
available.

```
with:
push_token: 'FOO_TOKEN'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FOO_TOKEN: ${{ secrets.FOO_TOKEN }}
```
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ inputs:
description: 'User email for git commits'
required: false
default: 'actions@github.com'
push_token:
description: 'Environment variable containing the token to use for push'
required: false
default: 'GITHUB_TOKEN'
runs:
using: 'docker'
image: 'Dockerfile'
Expand Down
17 changes: 11 additions & 6 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

set -e

if [[ -z "$GITHUB_TOKEN" ]]; then
echo "Set the GITHUB_TOKEN env variable."
exit 1
fi

echo
echo " 'Nightly Merge Action' is using the following input:"
echo " - stable_branch = '$INPUT_STABLE_BRANCH'"
Expand All @@ -15,14 +10,24 @@ echo " - allow_ff = $INPUT_ALLOW_FF"
echo " - allow_forks = $INPUT_ALLOW_FORKS"
echo " - user_name = $INPUT_USER_NAME"
echo " - user_email = $INPUT_USER_EMAIL"
echo " - push_token = $INPUT_PUSH_TOKEN = ${!INPUT_PUSH_TOKEN}"
echo

if [[ -z "${!INPUT_PUSH_TOKEN}" ]]; then
echo "Set the ${INPUT_PUSH_TOKEN} env variable."
exit 1
fi

NO_FF="--no-ff"
if $INPUT_ALLOW_FF; then
NO_FF=""
fi

if ! $INPUT_ALLOW_FORKS; then
if [[ -z "$GITHUB_TOKEN" ]]; then
echo "Set the GITHUB_TOKEN env variable."
exit 1
fi
URI=https://api.github.com
API_HEADER="Accept: application/vnd.github.v3+json"
AUTH_HEADER="Authorization: token $GITHUB_TOKEN"
Expand All @@ -33,7 +38,7 @@ if ! $INPUT_ALLOW_FORKS; then
fi
fi

git remote set-url origin https://x-access-token:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY.git
git remote set-url origin https://x-access-token:${!INPUT_PUSH_TOKEN}@github.com/$GITHUB_REPOSITORY.git
git config --global user.name "$INPUT_USER_NAME"
git config --global user.email "$INPUT_USER_EMAIL"

Expand Down

0 comments on commit 2ad5c41

Please sign in to comment.