Skip to content

Commit

Permalink
Allow GitHub token
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-Chen-Wang committed Jun 17, 2020
1 parent 2411fcd commit 5029a9e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ for all inputs.
You must have a single wiki page available from the beginning.
It can be blank, but there must be at least one page that exists.
You must also have a directory where all your wiki files will
be located (the default directory is "wiki/").
be located (the default directory is "wiki/"). To include the
mandatory homepage, have a file in your wiki/ directory
called Home.md or with any other extension (e.g. rst).

```yaml
name: Deploy Wiki
Expand All @@ -46,13 +48,14 @@ jobs:
# Make sure you have that / at the end. We use rsync
# WIKI_DIR's default is wiki/
WIKI_DIR: wiki/
GH_PAT: ${{ secrets.GH_PAT }}
GH_PAT: ${{ secrets.GITHUB_TOKEN }}
GH_MAIL: ${{ secrets.YOUR_EMAIL }}
GH_NAME: ${{ github.repository_owner }}
```
You're going to need a Personal Access Token with the minimal scopes of
[seen here.](https://github.com/settings/tokens/new?scopes=repo&description=wiki%20page%20creator%20token)
If you plan on having a different repository host your wiki
directory, you're going to need a Personal Access Token instead of the `GITHUB_TOKEN`
with the minimal scopes [seen here.](https://github.com/settings/tokens/new?scopes=repo&description=wiki%20page%20creator%20token)

---
This intended usage was to avoid hosting a private ReadTheDocs
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ inputs:
description: 'Directory to rsync files to the wiki.'
required: false
default: 'wiki/'
GH_PAT:
GH_TOKEN:
description: 'The GitHub Personal Access Token for this action to use'
required: true
GH_MAIL:
Expand All @@ -19,7 +19,7 @@ inputs:
description: 'The username associated with the token.'
required: true
REPO:
description: 'The target repository.'
description: 'The target repository. Default is the current repo.'
required: false
WIKI_PUSH_MESSAGE:
description: 'The commit message for the wiki commit. Default is the commit to actual repository.'
Expand Down
20 changes: 7 additions & 13 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

TEMP_CLONE_FOLDER="temp_wiki_4567129308192764578126573891723968"

if [ -z "$GH_TOKEN" ]; then
echo "GH_TOKEN ENV is missing. Use $\{{ secrets.GITHUB_TOKEN }} or a PAT if your wiki repo is different from your current repo."

if [ -z "$GH_MAIL" ]; then
echo "GH_MAIL ENV is missing. Use the email for a user that can push to this repository."
exit 1
Expand All @@ -15,13 +18,6 @@ fi
if [ -z "$REPO" ]; then
echo "REPO ENV is missing. Using the current one."
REPO=$GITHUB_REPOSITORY
else
if [ -z "$REPO" != "$GITHUB_REPOSITORY"]; then
if [ -z "$GITHUB_TOKEN" == "$GH_PAT"]; then
echo "You must use a Personal Access Token to write to the wiki of a different repository."
exit 1
fi
fi
fi

if [ -z "$WIKI_DIR" ]; then
Expand All @@ -37,25 +33,23 @@ git init
# Setup credentials
git config user.name $GH_NAME
git config user.email $GH_MAIL
credentials=${GH_PAT:-$GITHUB_TOKEN}

git pull https://$credentials@github.com/$REPO.wiki.git
git pull https://$GH_TOKEN@github.com/$REPO.wiki.git
cd ..

# Get commit message
if [ -z "$WIKI_PUSH_MESSAGE" ]; then
echo "WIKI_PUSH_MESSAGE ENV is missing, using the commit's."
message=$(git log -1 --format=%B)
else
message=$WIKI_PUSH_MESSAGE
fi
echo "Message: $message"
echo "Message:"
echo $message

echo "Copying files to Wiki"
rsync -av $WIKI_DIR $TEMP_CLONE_FOLDER/ --exclude $TEMP_CLONE_FOLDER --exclude .git --delete
echo "Pushing to Wiki"
cd $TEMP_CLONE_FOLDER
git add .
git commit -m "$message"
echo https://$credentials@github.com/$REPO.wiki.git
git push --set-upstream https://$credentials@github.com/$REPO.wiki.git master
git push --set-upstream https://$GH_TOKEN@github.com/$REPO.wiki.git master

0 comments on commit 5029a9e

Please sign in to comment.