From 0e9b021a89ed70fb4b7b02fa6161dad67d5ca684 Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 00:13:53 +0200 Subject: [PATCH 01/32] feat: add sync.yml which runs every month --- .github/workflows/sync.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/sync.yml diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml new file mode 100644 index 0000000..df16280 --- /dev/null +++ b/.github/workflows/sync.yml @@ -0,0 +1,28 @@ +name: Sync branch to template + +on: + workflow_dispatch: + schedule: + - cron: '0 0 1 * *' + +jobs: + sync: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Sync branch to template + run: | + branch_name=$(git rev-parse --abbrev-ref HEAD) + original_remote=$(git remote get-url origin) + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git config --global user.name "github-actions[bot]" + git remote add template https://github.com/ubiquity/ts-template + git fetch template development + git update-index --assume-unchanged ".github/workflows/sync.yml" + git merge template/development --allow-unrelated-histories + git push "$original_remote" HEAD:"$branch_name" From a9fde248925f990c0c6d1a451375920655d20897 Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 13:39:04 +0200 Subject: [PATCH 02/32] feat: create a pull request --- .github/workflows/sync.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index df16280..5e59622 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -3,7 +3,7 @@ name: Sync branch to template on: workflow_dispatch: schedule: - - cron: '0 0 1 * *' + - cron: '14 0 1 * *' jobs: sync: @@ -16,13 +16,20 @@ jobs: fetch-depth: 0 - name: Sync branch to template + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | branch_name=$(git rev-parse --abbrev-ref HEAD) original_remote=$(git remote get-url origin) + pr_branch="sync/${branch_name}" git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" git remote add template https://github.com/ubiquity/ts-template git fetch template development git update-index --assume-unchanged ".github/workflows/sync.yml" - git merge template/development --allow-unrelated-histories - git push "$original_remote" HEAD:"$branch_name" + git merge template/development --allow-unrelated-histories || true + git checkout -b "$pr_branch" + git add . + git push "$original_remote" "$pr_branch" + gh pr create --title "Sync branch to template" --body "This pull request merges changes from the template repository." --head "$pr_branch" --base "$branch_name" + From 4c71cdfee18bc4b539932442eebaa68c3ff24e1b Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:27:36 +0200 Subject: [PATCH 03/32] feat: create add-sync-to-repos.yml --- .github/workflows/add-sync-to-repos.yml | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/add-sync-to-repos.yml diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml new file mode 100644 index 0000000..a445c38 --- /dev/null +++ b/.github/workflows/add-sync-to-repos.yml @@ -0,0 +1,45 @@ +name: Add Sync Script to Updated Repos + +on: + workflow_dispatch: + +jobs: + update-repos: + runs-on: ubuntu-latest + steps: + - name: Checkout GitHub CLI + uses: actions/checkout@v4 + + - name: Read sync.yml content + id: read-sync-yml + run: | + SYNC_CONTENT=$(cat .github/templates/sync.yml) + echo "SYNC_CONTENT<> $GITHUB_ENV + echo "$SYNC_CONTENT" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + - name: List repositories updated in the last month + id: list_repos + run: | + REPOS=$(gh repo list ubiquity --limit 1 --json name,updatedAt -q '.[] | select(.updatedAt > (now - 30*24*60*60)) | .name') + echo "REPOS=$REPOS" >> $GITHUB_ENV + + - name: Add sync.yml to each repo + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + for REPO in ${{ env.REPOS }}; do + echo "Processing $REPO" + gh repo clone ubiquity/$REPO + cd $REPO + branch_name="add-sync-script" + git checkout -b $branch_name + mkdir -p .github/workflows + echo "${{ env.SYNC_CONTENT }}" > .github/workflows/sync.yml + git add .github/workflows/sync.yml + git commit -m "Add sync.yml workflow" + # git push origin $branch_name + # gh pr create --title "Add sync.yml workflow that synchronizes the template every month" --body "Details: https://github.com/ubiquity/ts-template/issues/54" --head "$branch_name" --base development + cd .. + rm -rf $REPO + done From 5e80ccd51c7ff1f3ae2c10eb88aa42355902d413 Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:30:09 +0200 Subject: [PATCH 04/32] fix: some typos --- .github/workflows/add-sync-to-repos.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index a445c38..253a3ba 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -1,4 +1,4 @@ -name: Add Sync Script to Updated Repos +name: Add sync.yml to repos on: workflow_dispatch: @@ -7,13 +7,13 @@ jobs: update-repos: runs-on: ubuntu-latest steps: - - name: Checkout GitHub CLI + - name: Checkout uses: actions/checkout@v4 - name: Read sync.yml content id: read-sync-yml run: | - SYNC_CONTENT=$(cat .github/templates/sync.yml) + SYNC_CONTENT=$(cat .github/workflows/sync.yml) echo "SYNC_CONTENT<> $GITHUB_ENV echo "$SYNC_CONTENT" >> $GITHUB_ENV echo "EOF" >> $GITHUB_ENV From 0a1343091aab112dbcf8a0fc0494ae3d496dccd1 Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:31:04 +0200 Subject: [PATCH 05/32] fix: github token --- .github/workflows/add-sync-to-repos.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index 253a3ba..9b92a62 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -20,6 +20,8 @@ jobs: - name: List repositories updated in the last month id: list_repos + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | REPOS=$(gh repo list ubiquity --limit 1 --json name,updatedAt -q '.[] | select(.updatedAt > (now - 30*24*60*60)) | .name') echo "REPOS=$REPOS" >> $GITHUB_ENV From 0a23113626571ca5d35dd24e90a4085e96e0d040 Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:34:40 +0200 Subject: [PATCH 06/32] fix: disable substitution --- .github/workflows/add-sync-to-repos.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index 9b92a62..3638706 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -15,7 +15,7 @@ jobs: run: | SYNC_CONTENT=$(cat .github/workflows/sync.yml) echo "SYNC_CONTENT<> $GITHUB_ENV - echo "$SYNC_CONTENT" >> $GITHUB_ENV + echo '$SYNC_CONTENT' >> $GITHUB_ENV echo "EOF" >> $GITHUB_ENV - name: List repositories updated in the last month @@ -37,7 +37,7 @@ jobs: branch_name="add-sync-script" git checkout -b $branch_name mkdir -p .github/workflows - echo "${{ env.SYNC_CONTENT }}" > .github/workflows/sync.yml + echo '${{ env.SYNC_CONTENT }}' > .github/workflows/sync.yml git add .github/workflows/sync.yml git commit -m "Add sync.yml workflow" # git push origin $branch_name From 7b80b79df0975f40c09f69caead95ac1b4813551 Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:35:36 +0200 Subject: [PATCH 07/32] fix: git auth --- .github/workflows/add-sync-to-repos.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index 3638706..7c7d806 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -30,6 +30,8 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git config --global user.name "github-actions[bot]" for REPO in ${{ env.REPOS }}; do echo "Processing $REPO" gh repo clone ubiquity/$REPO From ec9246472ad36d73d9d052f0b54161c4f2c1a310 Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:37:59 +0200 Subject: [PATCH 08/32] fix: uncomment push and pr --- .github/workflows/add-sync-to-repos.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index 7c7d806..d4ad85f 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -15,7 +15,7 @@ jobs: run: | SYNC_CONTENT=$(cat .github/workflows/sync.yml) echo "SYNC_CONTENT<> $GITHUB_ENV - echo '$SYNC_CONTENT' >> $GITHUB_ENV + echo "$SYNC_CONTENT" >> $GITHUB_ENV echo "EOF" >> $GITHUB_ENV - name: List repositories updated in the last month @@ -39,11 +39,11 @@ jobs: branch_name="add-sync-script" git checkout -b $branch_name mkdir -p .github/workflows - echo '${{ env.SYNC_CONTENT }}' > .github/workflows/sync.yml + echo ${{env.SYNC_CONTENT}} > .github/workflows/sync.yml git add .github/workflows/sync.yml git commit -m "Add sync.yml workflow" - # git push origin $branch_name - # gh pr create --title "Add sync.yml workflow that synchronizes the template every month" --body "Details: https://github.com/ubiquity/ts-template/issues/54" --head "$branch_name" --base development + git push origin $branch_name + gh pr create --title "Add sync.yml workflow that synchronizes the template every month" --body "Details: https://github.com/ubiquity/ts-template/issues/54" --head "$branch_name" --base development cd .. rm -rf $REPO done From 547de5fbef47c7e0e59fc63e4f4f1f4a2e89f1e7 Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:40:26 +0200 Subject: [PATCH 09/32] fix: use sed --- .github/workflows/add-sync-to-repos.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index d4ad85f..fe20b55 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -13,7 +13,7 @@ jobs: - name: Read sync.yml content id: read-sync-yml run: | - SYNC_CONTENT=$(cat .github/workflows/sync.yml) + SYNC_CONTENT=$(cat .github/templates/sync.yml | sed 's/[$()`]/\\&/g') echo "SYNC_CONTENT<> $GITHUB_ENV echo "$SYNC_CONTENT" >> $GITHUB_ENV echo "EOF" >> $GITHUB_ENV @@ -39,7 +39,7 @@ jobs: branch_name="add-sync-script" git checkout -b $branch_name mkdir -p .github/workflows - echo ${{env.SYNC_CONTENT}} > .github/workflows/sync.yml + echo "${{ env.SYNC_CONTENT }}" > .github/workflows/sync.yml git add .github/workflows/sync.yml git commit -m "Add sync.yml workflow" git push origin $branch_name From 426e34963a910ac6a944b04ca978270e1f2d956b Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:45:20 +0200 Subject: [PATCH 10/32] fix: move git config --- .github/workflows/add-sync-to-repos.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index fe20b55..37a1daf 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -30,8 +30,6 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - git config --global user.email "github-actions[bot]@users.noreply.github.com" - git config --global user.name "github-actions[bot]" for REPO in ${{ env.REPOS }}; do echo "Processing $REPO" gh repo clone ubiquity/$REPO @@ -39,7 +37,10 @@ jobs: branch_name="add-sync-script" git checkout -b $branch_name mkdir -p .github/workflows + echo "${{ env.SYNC_CONTENT }}" echo "${{ env.SYNC_CONTENT }}" > .github/workflows/sync.yml + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git config --global user.name "github-actions[bot]" git add .github/workflows/sync.yml git commit -m "Add sync.yml workflow" git push origin $branch_name From 747d03de5e603d2b1bde0d96b8745dbf0952e462 Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:46:42 +0200 Subject: [PATCH 11/32] fix: change pr title --- .github/workflows/add-sync-to-repos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index 37a1daf..fdfebdf 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -44,7 +44,7 @@ jobs: git add .github/workflows/sync.yml git commit -m "Add sync.yml workflow" git push origin $branch_name - gh pr create --title "Add sync.yml workflow that synchronizes the template every month" --body "Details: https://github.com/ubiquity/ts-template/issues/54" --head "$branch_name" --base development + gh pr create --title "Add sync.yml workflow that synchronizes the template every month" --body "s" --head "$branch_name" --base development cd .. rm -rf $REPO done From 9b0e70b331ce12d48f7b5da5cb5afa692e0a9baf Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:49:53 +0200 Subject: [PATCH 12/32] fix: add original_remote variable --- .github/workflows/add-sync-to-repos.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index fdfebdf..4fcf47d 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -30,6 +30,7 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | + original_remote=$(git remote get-url origin) for REPO in ${{ env.REPOS }}; do echo "Processing $REPO" gh repo clone ubiquity/$REPO @@ -43,8 +44,8 @@ jobs: git config --global user.name "github-actions[bot]" git add .github/workflows/sync.yml git commit -m "Add sync.yml workflow" - git push origin $branch_name - gh pr create --title "Add sync.yml workflow that synchronizes the template every month" --body "s" --head "$branch_name" --base development + git push $original_remote $branch_name + gh pr create --title "Add sync.yml workflow that synchronizes the template every month" --body "Details: https://github.com/ubiquity/ts-template/issues/54" --head "$branch_name" --base development cd .. rm -rf $REPO done From 3d04254b45622e7ee4efb0bd93ed07d2c9bad912 Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:51:40 +0200 Subject: [PATCH 13/32] fix: add debug prints --- .github/workflows/add-sync-to-repos.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index 4fcf47d..d3174e2 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -38,12 +38,17 @@ jobs: branch_name="add-sync-script" git checkout -b $branch_name mkdir -p .github/workflows + echo "sync.yml content:" echo "${{ env.SYNC_CONTENT }}" + echo "------" echo "${{ env.SYNC_CONTENT }}" > .github/workflows/sync.yml + echo "configuring git" git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" git add .github/workflows/sync.yml + echo "commiting" git commit -m "Add sync.yml workflow" + echo "pushing" git push $original_remote $branch_name gh pr create --title "Add sync.yml workflow that synchronizes the template every month" --body "Details: https://github.com/ubiquity/ts-template/issues/54" --head "$branch_name" --base development cd .. From b006f484f8cfe605f86ec7f87ab1a1b5de6f045b Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:56:00 +0200 Subject: [PATCH 14/32] fix: remove push --- .github/workflows/add-sync-to-repos.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index d3174e2..6662ee4 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -13,7 +13,7 @@ jobs: - name: Read sync.yml content id: read-sync-yml run: | - SYNC_CONTENT=$(cat .github/templates/sync.yml | sed 's/[$()`]/\\&/g') + SYNC_CONTENT=$(cat .github/templates/sync.yml) echo "SYNC_CONTENT<> $GITHUB_ENV echo "$SYNC_CONTENT" >> $GITHUB_ENV echo "EOF" >> $GITHUB_ENV @@ -49,7 +49,7 @@ jobs: echo "commiting" git commit -m "Add sync.yml workflow" echo "pushing" - git push $original_remote $branch_name + # git push $original_remote $branch_name gh pr create --title "Add sync.yml workflow that synchronizes the template every month" --body "Details: https://github.com/ubiquity/ts-template/issues/54" --head "$branch_name" --base development cd .. rm -rf $REPO From f5e88a81fd1a321a7cafe2d28a074a2d3e14acbd Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:56:51 +0200 Subject: [PATCH 15/32] fix: typo --- .github/workflows/add-sync-to-repos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index 6662ee4..95e4330 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -13,7 +13,7 @@ jobs: - name: Read sync.yml content id: read-sync-yml run: | - SYNC_CONTENT=$(cat .github/templates/sync.yml) + SYNC_CONTENT=$(cat .github/workflows/sync.yml) echo "SYNC_CONTENT<> $GITHUB_ENV echo "$SYNC_CONTENT" >> $GITHUB_ENV echo "EOF" >> $GITHUB_ENV From 42c69b6a1fdcf1ea12dc60f0db316c531b94df1b Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:01:53 +0200 Subject: [PATCH 16/32] fix: copy the file --- .github/workflows/add-sync-to-repos.yml | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index 95e4330..86d669d 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -10,27 +10,13 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Read sync.yml content - id: read-sync-yml - run: | - SYNC_CONTENT=$(cat .github/workflows/sync.yml) - echo "SYNC_CONTENT<> $GITHUB_ENV - echo "$SYNC_CONTENT" >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV - - - name: List repositories updated in the last month - id: list_repos - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - REPOS=$(gh repo list ubiquity --limit 1 --json name,updatedAt -q '.[] | select(.updatedAt > (now - 30*24*60*60)) | .name') - echo "REPOS=$REPOS" >> $GITHUB_ENV - - name: Add sync.yml to each repo env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | + sync_path=$(realpath .github/workflows/sync.yml) original_remote=$(git remote get-url origin) + repos=$(gh repo list ubiquity --limit 1 --json name,updatedAt -q '.[] | select(.updatedAt > (now - 30*24*60*60)) | .name') for REPO in ${{ env.REPOS }}; do echo "Processing $REPO" gh repo clone ubiquity/$REPO @@ -38,11 +24,7 @@ jobs: branch_name="add-sync-script" git checkout -b $branch_name mkdir -p .github/workflows - echo "sync.yml content:" - echo "${{ env.SYNC_CONTENT }}" - echo "------" - echo "${{ env.SYNC_CONTENT }}" > .github/workflows/sync.yml - echo "configuring git" + cp ${{ env.SYNC_YML_PATH }} .github/workflows/sync.yml git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" git add .github/workflows/sync.yml From cf09a00669d5811a12e3b1d890647c6608a68d97 Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:03:28 +0200 Subject: [PATCH 17/32] fix: typo --- .github/workflows/add-sync-to-repos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index 86d669d..8ffe86a 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -17,7 +17,7 @@ jobs: sync_path=$(realpath .github/workflows/sync.yml) original_remote=$(git remote get-url origin) repos=$(gh repo list ubiquity --limit 1 --json name,updatedAt -q '.[] | select(.updatedAt > (now - 30*24*60*60)) | .name') - for REPO in ${{ env.REPOS }}; do + for REPO in $repos; do echo "Processing $REPO" gh repo clone ubiquity/$REPO cd $REPO From a969b8263d73352ed1d49c823f59ff20b56e24e7 Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:04:32 +0200 Subject: [PATCH 18/32] fix: typo --- .github/workflows/add-sync-to-repos.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index 8ffe86a..1b8175b 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -24,13 +24,11 @@ jobs: branch_name="add-sync-script" git checkout -b $branch_name mkdir -p .github/workflows - cp ${{ env.SYNC_YML_PATH }} .github/workflows/sync.yml + cp $sync_path .github/workflows/sync.yml git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" git add .github/workflows/sync.yml - echo "commiting" git commit -m "Add sync.yml workflow" - echo "pushing" # git push $original_remote $branch_name gh pr create --title "Add sync.yml workflow that synchronizes the template every month" --body "Details: https://github.com/ubiquity/ts-template/issues/54" --head "$branch_name" --base development cd .. From 626269f162a1843a5ae3efc5d056bb91cf3a7f4e Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:15:07 +0200 Subject: [PATCH 19/32] fix: create a branch in this repository --- .github/workflows/add-sync-to-repos.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index 1b8175b..4286e33 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -29,8 +29,8 @@ jobs: git config --global user.name "github-actions[bot]" git add .github/workflows/sync.yml git commit -m "Add sync.yml workflow" - # git push $original_remote $branch_name - gh pr create --title "Add sync.yml workflow that synchronizes the template every month" --body "Details: https://github.com/ubiquity/ts-template/issues/54" --head "$branch_name" --base development + git push $original_remote $branch_name + gh pr create --title "Add sync.yml workflow that synchronizes the template every month" --body "Details: https://github.com/ubiquity/ts-template/issues/54" --head "$original_remote:$branch_name" --base development cd .. rm -rf $REPO done From 1d9a0dc7a3eafdb170053899b3a29dfb2beec30a Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:16:01 +0200 Subject: [PATCH 20/32] fix: typo --- .github/workflows/add-sync-to-repos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index 4286e33..2ae624e 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -29,7 +29,7 @@ jobs: git config --global user.name "github-actions[bot]" git add .github/workflows/sync.yml git commit -m "Add sync.yml workflow" - git push $original_remote $branch_name + git push "$original_remote" "$branch_name" gh pr create --title "Add sync.yml workflow that synchronizes the template every month" --body "Details: https://github.com/ubiquity/ts-template/issues/54" --head "$original_remote:$branch_name" --base development cd .. rm -rf $REPO From 7f261f94066e0f6b0389692788b3ca1a1d15ad25 Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:21:56 +0200 Subject: [PATCH 21/32] fix: add git config url --- .github/workflows/add-sync-to-repos.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index 2ae624e..53122dc 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -14,6 +14,9 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git config --global user.name "github-actions[bot]" + git config --global url."https://${{ secrets.GITHUB_TOKEN }}@github.com/".insteadOf "https://github.com/" sync_path=$(realpath .github/workflows/sync.yml) original_remote=$(git remote get-url origin) repos=$(gh repo list ubiquity --limit 1 --json name,updatedAt -q '.[] | select(.updatedAt > (now - 30*24*60*60)) | .name') @@ -25,8 +28,6 @@ jobs: git checkout -b $branch_name mkdir -p .github/workflows cp $sync_path .github/workflows/sync.yml - git config --global user.email "github-actions[bot]@users.noreply.github.com" - git config --global user.name "github-actions[bot]" git add .github/workflows/sync.yml git commit -m "Add sync.yml workflow" git push "$original_remote" "$branch_name" From edf90e83786964e99bb804de3b1a83f5eecab555 Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:25:16 +0200 Subject: [PATCH 22/32] fix: try on this repo --- .github/workflows/add-sync-to-repos.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index 53122dc..2f01159 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -21,6 +21,7 @@ jobs: original_remote=$(git remote get-url origin) repos=$(gh repo list ubiquity --limit 1 --json name,updatedAt -q '.[] | select(.updatedAt > (now - 30*24*60*60)) | .name') for REPO in $repos; do + $REPO = https://github.com/zyrafal/ts-template echo "Processing $REPO" gh repo clone ubiquity/$REPO cd $REPO @@ -30,7 +31,8 @@ jobs: cp $sync_path .github/workflows/sync.yml git add .github/workflows/sync.yml git commit -m "Add sync.yml workflow" - git push "$original_remote" "$branch_name" + git remote set-url origin https://${{ secrets.GITHUB_TOKEN }}@github.com/ubiquity/$REPO.git + git push origin "$branch_name" gh pr create --title "Add sync.yml workflow that synchronizes the template every month" --body "Details: https://github.com/ubiquity/ts-template/issues/54" --head "$original_remote:$branch_name" --base development cd .. rm -rf $REPO From ab9d76d89806609b52fd2f2a12d1e2a07fdddd57 Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:26:52 +0200 Subject: [PATCH 23/32] fix: quotes --- .github/workflows/add-sync-to-repos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index 2f01159..882f710 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -21,7 +21,7 @@ jobs: original_remote=$(git remote get-url origin) repos=$(gh repo list ubiquity --limit 1 --json name,updatedAt -q '.[] | select(.updatedAt > (now - 30*24*60*60)) | .name') for REPO in $repos; do - $REPO = https://github.com/zyrafal/ts-template + $REPO = "https://github.com/zyrafal/ts-template" echo "Processing $REPO" gh repo clone ubiquity/$REPO cd $REPO From 3174b2050e68c6eec9e9cd764e28b5768841a4d1 Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:30:28 +0200 Subject: [PATCH 24/32] fix: replace repo --- .github/workflows/add-sync-to-repos.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index 882f710..219e814 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -21,9 +21,8 @@ jobs: original_remote=$(git remote get-url origin) repos=$(gh repo list ubiquity --limit 1 --json name,updatedAt -q '.[] | select(.updatedAt > (now - 30*24*60*60)) | .name') for REPO in $repos; do - $REPO = "https://github.com/zyrafal/ts-template" echo "Processing $REPO" - gh repo clone ubiquity/$REPO + gh repo clone zyrafal/$REPO cd $REPO branch_name="add-sync-script" git checkout -b $branch_name From 63530cc1b0965d3915e73d4ef87c652c78ff7040 Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 16:43:06 +0200 Subject: [PATCH 25/32] fix: try forking the repo --- .github/workflows/add-sync-to-repos.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml index 219e814..fc59586 100644 --- a/.github/workflows/add-sync-to-repos.yml +++ b/.github/workflows/add-sync-to-repos.yml @@ -16,23 +16,19 @@ jobs: run: | git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" - git config --global url."https://${{ secrets.GITHUB_TOKEN }}@github.com/".insteadOf "https://github.com/" sync_path=$(realpath .github/workflows/sync.yml) original_remote=$(git remote get-url origin) repos=$(gh repo list ubiquity --limit 1 --json name,updatedAt -q '.[] | select(.updatedAt > (now - 30*24*60*60)) | .name') for REPO in $repos; do echo "Processing $REPO" - gh repo clone zyrafal/$REPO + yes | gh repo fork --clone ubiquity/$REPO cd $REPO - branch_name="add-sync-script" - git checkout -b $branch_name mkdir -p .github/workflows cp $sync_path .github/workflows/sync.yml git add .github/workflows/sync.yml git commit -m "Add sync.yml workflow" - git remote set-url origin https://${{ secrets.GITHUB_TOKEN }}@github.com/ubiquity/$REPO.git - git push origin "$branch_name" - gh pr create --title "Add sync.yml workflow that synchronizes the template every month" --body "Details: https://github.com/ubiquity/ts-template/issues/54" --head "$original_remote:$branch_name" --base development + git push + gh pr create --title "Test" --body "Don't mind this, I'm just testing something." --base development cd .. rm -rf $REPO done From fddee05b7806d380171ab3ab9356ffaa387dbda2 Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 17:39:13 +0200 Subject: [PATCH 26/32] fix: add write permission to sync.yml --- .github/workflows/sync.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index 5e59622..c507f1f 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -8,7 +8,8 @@ on: jobs: sync: runs-on: ubuntu-latest - + permissions: + contents: write steps: - name: Checkout uses: actions/checkout@v4 From de08e6f0ad43ff50fcaf5eed4e5c1263e2e3a39a Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 17:43:27 +0200 Subject: [PATCH 27/32] fix: delete add-sync-to-repos.yml --- .github/workflows/add-sync-to-repos.yml | 34 ------------------------- 1 file changed, 34 deletions(-) delete mode 100644 .github/workflows/add-sync-to-repos.yml diff --git a/.github/workflows/add-sync-to-repos.yml b/.github/workflows/add-sync-to-repos.yml deleted file mode 100644 index fc59586..0000000 --- a/.github/workflows/add-sync-to-repos.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Add sync.yml to repos - -on: - workflow_dispatch: - -jobs: - update-repos: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Add sync.yml to each repo - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - git config --global user.email "github-actions[bot]@users.noreply.github.com" - git config --global user.name "github-actions[bot]" - sync_path=$(realpath .github/workflows/sync.yml) - original_remote=$(git remote get-url origin) - repos=$(gh repo list ubiquity --limit 1 --json name,updatedAt -q '.[] | select(.updatedAt > (now - 30*24*60*60)) | .name') - for REPO in $repos; do - echo "Processing $REPO" - yes | gh repo fork --clone ubiquity/$REPO - cd $REPO - mkdir -p .github/workflows - cp $sync_path .github/workflows/sync.yml - git add .github/workflows/sync.yml - git commit -m "Add sync.yml workflow" - git push - gh pr create --title "Test" --body "Don't mind this, I'm just testing something." --base development - cd .. - rm -rf $REPO - done From 67f39ba3b71f3a9f23d6e9fd9917b11bf91b3afb Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 21 Aug 2024 17:43:49 +0200 Subject: [PATCH 28/32] fix: add pull-requests permission to sync.yml --- .github/workflows/sync.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index c507f1f..c90fd3d 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -10,6 +10,7 @@ jobs: runs-on: ubuntu-latest permissions: contents: write + pull-requests: write steps: - name: Checkout uses: actions/checkout@v4 From 89a8e54735bc193a83652087bd2952333ea60b63 Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Fri, 30 Aug 2024 14:38:56 +0200 Subject: [PATCH 29/32] fix: avoid merge conflicts and rename sync.yml to sync-template.yml --- .github/workflows/{sync.yml => sync-template.yml} | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) rename .github/workflows/{sync.yml => sync-template.yml} (76%) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync-template.yml similarity index 76% rename from .github/workflows/sync.yml rename to .github/workflows/sync-template.yml index c90fd3d..6a658b6 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync-template.yml @@ -23,15 +23,16 @@ jobs: run: | branch_name=$(git rev-parse --abbrev-ref HEAD) original_remote=$(git remote get-url origin) - pr_branch="sync/${branch_name}" + pr_branch="sync-template/${branch_name}" git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" - git remote add template https://github.com/ubiquity/ts-template - git fetch template development - git update-index --assume-unchanged ".github/workflows/sync.yml" - git merge template/development --allow-unrelated-histories || true git checkout -b "$pr_branch" + git clone https://github.com/ubiquity/ts-template + cp -rf ts-template/* . + rm -rf ts-template/ git add . + git commit -m "Sync template" git push "$original_remote" "$pr_branch" gh pr create --title "Sync branch to template" --body "This pull request merges changes from the template repository." --head "$pr_branch" --base "$branch_name" + From b5235dc2f0d1b16932db1fc099669a2deb83ae32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A2=E3=83=AC=E3=82=AF=E3=82=B5=E3=83=B3=E3=83=80?= =?UTF-8?q?=E3=83=BC=2Eeth?= <4975670+0x4007@users.noreply.github.com> Date: Sun, 1 Sep 2024 16:31:00 +0900 Subject: [PATCH 30/32] Update sync-template.yml Co-authored-by: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> --- .github/workflows/sync-template.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-template.yml b/.github/workflows/sync-template.yml index 6a658b6..f92dd60 100644 --- a/.github/workflows/sync-template.yml +++ b/.github/workflows/sync-template.yml @@ -31,7 +31,7 @@ jobs: cp -rf ts-template/* . rm -rf ts-template/ git add . - git commit -m "Sync template" + git commit -m "chore: sync template" git push "$original_remote" "$pr_branch" gh pr create --title "Sync branch to template" --body "This pull request merges changes from the template repository." --head "$pr_branch" --base "$branch_name" From 4356e5c6c3b3059cbe01b3621e7be37355b0d10e Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 4 Sep 2024 12:29:15 +0200 Subject: [PATCH 31/32] feat: add a list of ignored files --- .github/workflows/sync-template.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/sync-template.yml b/.github/workflows/sync-template.yml index f92dd60..28827be 100644 --- a/.github/workflows/sync-template.yml +++ b/.github/workflows/sync-template.yml @@ -20,6 +20,7 @@ jobs: - name: Sync branch to template env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + IGNORE_FILES: "README.md another-file.txt" run: | branch_name=$(git rev-parse --abbrev-ref HEAD) original_remote=$(git remote get-url origin) @@ -28,6 +29,9 @@ jobs: git config --global user.name "github-actions[bot]" git checkout -b "$pr_branch" git clone https://github.com/ubiquity/ts-template + for file in $IGNORE_FILES; do + rm -rf "ts-template/$file" + done cp -rf ts-template/* . rm -rf ts-template/ git add . From 89b942ed3a2d87c00f2bf61057586e0ead5119d3 Mon Sep 17 00:00:00 2001 From: zyrafal <37906205+zyrafal@users.noreply.github.com> Date: Wed, 4 Sep 2024 12:48:29 +0200 Subject: [PATCH 32/32] feat: auth as the bot --- .github/workflows/sync-template.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sync-template.yml b/.github/workflows/sync-template.yml index 28827be..dc92ad5 100644 --- a/.github/workflows/sync-template.yml +++ b/.github/workflows/sync-template.yml @@ -16,10 +16,17 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + + - name: Get GitHub App token + uses: tibdex/github-app-token@v1.7.0 + id: get_installation_token + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} - name: Sync branch to template env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ steps.get_installation_token.outputs.token }} IGNORE_FILES: "README.md another-file.txt" run: | branch_name=$(git rev-parse --abbrev-ref HEAD)