fix: fix del exist target branch #15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build | |
on: | |
push: | |
branches: | |
- master | |
- 'ver/**' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Branch | |
uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '18' | |
- name: Install Dependencies | |
run: yarn install | |
- name: Build Docs | |
run: 'yarn run docs:build' | |
- name: Push to Publish Branch | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
BRANCH=$(echo ${GITHUB_REF} | sed -e 's/refs\/heads\///') | |
TARGET_BRANCH="build/${BRANCH}" | |
COMMIT_MSG=$(git log -1 --pretty=%B) | |
if git ls-remote --heads origin ${TARGET_BRANCH} | grep ${TARGET_BRANCH}; then | |
git push origin --delete ${TARGET_BRANCH} | |
fi | |
find . -mindepth 1 -maxdepth 1 ! -name 'docs' ! -name '.git' -exec rm -rf {} + | |
find docs -mindepth 1 -maxdepth 1 ! -name '.vitepress' -exec rm -rf {} + | |
cp -r docs/.vitepress/docs/* . | |
rm -rf docs/.vitepress/docs | |
git checkout -b "${TARGET_BRANCH}" | |
git add . | |
git commit -m "${COMMIT_MSG}" | |
echo "Branch: ${BRANCH}" | |
echo "Pushing to ${TARGET_BRANCH}" | |
echo "Commit Message: ${COMMIT_MSG}" | |
git push origin "${TARGET_BRANCH}" |