Skip to content
This repository was archived by the owner on Oct 17, 2021. It is now read-only.

Commit a87db85

Browse files
committed
Initial commit
0 parents  commit a87db85

File tree

5 files changed

+192
-0
lines changed

5 files changed

+192
-0
lines changed

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM alpine/git:latest
2+
3+
RUN apk add --no-cache bash findutils
4+
COPY entrypoint.sh /
5+
RUN chmod +x /entrypoint.sh
6+
7+
ENTRYPOINT ["/entrypoint.sh"]

LICENSE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright 2019 Read Evaluate Press, LLC
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a
4+
copy of this software and associated documentation files (the "Software"),
5+
to deal in the Software without restriction, including without limitation
6+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
7+
and/or sell copies of the Software, and to permit persons to whom the
8+
Software is furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19+
DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Github Wiki Publish Action
2+
3+
This [GitHub Action][github actions]
4+
publishes the contents of a directory to your project's [wiki][github wiki]
5+
from a workflow.
6+
7+
## Setup
8+
9+
This GitHub action requires that your repository has the following:
10+
11+
- A wiki with at least one page in it
12+
- A secret named `GITHUB_PERSONAL_ACCESS_TOKEN`
13+
with a Github personal access token with "repo" authorization
14+
15+
Follow the steps below to ensure that everything's configured correctly.
16+
17+
> **Note**
18+
> GitHub doesn't currently provide APIs for interacting with project wikis,
19+
> so much of the required setup must be done manually.
20+
21+
### 1. Enable Your Repository's Wikis Feature
22+
23+
Navigate to the "Settings" tab for your repository,
24+
scroll down to the "Features" section,
25+
and ensure that the checkbox labeled "Wikis" is checked.
26+
27+
![GitHub Wikis Feature](https://user-images.githubusercontent.com/7659/72726104-5f3aff80-3b3c-11ea-8f2e-fe73aff0276b.png)
28+
29+
### 2. Create the First Wiki Page
30+
31+
With the Wikis feature enabled for your repository,
32+
navigate to the "Wiki" tab.
33+
If prompted,
34+
create the first wiki page.
35+
36+
![GitHub Wiki Create First Page](https://user-images.githubusercontent.com/7659/72726186-927d8e80-3b3c-11ea-8014-4622f8ff3226.png)
37+
38+
### 3. Generate a Personal Access Token
39+
40+
Navigate to the [Personal access tokens](https://github.com/settings/tokens) page
41+
in your GitHub account settings
42+
(Settings > Developer settings > Personal access tokens)
43+
and click the "Generate a new token" button.
44+
45+
In the "New personal access token" form,
46+
provide a descriptive comment in the "Note" field, like "Wiki Management".
47+
Under "Select scopes",
48+
enable all of the entries under "repo" perms.
49+
50+
When you're done,
51+
click the "Generate token" button at the bottom of the form.
52+
53+
![GitHub Personal Access Token Select Scopes](https://user-images.githubusercontent.com/7659/72726210-9f9a7d80-3b3c-11ea-81b4-528de92fb9fa.png)
54+
55+
> **Note**:
56+
> GitHub actions have access to [a `GITHUB_TOKEN` secret][GITHUB_TOKEN],
57+
> but that token's permissions are limited to
58+
> the repository that contains your workflow.
59+
> This workflow requires the generation of a new personal acccess token
60+
> to read and write to the git repository for your project's wiki.
61+
62+
### 4. Set a Repository Secret
63+
64+
Copy your generated personal access token to the clipboard
65+
and navigate to your project settings.
66+
Navigate to the "Secrets" page,
67+
click "Add a new secret",
68+
and fill in the form by
69+
entering `GITHUB_PERSONAL_ACCESS_TOKEN` into the "Name" field and
70+
pasting your token into the "Value" field.
71+
72+
## License
73+
74+
MIT
75+
76+
## Contact
77+
78+
Mattt ([@mattt](https://twitter.com/mattt))
79+
80+
[github actions]: https://help.github.com/en/actions
81+
[github wiki]: https://help.github.com/en/github/building-a-strong-community/about-wikis
82+
[GITHUB_TOKEN]: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token#about-the-github_token-secret

action.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: "Publish to GitHub Wiki"
2+
description: "Pushes files to a GitHub project's wiki"
3+
4+
inputs:
5+
path:
6+
description: "A path to the directory of files to publish"
7+
required: true
8+
9+
runs:
10+
using: "docker"
11+
image: "Dockerfile"
12+
args: ["${{ inputs.path }}"]
13+
14+
branding:
15+
icon: "book-open"
16+
color: "black"

entrypoint.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
3+
function debug() {
4+
echo "::debug file=${BASH_SOURCE[0]},line=${BASH_LINENO[0]}::$1"
5+
}
6+
7+
function warning() {
8+
echo "::warning file=${BASH_SOURCE[0]},line=${BASH_LINENO[0]}::$1"
9+
}
10+
11+
function error() {
12+
echo "::error file=${BASH_SOURCE[0]},line=${BASH_LINENO[0]}::$1"
13+
}
14+
15+
function add_mask() {
16+
echo "::add-mask::$1"
17+
}
18+
19+
if [ -z "$GITHUB_ACTOR" ]; then
20+
error "GITHUB_ACTOR environment variable is not set"
21+
exit 1
22+
fi
23+
24+
if [ -z "$GITHUB_REPOSITORY" ]; then
25+
error "GITHUB_REPOSITORY environment variable is not set"
26+
exit 1
27+
fi
28+
29+
if [ -z "$GITHUB_PERSONAL_ACCESS_TOKEN" ]; then
30+
error "GITHUB_PERSONAL_ACCESS_TOKEN environment variable is not set"
31+
exit 1
32+
fi
33+
34+
add_mask "${GITHUB_PERSONAL_ACCESS_TOKEN}"
35+
36+
if [ -z "${WIKI_COMMIT_MESSAGE:-}" ]; then
37+
debug "WIKI_COMMIT_MESSAGE not set, using default"
38+
WIKI_COMMIT_MESSAGE='Automatically publish wiki'
39+
fi
40+
41+
GIT_REPOSITORY_URL="https://${GITHUB_PERSONAL_ACCESS_TOKEN}@github.com/$GITHUB_REPOSITORY.wiki.git"
42+
43+
debug "Checking out wiki repository"
44+
tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX)
45+
(
46+
cd "$tmp_dir" || exit 1
47+
git init
48+
git config user.name "$GITHUB_ACTOR"
49+
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
50+
git pull "$GIT_REPOSITORY_URL"
51+
)
52+
53+
debug "Enumerating contents of $1"
54+
for file in $(find $1 -maxdepth 1 -type f -name '*.md' -execdir basename '{}' ';'); do
55+
debug "Copying $file"
56+
cp "$1/$file" "$tmp_dir"
57+
done
58+
59+
debug "Committing and pushing changes"
60+
(
61+
cd "$tmp_dir" || exit 1
62+
git add .
63+
git commit -m "$WIKI_COMMIT_MESSAGE"
64+
git push --set-upstream "$GIT_REPOSITORY_URL" master
65+
)
66+
67+
rm -rf "$tmp_dir"
68+
exit 0

0 commit comments

Comments
 (0)