This repository has been archived by the owner on Oct 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a87db85
Showing
5 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM alpine/git:latest | ||
|
||
RUN apk add --no-cache bash findutils | ||
COPY entrypoint.sh / | ||
RUN chmod +x /entrypoint.sh | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright 2019 Read Evaluate Press, LLC | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Github Wiki Publish Action | ||
|
||
This [GitHub Action][github actions] | ||
publishes the contents of a directory to your project's [wiki][github wiki] | ||
from a workflow. | ||
|
||
## Setup | ||
|
||
This GitHub action requires that your repository has the following: | ||
|
||
- A wiki with at least one page in it | ||
- A secret named `GITHUB_PERSONAL_ACCESS_TOKEN` | ||
with a Github personal access token with "repo" authorization | ||
|
||
Follow the steps below to ensure that everything's configured correctly. | ||
|
||
> **Note** | ||
> GitHub doesn't currently provide APIs for interacting with project wikis, | ||
> so much of the required setup must be done manually. | ||
### 1. Enable Your Repository's Wikis Feature | ||
|
||
Navigate to the "Settings" tab for your repository, | ||
scroll down to the "Features" section, | ||
and ensure that the checkbox labeled "Wikis" is checked. | ||
|
||
![GitHub Wikis Feature](https://user-images.githubusercontent.com/7659/72726104-5f3aff80-3b3c-11ea-8f2e-fe73aff0276b.png) | ||
|
||
### 2. Create the First Wiki Page | ||
|
||
With the Wikis feature enabled for your repository, | ||
navigate to the "Wiki" tab. | ||
If prompted, | ||
create the first wiki page. | ||
|
||
![GitHub Wiki Create First Page](https://user-images.githubusercontent.com/7659/72726186-927d8e80-3b3c-11ea-8014-4622f8ff3226.png) | ||
|
||
### 3. Generate a Personal Access Token | ||
|
||
Navigate to the [Personal access tokens](https://github.com/settings/tokens) page | ||
in your GitHub account settings | ||
(Settings > Developer settings > Personal access tokens) | ||
and click the "Generate a new token" button. | ||
|
||
In the "New personal access token" form, | ||
provide a descriptive comment in the "Note" field, like "Wiki Management". | ||
Under "Select scopes", | ||
enable all of the entries under "repo" perms. | ||
|
||
When you're done, | ||
click the "Generate token" button at the bottom of the form. | ||
|
||
![GitHub Personal Access Token Select Scopes](https://user-images.githubusercontent.com/7659/72726210-9f9a7d80-3b3c-11ea-81b4-528de92fb9fa.png) | ||
|
||
> **Note**: | ||
> GitHub actions have access to [a `GITHUB_TOKEN` secret][GITHUB_TOKEN], | ||
> but that token's permissions are limited to | ||
> the repository that contains your workflow. | ||
> This workflow requires the generation of a new personal acccess token | ||
> to read and write to the git repository for your project's wiki. | ||
### 4. Set a Repository Secret | ||
|
||
Copy your generated personal access token to the clipboard | ||
and navigate to your project settings. | ||
Navigate to the "Secrets" page, | ||
click "Add a new secret", | ||
and fill in the form by | ||
entering `GITHUB_PERSONAL_ACCESS_TOKEN` into the "Name" field and | ||
pasting your token into the "Value" field. | ||
|
||
## License | ||
|
||
MIT | ||
|
||
## Contact | ||
|
||
Mattt ([@mattt](https://twitter.com/mattt)) | ||
|
||
[github actions]: https://help.github.com/en/actions | ||
[github wiki]: https://help.github.com/en/github/building-a-strong-community/about-wikis | ||
[GITHUB_TOKEN]: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token#about-the-github_token-secret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: "Publish to GitHub Wiki" | ||
description: "Pushes files to a GitHub project's wiki" | ||
|
||
inputs: | ||
path: | ||
description: "A path to the directory of files to publish" | ||
required: true | ||
|
||
runs: | ||
using: "docker" | ||
image: "Dockerfile" | ||
args: ["${{ inputs.path }}"] | ||
|
||
branding: | ||
icon: "book-open" | ||
color: "black" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/bin/bash | ||
|
||
function debug() { | ||
echo "::debug file=${BASH_SOURCE[0]},line=${BASH_LINENO[0]}::$1" | ||
} | ||
|
||
function warning() { | ||
echo "::warning file=${BASH_SOURCE[0]},line=${BASH_LINENO[0]}::$1" | ||
} | ||
|
||
function error() { | ||
echo "::error file=${BASH_SOURCE[0]},line=${BASH_LINENO[0]}::$1" | ||
} | ||
|
||
function add_mask() { | ||
echo "::add-mask::$1" | ||
} | ||
|
||
if [ -z "$GITHUB_ACTOR" ]; then | ||
error "GITHUB_ACTOR environment variable is not set" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$GITHUB_REPOSITORY" ]; then | ||
error "GITHUB_REPOSITORY environment variable is not set" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$GITHUB_PERSONAL_ACCESS_TOKEN" ]; then | ||
error "GITHUB_PERSONAL_ACCESS_TOKEN environment variable is not set" | ||
exit 1 | ||
fi | ||
|
||
add_mask "${GITHUB_PERSONAL_ACCESS_TOKEN}" | ||
|
||
if [ -z "${WIKI_COMMIT_MESSAGE:-}" ]; then | ||
debug "WIKI_COMMIT_MESSAGE not set, using default" | ||
WIKI_COMMIT_MESSAGE='Automatically publish wiki' | ||
fi | ||
|
||
GIT_REPOSITORY_URL="https://${GITHUB_PERSONAL_ACCESS_TOKEN}@github.com/$GITHUB_REPOSITORY.wiki.git" | ||
|
||
debug "Checking out wiki repository" | ||
tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX) | ||
( | ||
cd "$tmp_dir" || exit 1 | ||
git init | ||
git config user.name "$GITHUB_ACTOR" | ||
git config user.email "$GITHUB_ACTOR@users.noreply.github.com" | ||
git pull "$GIT_REPOSITORY_URL" | ||
) | ||
|
||
debug "Enumerating contents of $1" | ||
for file in $(find $1 -maxdepth 1 -type f -name '*.md' -execdir basename '{}' ';'); do | ||
debug "Copying $file" | ||
cp "$1/$file" "$tmp_dir" | ||
done | ||
|
||
debug "Committing and pushing changes" | ||
( | ||
cd "$tmp_dir" || exit 1 | ||
git add . | ||
git commit -m "$WIKI_COMMIT_MESSAGE" | ||
git push --set-upstream "$GIT_REPOSITORY_URL" master | ||
) | ||
|
||
rm -rf "$tmp_dir" | ||
exit 0 |