-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
113 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
name: Sync Boilerplate to Create-Hyperweb-App | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- 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 "Anmol1696" | ||
git config --global user.email "[email protected]" | ||
- 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 ad183e0ba325628aad90b486fa415602c1fbf6d4 || 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) | ||
GIT_HEAD=$(jq -r .gitHead ../create-hyperweb-app/templates/hyperweb/package.json) | ||
echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
echo "git_head=$GIT_HEAD" >> $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 and GitHead 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 }}" | ||
GIT_HEAD="${{ steps.get_version.outputs.git_head }}" | ||
jq --arg version "$NEW_VERSION" --arg gitHead "$GIT_HEAD" \ | ||
'if .gitHead == null then .gitHead = $gitHead else .gitHead end | .version = $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 . | ||
git restore --staged templates/hyperweb/CHANGELOG.md | ||
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 "$(echo '{ | ||
"title": "Sync boilerplate changes for branch '"${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." | ||
}')" | ||
) | ||
echo "Pull request created: $PR_URL" |