Update cd.yml #5
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 # Fetch all history for proper branch creation | |
- name: Install dependencies | |
run: npm install | |
- name: Build | |
run: npm run build | |
- name: Create PR Branch | |
run: | | |
git config --global user.name "github-actions-bot" | |
git config --global user.email "[email protected]" | |
# Stash any changes | |
git stash | |
# Create a new branch from gh-pages if it exists, or create it as an orphan branch | |
if git ls-remote --heads origin gh-pages | grep -q 'gh-pages'; then | |
git fetch origin gh-pages | |
git checkout -f gh-pages | |
else | |
git checkout --orphan gh-pages | |
git rm -rf . | |
fi | |
# Remove all files but keep .git | |
find . -maxdepth 1 ! -name '.git' ! -name '.' -exec rm -rf {} + | |
# Copy build files to root directory | |
cp -r build/* . | |
rm -rf build | |
# Add all files and commit | |
git add . | |
git commit -m "Update build files" | |
# Create a new branch for the PR | |
timestamp=$(date +%s) | |
branch_name="build-update-${timestamp}" | |
git checkout -b $branch_name | |
# Push both branches | |
git push origin gh-pages --force | |
git push origin $branch_name | |
- name: Create Pull Request | |
uses: repo-sync/pull-request@v2 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
destination_branch: "gh-pages" | |
source_branch: ${{ format('build-update-{0}', steps.get-timestamp.outputs.timestamp) }} | |
pr_title: "Update build files" | |
pr_body: "Automated PR to update build files" | |
pr_label: "automated pr" |