Skip to content

Commit

Permalink
refactor documentation workflow to follow best github action best pra…
Browse files Browse the repository at this point in the history
…ctices
  • Loading branch information
tuunit committed Sep 8, 2023
1 parent 58dfe37 commit 78378fe
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 67 deletions.
93 changes: 47 additions & 46 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,64 @@ on:
paths: ['docs/**']

jobs:
checks:
if: github.event_name != 'push'
pull-request-check:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v1
- uses: actions/checkout@v4

- uses: actions/setup-node@v3
with:
node-version: '17.x'
node-version: 18

- name: Test Build
working-directory: ./docs
env:
NODE_OPTIONS: --openssl-legacy-provider
run: |
if [ -e yarn.lock ]; then
yarn install --frozen-lockfile
elif [ -e package-lock.json ]; then
npm ci
else
npm i
fi
npm run build
gh-release:
if: github.event_name != 'pull_request'
gh-pages-release:
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
with:
node-version: '17.x'
- name: Add key to allow access to repository
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
NODE_OPTIONS: --openssl-legacy-provider
path: master

- uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages

- uses: actions/setup-node@v3
with:
node-version: 18

- name: Build docusaurus
working-directory: master/docs
id: build
run: |
mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts
echo "${{ secrets.GH_PAGES_DEPLOY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
cat <<EOT >> ~/.ssh/config
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa
EOT
- name: Release to GitHub Pages
working-directory: ./docs
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
npm ci
npm run build
- name: Release to github pages
env:
USE_SSH: true
GIT_USER: git
NODE_OPTIONS: --openssl-legacy-provider
GIT_TOKEN: ${{ secrets.GITHUB_TOKEN }}
working-directory: gh-pages
run: |
git config --global user.email "actions@gihub.com"
git config --global user.name "gh-actions"
if [ -e yarn.lock ]; then
yarn install --frozen-lockfile
elif [ -e package-lock.json ]; then
npm ci
else
npm i
fi
npx docusaurus deploy
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
# Remove all files except .git
git rm -r *
# Copy the build files from master/docs/build to gh-pages
cp -r ../master/docs/build/* .
# Commit and push
git add .
git commit -m "Update documentation based on ${{ steps.build.outputs.sha }}"
git push origin gh-pages
40 changes: 20 additions & 20 deletions docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "docusaurus",

"version": "0.0.0",
"private": true,
"scripts": {
Expand All @@ -13,7 +14,7 @@
"dependencies": {
"@docusaurus/core": "^2.0.0-beta.15",
"@docusaurus/preset-classic": "^2.0.0-beta.15",
"@easyops-cn/docusaurus-search-local": "^0.35.0",
"@easyops-cn/docusaurus-search-local": "^0.29.0",
"@mdx-js/react": "^1.6.22",
"clsx": "^1.1.1",
"react": "^16.14.0",
Expand Down

0 comments on commit 78378fe

Please sign in to comment.