Skip to content

Commit

Permalink
action.sh: allow to change origin
Browse files Browse the repository at this point in the history
It's not possible to override a default environment variable
  • Loading branch information
andi34 committed Sep 5, 2024
1 parent 7d7e832 commit 737290d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Note that for this approach, Github Pages will be enabled in Settings but you wi

In case this action should be used in a Github Enterprise environment you can overwrite the `github.com` domain with your corresponding Github Enterprise domain name by specifying the `GITHUB_DOMAIN` environment variable.

### Custom repository

In case you want to push to another repository than origin define `GITHUB_ORIGIN`. Needs building with `PERSONAL_TOKEN`.

### Custom domain for github pages

MkDocs can be deployed to github pages using a custom domain, if you populate a `CUSTOM_DOMAIN` environment variable. This will generate a CNAME file, which will be placed inside the `/docs` folder.
Expand Down Expand Up @@ -62,15 +66,19 @@ jobs:
steps:
- name: Checkout main
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT_TOKEN }} # Uses Personal Access Token (PAT) for checkout, needed to push to another repository

- name: Deploy docs
uses: mhausenblas/mkdocs-deploy-gh-pages@nomaterial
# Or use mhausenblas/mkdocs-deploy-gh-pages@master to build with the mkdocs-material theme
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# PERSONAL_TOKEN: ${{ secrets.PAT_TOKEN }}
CUSTOM_DOMAIN: optionaldomain.com
CONFIG_FILE: folder/mkdocs.yml
EXTRA_PACKAGES: build-base
# GITHUB_DOMAIN: github.myenterprise.com
# GITHUB_ORIGIN: destination-repository-username/destination-repository-name
REQUIREMENTS: folder/requirements.txt
```
11 changes: 9 additions & 2 deletions action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,19 @@ else
export CONFIG_FILE="${GITHUB_WORKSPACE}/mkdocs.yml"
fi

if [ -n "${GITHUB_ORIGIN}" ]; then
print_info "setup with GITHUB_ORIGIN"
else
print_info "setup with GITHUB_REPOSITORY"
export GITHUB_ORIGIN=${GITHUB_REPOSITORY}
fi

if [ -n "${GITHUB_TOKEN}" ]; then
print_info "setup with GITHUB_TOKEN"
remote_repo="https://x-access-token:${GITHUB_TOKEN}@${GITHUB_DOMAIN:-"github.com"}/${GITHUB_REPOSITORY}.git"
remote_repo="https://x-access-token:${GITHUB_TOKEN}@${GITHUB_DOMAIN:-"github.com"}/${GITHUB_ORIGIN}.git"
elif [ -n "${PERSONAL_TOKEN}" ]; then
print_info "setup with PERSONAL_TOKEN"
remote_repo="https://x-access-token:${PERSONAL_TOKEN}@${GITHUB_DOMAIN:-"github.com"}/${GITHUB_REPOSITORY}.git"
remote_repo="https://x-access-token:${PERSONAL_TOKEN}@${GITHUB_DOMAIN:-"github.com"}/${GITHUB_ORIGIN}.git"
else
print_info "no token found; linting"
exec -- mkdocs build --config-file "${CONFIG_FILE}"
Expand Down

0 comments on commit 737290d

Please sign in to comment.