ci(sync): clean untracked files before syncing to release branch (#44) #53
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: Sync to Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 60 | |
| concurrency: | |
| group: release-branch | |
| cancel-in-progress: false | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: 'pnpm' | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Build | |
| run: pnpm run build | |
| - name: Setup tree command | |
| run: sudo apt-get update && sudo apt-get install -y tree | |
| - name: Export to dist | |
| run: | | |
| mkdir -p dist | |
| npx build-marketplace export ./dist | |
| cp README.md CONTRIBUTING.md dist/ | |
| tree ./dist | |
| - name: Push to release branch | |
| run: | | |
| STAGE_DIR=$(mktemp -d) | |
| cp -R dist/. "$STAGE_DIR" | |
| git fetch origin release || true | |
| if git show-ref --verify --quiet refs/remotes/origin/release; then | |
| git checkout release | |
| else | |
| git checkout --orphan release | |
| fi | |
| git clean -fdx -e .git | |
| git checkout -- . 2>/dev/null || true | |
| ls -A "$STAGE_DIR" | while read -r item; do | |
| rm -rf "$item" | |
| done | |
| cp -R "$STAGE_DIR"/. . && rm -rf "$STAGE_DIR" | |
| git config --local user.name "github-actions[bot]" | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git add -A | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit, skipping" | |
| else | |
| git commit \ | |
| --author="$(git log -1 --format='%an <%ae>' ${{ github.sha }})" \ | |
| -m "$(git log -1 --format='%B' ${{ github.sha }})" | |
| git show HEAD | |
| git push origin release | |
| fi |