|
| 1 | +name: Sync Boilerplate to Create-Hyperweb-App |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - cha-sync-branch |
| 8 | + workflow_run: |
| 9 | + workflows: ["Build"] |
| 10 | + types: |
| 11 | + - completed |
| 12 | + |
| 13 | +jobs: |
| 14 | + sync-repo: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Checkout Boilerplate Repo |
| 18 | + uses: actions/checkout@v2 |
| 19 | + with: |
| 20 | + repository: hyperweb-io/hyperweb-boilerplate |
| 21 | + token: ${{ secrets.PAT_TOKEN }} # Use PAT for private repo access |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - name: Set Git User Identity |
| 25 | + run: | |
| 26 | + git config --global user.name "Anmol1696" |
| 27 | + git config --global user.email "[email protected]" |
| 28 | +
|
| 29 | + - name: Checkout CHA Sync Branch |
| 30 | + run: | |
| 31 | + git checkout cha-sync-branch |
| 32 | + git pull origin cha-sync-branch |
| 33 | +
|
| 34 | + - name: Cherry-pick the commit |
| 35 | + run: | |
| 36 | + git checkout main |
| 37 | + git pull origin main |
| 38 | + git cherry-pick 1c4b4c1eb436d27154e983d3c761632c4b40e029 ad183e0ba325628aad90b486fa415602c1fbf6d4 || git cherry-pick --abort |
| 39 | +
|
| 40 | + - name: Clone Create-Hyperweb-App Repo |
| 41 | + run: | |
| 42 | + git clone https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/hyperweb-io/create-hyperweb-app.git ../create-hyperweb-app |
| 43 | + cd ../create-hyperweb-app |
| 44 | + git checkout main |
| 45 | + cd - |
| 46 | +
|
| 47 | + - name: Get Version from Synced package.json |
| 48 | + id: get_version |
| 49 | + run: | |
| 50 | + if [ ! -f ../create-hyperweb-app/templates/hyperweb/package.json ]; then |
| 51 | + echo "package.json not found!" |
| 52 | + exit 1 |
| 53 | + fi |
| 54 | + VERSION=$(jq -r .version ../create-hyperweb-app/templates/hyperweb/package.json) |
| 55 | + GIT_HEAD=$(jq -r .gitHead ../create-hyperweb-app/templates/hyperweb/package.json) |
| 56 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 57 | + echo "git_head=$GIT_HEAD" >> $GITHUB_OUTPUT |
| 58 | +
|
| 59 | + - name: Get GIT_HASH from Hyperweb-Boilerplate |
| 60 | + id: git_hash |
| 61 | + run: | |
| 62 | + SHORT_HASH=$(git -C ../hyperweb-boilerplate rev-parse --short HEAD) |
| 63 | + echo "git_hash=$SHORT_HASH" >> $GITHUB_OUTPUT |
| 64 | +
|
| 65 | + - name: Copy and Apply Changes to Create-Hyperweb-App |
| 66 | + run: | |
| 67 | + rsync -av --exclude='.git' ./ ../create-hyperweb-app/templates/hyperweb/ --delete |
| 68 | +
|
| 69 | + - name: Update Version and GitHead in package.json |
| 70 | + run: | |
| 71 | + cd ../create-hyperweb-app |
| 72 | + if [ -f templates/hyperweb/package.json ]; then |
| 73 | + # Update the version in package.json (increment or set the value as needed) |
| 74 | + NEW_VERSION="${{ steps.get_version.outputs.version }}" |
| 75 | + GIT_HEAD="${{ steps.get_version.outputs.git_head }}" |
| 76 | + jq --arg version "$NEW_VERSION" --arg gitHead "$GIT_HEAD" \ |
| 77 | + 'if .gitHead == null then .gitHead = $gitHead else .gitHead end | .version = $version' \ |
| 78 | + templates/hyperweb/package.json > tmp.json && mv tmp.json templates/hyperweb/package.json |
| 79 | + else |
| 80 | + echo "package.json not found!" |
| 81 | + exit 1 |
| 82 | + fi |
| 83 | +
|
| 84 | + - name: Commit and Push Changes |
| 85 | + id: push_changes |
| 86 | + run: | |
| 87 | + cd ../create-hyperweb-app |
| 88 | + git add . |
| 89 | + git restore --staged templates/hyperweb/CHANGELOG.md |
| 90 | + if ! git diff-index --quiet HEAD; then |
| 91 | + SHORT_HASH="${{ steps.git_hash.outputs.git_hash }}" |
| 92 | + NEW_BRANCH="sync/hyperweb-boilerplate-update-${SHORT_HASH}-$(date +%Y%m%d%H%M)" |
| 93 | + git checkout -b $NEW_BRANCH |
| 94 | + git commit -m "Sync changes from hyperweb-boilerplate for commit ${SHORT_HASH}" |
| 95 | + git push origin $NEW_BRANCH |
| 96 | + echo "new_branch=$NEW_BRANCH" >> $GITHUB_OUTPUT |
| 97 | + fi |
| 98 | +
|
| 99 | + - name: Create Pull Request |
| 100 | + run: | |
| 101 | + NEW_BRANCH=${{ steps.push_changes.outputs.new_branch }} |
| 102 | + PR_URL=$(curl -s -X POST \ |
| 103 | + -H "Authorization: token ${{ secrets.PAT_TOKEN }}" \ |
| 104 | + -H "Accept: application/vnd.github.v3+json" \ |
| 105 | + https://api.github.com/repos/hyperweb-io/create-hyperweb-app/pulls \ |
| 106 | + -d "$(echo '{ |
| 107 | + "title": "Sync boilerplate changes for branch '"${NEW_BRANCH}"'", |
| 108 | + "head": "'"${NEW_BRANCH}"'", |
| 109 | + "base": "main", |
| 110 | + "body": "This PR contains the latest boilerplate changes from hyperweb-boilerplate for branch '"${NEW_BRANCH}"'. Also includes updates from the changelog file." |
| 111 | + }')" |
| 112 | + ) |
| 113 | + echo "Pull request created: $PR_URL" |
0 commit comments