mirror of
https://github.com/gofiber/storage.git
synced 2025-10-06 17:17:18 +08:00
Add docu sync for releases
This commit is contained in:
52
.github/scripts/sync_docs.sh
vendored
52
.github/scripts/sync_docs.sh
vendored
@@ -2,34 +2,62 @@
|
|||||||
|
|
||||||
# Some env variables
|
# Some env variables
|
||||||
BRANCH="main"
|
BRANCH="main"
|
||||||
REPO="storage"
|
|
||||||
REPO_URL="github.com/gofiber/docs.git"
|
REPO_URL="github.com/gofiber/docs.git"
|
||||||
AUTHOR_EMAIL="github-actions[bot]@users.noreply.github.com"
|
AUTHOR_EMAIL="github-actions[bot]@users.noreply.github.com"
|
||||||
AUTHOR_USERNAME="github-actions[bot]"
|
AUTHOR_USERNAME="github-actions[bot]"
|
||||||
|
VERSION_FILE="template_versions.json"
|
||||||
|
REPO_DIR="storage"
|
||||||
|
COMMIT_URL="https://github.com/gofiber/storage"
|
||||||
|
DOCUSAURUS_COMMAND="npm run docusaurus -- docs:version:storage"
|
||||||
|
|
||||||
# Set commit author
|
# Set commit author
|
||||||
git config --global user.email "${AUTHOR_EMAIL}"
|
git config --global user.email "${AUTHOR_EMAIL}"
|
||||||
git config --global user.name "${AUTHOR_USERNAME}"
|
git config --global user.name "${AUTHOR_USERNAME}"
|
||||||
|
|
||||||
# Exit if event is not PUSH
|
git clone https://${TOKEN}@${REPO_URL} fiber-docs
|
||||||
if [ "$EVENT" != "push" ]; then
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
# Handle push event
|
||||||
|
if [ "$EVENT" == "push" ]; then
|
||||||
latest_commit=$(git rev-parse --short HEAD)
|
latest_commit=$(git rev-parse --short HEAD)
|
||||||
|
|
||||||
git clone https://${TOKEN}@${REPO_URL} fiber-docs
|
|
||||||
for f in $(find . -type f -name "*.md" -not -path "./fiber-docs/*"); do
|
for f in $(find . -type f -name "*.md" -not -path "./fiber-docs/*"); do
|
||||||
log_output=$(git log --oneline "${BRANCH}" HEAD~1..HEAD --name-status -- "${f}")
|
log_output=$(git log --oneline "${BRANCH}" HEAD~1..HEAD --name-status -- "${f}")
|
||||||
|
|
||||||
if [[ $log_output != "" || ! -f "fiber-docs/docs/$REPO/$f" ]]; then
|
if [[ $log_output != "" || ! -f "fiber-docs/docs/${REPO_DIR}/$f" ]]; then
|
||||||
mkdir -p fiber-docs/docs/$REPO/$(dirname $f)
|
mkdir -p fiber-docs/docs/${REPO_DIR}/$(dirname $f)
|
||||||
cp "${f}" fiber-docs/docs/$REPO/$f
|
cp "${f}" fiber-docs/docs/${REPO_DIR}/$f
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Push changes for storage instance docs
|
# Handle release event
|
||||||
cd fiber-docs/ || return
|
elif [ "$EVENT" == "release" ]; then
|
||||||
|
# Extract package name from tag
|
||||||
|
package_name="${TAG_NAME%/*}"
|
||||||
|
major_version="${TAG_NAME#*/}"
|
||||||
|
major_version="${major_version%%.*}"
|
||||||
|
|
||||||
|
# Form new version name
|
||||||
|
new_version="${package_name}_${major_version}.x.x"
|
||||||
|
|
||||||
|
cd fiber-docs/ || true
|
||||||
|
npm ci
|
||||||
|
|
||||||
|
# Check if contrib_versions.json exists and modify it if required
|
||||||
|
if [[ -f $VERSION_FILE ]]; then
|
||||||
|
jq --arg new_version "$new_version" 'del(.[] | select(. == $new_version))' $VERSION_FILE > temp.json && mv temp.json $VERSION_FILE
|
||||||
|
jq -S . ${VERSION_FILE} > temp.json && mv temp.json ${VERSION_FILE}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run docusaurus versioning command
|
||||||
|
$DOCUSAURUS_COMMAND "${new_version}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Push changes
|
||||||
|
cd fiber-docs/ || true
|
||||||
git add .
|
git add .
|
||||||
git commit -m "Add docs from https://github.com/gofiber/$REPO/commit/${latest_commit}"
|
if [[ $EVENT == "push" ]]; then
|
||||||
|
git commit -m "Add docs from ${COMMIT_URL}/commit/${latest_commit}"
|
||||||
|
elif [[ $EVENT == "release" ]]; then
|
||||||
|
git commit -m "Sync docs for release ${COMMIT_URL}/releases/tag/${TAG_NAME}"
|
||||||
|
fi
|
||||||
git push https://${TOKEN}@${REPO_URL}
|
git push https://${TOKEN}@${REPO_URL}
|
51
.github/workflows/sync-docs.yml
vendored
51
.github/workflows/sync-docs.yml
vendored
@@ -1,25 +1,38 @@
|
|||||||
name: 'Sync docs'
|
name: 'Sync docs'
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
- main
|
- main
|
||||||
paths:
|
paths:
|
||||||
- '**/*.md'
|
- '**/*.md'
|
||||||
|
release:
|
||||||
|
types: [published]
|
||||||
|
branches:
|
||||||
|
- '*/v[0-9]+.[0-9]+.[0-9]+'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
sync-docs:
|
sync-docs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
fetch-depth: 2
|
fetch-depth: 2
|
||||||
|
|
||||||
- name: Sync docs
|
- name: Setup Node.js environment
|
||||||
run: ./.github/scripts/sync_docs.sh
|
uses: actions/setup-node@v3
|
||||||
env:
|
with:
|
||||||
EVENT: ${{ github.event_name }}
|
node-version: '18'
|
||||||
TOKEN: ${{ secrets.DOC_SYNC_TOKEN }}
|
|
||||||
|
- name: Install JQ
|
||||||
|
run: sudo apt-get install jq
|
||||||
|
|
||||||
|
- name: Sync docs
|
||||||
|
run: ./.github/scripts/sync_docs.sh
|
||||||
|
env:
|
||||||
|
EVENT: ${{ github.event_name }}
|
||||||
|
TAG_NAME: ${{ github.ref_name }}
|
||||||
|
TOKEN: ${{ secrets.DOC_SYNC_TOKEN }}
|
||||||
|
Reference in New Issue
Block a user