From 8cbfffa007e5834bdb5cd8e1c52822fede05bb23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Nesveda?= Date: Thu, 14 May 2026 11:17:08 +0200 Subject: [PATCH 1/4] chore: Use custom action to commit changes in CI instead of `git commit` --- .github/workflows/build_archives.yaml | 19 +++++-- .github/workflows/update-templates.yml | 72 ++++++++++++-------------- 2 files changed, 48 insertions(+), 43 deletions(-) diff --git a/.github/workflows/build_archives.yaml b/.github/workflows/build_archives.yaml index 1db9ddd1..048fc153 100644 --- a/.github/workflows/build_archives.yaml +++ b/.github/workflows/build_archives.yaml @@ -28,10 +28,19 @@ jobs: - name: Build template archives run: npm run build - - name: Commit the updated template archives + - name: Stage the updated template archives + id: stage run: | - git config user.name 'GitHub Actions' - git config user.email 'github-actions[bot]@users.noreply.github.com' git add dist/* templates/* - git diff-index --quiet HEAD || git commit -m 'chore: Update template archives [skip ci]' || true - git push + if git diff --cached --quiet; then + echo "has-changes=false" >> "$GITHUB_OUTPUT" + else + echo "has-changes=true" >> "$GITHUB_OUTPUT" + fi + + - name: Commit the updated template archives + if: steps.stage.outputs.has-changes == 'true' + uses: apify/workflows/commit@v0.44.0 + with: + commit-message: 'chore: Update template archives [skip ci]' + github-token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} diff --git a/.github/workflows/update-templates.yml b/.github/workflows/update-templates.yml index 416f1937..90b38a71 100644 --- a/.github/workflows/update-templates.yml +++ b/.github/workflows/update-templates.yml @@ -43,26 +43,6 @@ jobs: token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} fetch-depth: 0 - - name: Configure Git - run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - - - name: Check and manage branch - run: | - # Fetch all branches - git fetch origin - - # Check if branch exists on remote - if git ls-remote --heads origin "${{ steps.branch-name.outputs.BRANCH_NAME }}" | grep -q "${{ steps.branch-name.outputs.BRANCH_NAME }}"; then - echo "Branch ${{ steps.branch-name.outputs.BRANCH_NAME }} exists, checking it out and resetting to origin/master" - git checkout "${{ steps.branch-name.outputs.BRANCH_NAME }}" - git reset --hard origin/master - else - echo "Branch ${{ steps.branch-name.outputs.BRANCH_NAME }} does not exist, creating it" - git checkout -b "${{ steps.branch-name.outputs.BRANCH_NAME }}" - fi - - name: Setup Node.js uses: actions/setup-node@v6 with: @@ -75,35 +55,51 @@ jobs: MODULE_VERSION: ${{ env.MODULE_VERSION }} run: node ./scripts/actions/update-templates.mts - - name: Commit and push changes - id: commit-and-push + - name: Stage changes + id: stage + run: | + git add -A + if git diff --cached --quiet; then + echo "has-changes=false" >> "$GITHUB_OUTPUT" + else + echo "has-changes=true" >> "$GITHUB_OUTPUT" + fi + + - name: Reset existing branch + if: steps.stage.outputs.has-changes == 'true' env: GH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} run: | BRANCH="${{ steps.branch-name.outputs.BRANCH_NAME }}" - # Check if there are any changes - if git diff --quiet && git diff --cached --quiet; then - echo "No changes to commit" - else - git add -A - git commit -m "chore: Update templates for base image: ${{ env.BASE_IMAGE_RAW }}" - echo "committed=true" >> $GITHUB_OUTPUT - - # Disable auto-merge on any existing PR before force-pushing, - # so the old commit can't be merged while we push the new one. - PR_NUMBER=$(gh pr list --head "$BRANCH" --base master --json number --jq '.[0].number // empty') - if [ -n "$PR_NUMBER" ]; then - gh pr merge "$PR_NUMBER" --disable-auto || true - fi + # If a PR already exists for this branch, disable auto-merge before + # we recreate the branch so the old commit can't be merged. + PR_NUMBER=$(gh pr list --head "$BRANCH" --base master --json number --jq '.[0].number // empty') + if [ -n "$PR_NUMBER" ]; then + gh pr merge "$PR_NUMBER" --disable-auto || true + fi - git push --force origin "$BRANCH" + # Delete the remote branch if it exists. The commit action below + # will recreate it from the current HEAD (which is origin/master). + if git ls-remote --heads origin "$BRANCH" | grep -q "$BRANCH"; then + echo "Deleting existing remote branch $BRANCH" + git push origin --delete "$BRANCH" fi + - name: Commit and push changes + id: commit-and-push + if: steps.stage.outputs.has-changes == 'true' + uses: apify/workflows/commit@v0.44.0 + with: + commit-message: "chore: Update templates for base image: ${{ env.BASE_IMAGE_RAW }}" + github-token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} + branch: ${{ steps.branch-name.outputs.BRANCH_NAME }} + create-branch: 'true' + - name: Create or update Pull Request env: GH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} - if: steps.commit-and-push.outputs.committed == 'true' + if: steps.stage.outputs.has-changes == 'true' run: | BRANCH="${{ steps.branch-name.outputs.BRANCH_NAME }}" From 59dd9c6088034b87bbe152e4bb359e68e33424f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Nesveda?= Date: Fri, 15 May 2026 16:47:10 +0200 Subject: [PATCH 2/4] Use `apify/actions/signed-commit`, simplify logic --- .github/workflows/build_archives.yaml | 16 +++------------- .github/workflows/update-templates.yml | 11 +++++------ 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build_archives.yaml b/.github/workflows/build_archives.yaml index 048fc153..f2fd7164 100644 --- a/.github/workflows/build_archives.yaml +++ b/.github/workflows/build_archives.yaml @@ -28,19 +28,9 @@ jobs: - name: Build template archives run: npm run build - - name: Stage the updated template archives - id: stage - run: | - git add dist/* templates/* - if git diff --cached --quiet; then - echo "has-changes=false" >> "$GITHUB_OUTPUT" - else - echo "has-changes=true" >> "$GITHUB_OUTPUT" - fi - - name: Commit the updated template archives - if: steps.stage.outputs.has-changes == 'true' - uses: apify/workflows/commit@v0.44.0 + uses: apify/actions/signed-commit@v1.0.0 with: - commit-message: 'chore: Update template archives [skip ci]' + message: 'chore: Update template archives [skip ci]' + add: 'dist/* templates/*' github-token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} diff --git a/.github/workflows/update-templates.yml b/.github/workflows/update-templates.yml index 90b38a71..6fbdd37e 100644 --- a/.github/workflows/update-templates.yml +++ b/.github/workflows/update-templates.yml @@ -55,11 +55,10 @@ jobs: MODULE_VERSION: ${{ env.MODULE_VERSION }} run: node ./scripts/actions/update-templates.mts - - name: Stage changes + - name: Detect changes id: stage run: | - git add -A - if git diff --cached --quiet; then + if git diff --quiet && [ -z "$(git ls-files --others --exclude-standard)" ]; then echo "has-changes=false" >> "$GITHUB_OUTPUT" else echo "has-changes=true" >> "$GITHUB_OUTPUT" @@ -89,9 +88,9 @@ jobs: - name: Commit and push changes id: commit-and-push if: steps.stage.outputs.has-changes == 'true' - uses: apify/workflows/commit@v0.44.0 + uses: apify/actions/signed-commit@v1.0.0 with: - commit-message: "chore: Update templates for base image: ${{ env.BASE_IMAGE_RAW }}" + message: "chore: Update templates for base image: ${{ env.BASE_IMAGE_RAW }}" github-token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} branch: ${{ steps.branch-name.outputs.BRANCH_NAME }} create-branch: 'true' @@ -99,7 +98,7 @@ jobs: - name: Create or update Pull Request env: GH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} - if: steps.stage.outputs.has-changes == 'true' + if: steps.commit-and-push.outputs.committed == 'true' run: | BRANCH="${{ steps.branch-name.outputs.BRANCH_NAME }}" From e1ad8470eac476777ba7e5d7fa20ff36c33f1861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Nesveda?= Date: Fri, 15 May 2026 17:13:58 +0200 Subject: [PATCH 3/4] Fix formatting --- .github/workflows/update-templates.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-templates.yml b/.github/workflows/update-templates.yml index 6fbdd37e..f2e9afdb 100644 --- a/.github/workflows/update-templates.yml +++ b/.github/workflows/update-templates.yml @@ -90,7 +90,7 @@ jobs: if: steps.stage.outputs.has-changes == 'true' uses: apify/actions/signed-commit@v1.0.0 with: - message: "chore: Update templates for base image: ${{ env.BASE_IMAGE_RAW }}" + message: 'chore: Update templates for base image: ${{ env.BASE_IMAGE_RAW }}' github-token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} branch: ${{ steps.branch-name.outputs.BRANCH_NAME }} create-branch: 'true' From f98b5559abb7e13b6ca7703a9f86fb93fff62208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Nesveda?= Date: Mon, 18 May 2026 16:37:39 +0200 Subject: [PATCH 4/4] chore: bump apify/actions/signed-commit to v1.1.2 --- .github/workflows/build_archives.yaml | 2 +- .github/workflows/update-templates.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_archives.yaml b/.github/workflows/build_archives.yaml index f2fd7164..00ae3203 100644 --- a/.github/workflows/build_archives.yaml +++ b/.github/workflows/build_archives.yaml @@ -29,7 +29,7 @@ jobs: run: npm run build - name: Commit the updated template archives - uses: apify/actions/signed-commit@v1.0.0 + uses: apify/actions/signed-commit@v1.1.2 with: message: 'chore: Update template archives [skip ci]' add: 'dist/* templates/*' diff --git a/.github/workflows/update-templates.yml b/.github/workflows/update-templates.yml index f2e9afdb..75f26c27 100644 --- a/.github/workflows/update-templates.yml +++ b/.github/workflows/update-templates.yml @@ -88,7 +88,7 @@ jobs: - name: Commit and push changes id: commit-and-push if: steps.stage.outputs.has-changes == 'true' - uses: apify/actions/signed-commit@v1.0.0 + uses: apify/actions/signed-commit@v1.1.2 with: message: 'chore: Update templates for base image: ${{ env.BASE_IMAGE_RAW }}' github-token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}