better workflow 2 #19
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 Store Artifact | |
| permissions: | |
| contents: write | |
| on: [push] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| - name: Install libs | |
| run: | | |
| npm install | |
| - name: Build project | |
| run: | | |
| npm run build | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: package | |
| path: dist | |
| - name: Push artifact to artifacts branch | |
| run: | | |
| # Configure Git | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # save artifact inside virutal machine | |
| cp -r dist ../$(basename $GITHUB_WORKSPACE)/dist/* | |
| # Create or switch to artifacts branch | |
| git fetch origin artifacts || true | |
| git checkout -B artifacts origin/artifacts || git checkout -b artifacts | |
| # Copy build output (adjust folder name if needed) | |
| rm -rf * | |
| cp ../$(basename $GITHUB_WORKSPACE)/dist/* . | |
| # Commit and push | |
| git add . | |
| git commit -m "Artifact from PR #${{ github.event.pull_request.number }}" | |
| git push origin artifacts --force |