try to create pr with gh-api #7
This file contains 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 Boilerplate to Create-Hyperweb-App | |
on: | |
push: | |
branches: | |
- cha-sync-branch | |
workflow_run: | |
workflows: ["Build"] | |
types: | |
- completed | |
jobs: | |
sync-repo: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Boilerplate Repo | |
uses: actions/checkout@v2 | |
with: | |
repository: hyperweb-io/hyperweb-boilerplate | |
token: ${{ secrets.PAT_TOKEN }} # Use PAT for private repo access | |
fetch-depth: 0 | |
- name: Set Git User Identity | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Checkout CHA Sync Branch | |
run: | | |
git checkout cha-sync-branch | |
git pull origin cha-sync-branch | |
- name: Cherry-pick the commit | |
run: | | |
git checkout main | |
git pull origin main | |
git cherry-pick 1c4b4c1eb436d27154e983d3c761632c4b40e029 || git cherry-pick --abort | |
- name: Clone Create-Hyperweb-App Repo | |
run: | | |
git clone https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/hyperweb-io/create-hyperweb-app.git ../create-hyperweb-app | |
cd ../create-hyperweb-app | |
git checkout main | |
cd - | |
- name: Get Version from Synced package.json | |
id: get_version | |
run: | | |
if [ ! -f ../create-hyperweb-app/templates/hyperweb/package.json ]; then | |
echo "package.json not found!" | |
exit 1 | |
fi | |
VERSION=$(jq -r .version ../create-hyperweb-app/templates/hyperweb/package.json) | |
echo "version=$VERSION" >> $GITHUB_OUTPUT | |
- name: Get GIT_HASH from Hyperweb-Boilerplate | |
id: git_hash | |
run: | | |
SHORT_HASH=$(git -C ../hyperweb-boilerplate rev-parse --short HEAD) | |
echo "git_hash=$SHORT_HASH" >> $GITHUB_OUTPUT | |
- name: Copy and Apply Changes to Create-Hyperweb-App | |
run: | | |
rsync -av --exclude='.git' ./ ../create-hyperweb-app/templates/hyperweb/ --delete | |
- name: Update Version in package.json | |
run: | | |
cd ../create-hyperweb-app | |
if [ -f templates/hyperweb/package.json ]; then | |
# Update the version in package.json (increment or set the value as needed) | |
NEW_VERSION="${{ steps.get_version.outputs.version }}" | |
jq ".version = \"$NEW_VERSION\"" templates/hyperweb/package.json > tmp.json && mv tmp.json templates/hyperweb/package.json | |
else | |
echo "package.json not found!" | |
exit 1 | |
fi | |
- name: Commit and Push Changes | |
id: push_changes | |
run: | | |
cd ../create-hyperweb-app | |
git add . | |
if ! git diff-index --quiet HEAD; then | |
SHORT_HASH="${{ steps.git_hash.outputs.git_hash }}" | |
NEW_BRANCH="sync/hyperweb-boilerplate-update-${SHORT_HASH}-$(date +%Y%m%d%H%M)" | |
git checkout -b $NEW_BRANCH | |
git commit -m "Sync changes from hyperweb-boilerplate for commit ${SHORT_HASH}" | |
git push origin $NEW_BRANCH | |
echo "new_branch=$NEW_BRANCH" >> $GITHUB_OUTPUT | |
fi | |
- name: Create Pull Request | |
run: | | |
NEW_BRANCH=${{ steps.push_changes.outputs.new_branch }} | |
PR_URL=$(curl -s -X POST \ | |
-H "Authorization: token ${{ secrets.PAT_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/hyperweb-io/create-hyperweb-app/pulls \ | |
-d @- << EOF | |
{ | |
"title": "Sync boilerplate changes for commit ${NEW_BRANCH}", | |
"head": "${NEW_BRANCH}", | |
"base": "main", | |
"body": "This PR contains the latest boilerplate changes from hyperweb-boilerplate for branch ${NEW_BRANCH}. Also includes updates from the changelog file." | |
} | |
EOF | |
) | |
echo "Pull request created: $PR_URL" |