feat: add GitHub Actions workflow for automated build and push to bui… #1
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 and Push to Build Branch | |
| on: | |
| push: | |
| branches: | |
| - development | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build project | |
| run: npm run build | |
| - name: Configure git | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| - name: Prepare build branch | |
| run: | | |
| # Create a temporary directory with only dist contents | |
| mkdir -p /tmp/build-contents | |
| cp -r dist/* /tmp/build-contents/ | |
| # Create or checkout build branch | |
| git fetch origin | |
| git checkout -B build origin/build 2>/dev/null || git checkout -B build | |
| # Clean the current branch (keep only dist content) | |
| find . -maxdepth 1 -not -name '.git' -not -name '.gitignore' -exec rm -rf {} + 2>/dev/null || true | |
| # Copy dist contents to root of build branch | |
| cp -r /tmp/build-contents/* . | |
| # Add .gitkeep if dist is empty | |
| if [ -z "$(ls -A)" ]; then | |
| touch .gitkeep | |
| fi | |
| - name: Commit and push build branch | |
| run: | | |
| git add . | |
| # Only commit if there are changes | |
| if ! git diff-index --quiet HEAD --; then | |
| git commit -m "Auto build from development branch" && \ | |
| git push -u origin build | |
| else | |
| echo "No changes to commit" | |
| fi |