Skip to content

Commit

Permalink
Merge pull request #72 from Andrew-Chen-Wang/revert-68-in-source-to-i…
Browse files Browse the repository at this point in the history
…n-wiki-links

Revert "Add in-source to in-wiki link transformer"
  • Loading branch information
jcbhmr authored Jul 16, 2023
2 parents 6d341e2 + 06e1bc0 commit 50650fc
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 173 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
cliw eol=lf
cli.ts eol=lf
*.sh eol=lf
2 changes: 0 additions & 2 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ on:
branches: "master"
paths-ignore:
- .gitignore
- .gitattributes
- LICENSE
- README.md
- .github/**
- "!.github/workflows/test-action.yml"
pull_request:
paths-ignore:
- .gitignore
- .gitattributes
- LICENSE
- README.md
- .github/**
Expand Down
2 changes: 0 additions & 2 deletions .gitignore

This file was deleted.

3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

44 changes: 23 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ is specific to GitHub wikis.
not push to the remote wiki. The default is `false`. This is useful for
testing.

- **`preprocess`:** If this option is true, we will preprocess the wiki to move
the `README.md` to `Home.md` as well as rewriting all `.md` links to be bare
links. This helps ensure that the Markdown works in source control as well as
the wiki. The default is true.

#### `strategy:` input

There are some specific usecases where using `strategy: init` might be better
Expand All @@ -138,6 +133,28 @@ than the default `strategy: clone`.
tab. This is essentially the concatenation of `${{ github.server_url }}`,
`${{ github.repository }}`, and the `/wiki` page.

### Preprocessing

You may wish to strip the `[link](page.md)` `.md` suffix from your links to make
them viewable in GitHub source view (with the `.md`) _as well as_ in GitHub wiki
(without the `.md`; pretty URLs!). You can use a preprocessing action like
[Strip MarkDown extensions from links action] to remove those `.md` suffixes
before using this action. Here's an example:

```yml
publish-wiki:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: impresscms-dev/strip-markdown-extensions-from-links-action@v1.0.0
with:
path: wiki
- uses: Andrew-Chen-Wang/github-wiki-action@v4
```

❤️ If you have an awesome preprocessor action that you want to add here, let us
know! We'd love to add an example.

### Cross-repo wikis

You _can_ use this action to deploy your octocat/mega-docs repository to the
Expand Down Expand Up @@ -172,24 +189,9 @@ jobs:
path: .
```

## Development

![Deno](https://img.shields.io/static/v1?style=for-the-badge&message=Deno&color=000000&logo=Deno&logoColor=FFFFFF&label=)
![GitHub Actions](https://img.shields.io/static/v1?style=for-the-badge&message=GitHub+Actions&color=2088FF&logo=GitHub+Actions&logoColor=FFFFFF&label=)

This GitHub Action uses a self-downloaded version of Deno. See `cliw` for the
`cli.ts` wrapper script that downloads the Deno binary and runs the TypeScript
code. The main script itself is ~100 lines of code, so it's not too bad.

ℹ Because the version of Deno is _pinned_, it's recommended to every-so-often
bump it to the latest version.

To test the action, open a PR! The `test-action.yml` workflow will run the code
with `dry-run: true` as well as a real run! Yes, this does get tedious swapping
between your IDE and the PR, but it's the easiest way to test the action.

<!-- prettier-ignore-start -->
[Decathlon/wiki-page-creator-action#11]: https://github.com/Decathlon/wiki-page-creator-action/issues/11
[supported markup languages]: https://github.com/github/markup#markups
[Strip MarkDown extensions from links action]: https://github.com/marketplace/actions/strip-markdown-extensions-from-links-action
[PAT]: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
<!-- prettier-ignore-end -->
11 changes: 1 addition & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@ inputs:
push to the remote wiki. The default is false. This is useful for testing.
required: true
default: false
preprocess:
description: >-
If this option is true, we will preprocess the wiki to move the README.md
to Home.md as well as rewriting all .md links to be bare links. This helps
ensure that the Markdown works in source control as well as the wiki. The
default is true.
required: true
default: true
outputs:
wiki_url:
description: >-
Expand All @@ -82,7 +74,7 @@ runs:
using: composite
steps:
- id: main
run: '"${GITHUB_ACTION_PATH%/}/cliw"'
run: '"${GITHUB_ACTION_PATH%/}/src/$INPUT_STRATEGY.sh"'
shell: bash
env:
INPUT_STRATEGY: ${{ inputs.strategy }}
Expand All @@ -93,4 +85,3 @@ runs:
INPUT_COMMIT_MESSAGE: ${{ inputs.commit-message }}
INPUT_IGNORE: ${{ inputs.ignore }}
INPUT_DRY_RUN: ${{ inputs.dry-run }}
INPUT_PREPROCESS: ${{ inputs.preprocess }}
101 changes: 0 additions & 101 deletions cli.ts

This file was deleted.

32 changes: 0 additions & 32 deletions cliw

This file was deleted.

40 changes: 40 additions & 0 deletions src/clone.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
# Copyright 2023 Jacob Hummer
# SPDX-License-Identifier: Apache-2.0
set -e
if [[ -n $RUNNER_DEBUG ]]; then
set -x
fi

export GITHUB_TOKEN="$INPUT_TOKEN"
export GITHUB_SERVER_URL="$INPUT_GITHUB_SERVER_URL"
export GITHUB_REPOSITORY="$INPUT_REPOSITORY"
export GH_HOST="${GITHUB_SERVER_URL#*//}"

export GIT_DIR && GIT_DIR=$(mktemp -d)
export GIT_WORK_TREE="$INPUT_PATH"
trap 'rm -rf "$GIT_DIR"' SIGINT SIGTERM ERR EXIT

gh auth setup-git
git config --global --add safe.directory "$GIT_DIR"

git clone "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.wiki.git" "$GIT_DIR" --bare
git config --unset core.bare

echo "$INPUT_IGNORE" >>"$GIT_DIR/info/exclude"
git add -Av

# https://github.com/stefanzweifel/git-auto-commit-action/blob/master/action.yml#L35-L42
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git commit --allow-empty -m "$INPUT_COMMIT_MESSAGE"

if [[ $INPUT_DRY_RUN == true ]]; then
echo 'Dry run'
git remote show origin
git show
exit 0
fi

git push origin master
echo "wiki_url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/wiki" >>"$GITHUB_OUTPUT"
40 changes: 40 additions & 0 deletions src/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
# Copyright 2023 Jacob Hummer
# SPDX-License-Identifier: Apache-2.0
set -e
if [[ -n $RUNNER_DEBUG ]]; then
set -x
fi

export GITHUB_TOKEN="$INPUT_TOKEN"
export GITHUB_SERVER_URL="$INPUT_GITHUB_SERVER_URL"
export GITHUB_REPOSITORY="$INPUT_REPOSITORY"
export GH_HOST="${GITHUB_SERVER_URL#*//}"

export GIT_DIR && GIT_DIR=$(mktemp -d)
export GIT_WORK_TREE="$INPUT_PATH"
trap 'rm -rf "$GIT_DIR"' SIGINT SIGTERM ERR EXIT

gh auth setup-git
git config --global --add safe.directory "$GIT_DIR"

git init -b master
git remote add origin "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.wiki.git"

echo "$INPUT_IGNORE" >>"$GIT_DIR/info/exclude"
git add -Av

git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com

git commit --allow-empty -m "$INPUT_COMMIT_MESSAGE"

if [[ $INPUT_DRY_RUN == true ]]; then
echo 'Dry run'
git remote show origin
git show
exit 0
fi

git push -f origin master
echo "wiki_url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/wiki" >>"$GITHUB_OUTPUT"

0 comments on commit 50650fc

Please sign in to comment.