Update cd.yml #12
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: Create PR with Build | |
| on: | |
| push: | |
| branches: | |
| - develop | |
| jobs: | |
| build-and-create-pr: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Build | |
| run: | | |
| npm run build | |
| # Save the build in a temporary folder | |
| mv build /tmp/build | |
| - name: Create PR branch | |
| id: create-branch | |
| run: | | |
| git config --global user.name "github-actions-bot" | |
| git config --global user.email "[email protected]" | |
| # Fetch all branches and make sure we have history for gh-pages | |
| git fetch origin main | |
| # Delete all files except .git | |
| find . -maxdepth 1 ! -name '.git' ! -name '.' -exec rm -rf {} + | |
| # Create a new branch from gh-pages | |
| timestamp=$(date +%s) | |
| branch_name="build-update-${timestamp}" | |
| git checkout -b $branch_name origin/gh-pages | |
| # Copy files from build folder | |
| cp -r /tmp/build/* . | |
| # Commit and push the new build files to the new created branch | |
| git add . | |
| git commit -m "Updates" | |
| git push origin $branch_name | |
| # Set output for timestamp to be used later | |
| echo "timestamp=${timestamp}" >> $GITHUB_ENV | |
| - name: Create Pull Request | |
| uses: repo-sync/pull-request@v2 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| destination_branch: "main" | |
| source_branch: "build-update-${{ env.timestamp }}" | |
| pr_title: "Update build files" | |
| pr_body: "Automated PR to update build files" |