Skip to content

Commit ff1ff70

Browse files
authored
chore: Use custom action to commit changes in CI instead of git commit (#297)
We want to enforce commit signing for all commits in our repositories. To do that, we need to make sure even commits created by CI workflows are signed. It would be possible to sign using GPG keys, but that would require a lot of maintenance. Instead, we can commit using the GitHub GraphQL API, which automatically signs commits. This PR replaces direct `git commit` / `git push` usage (and third-party commit actions like `EndBug/add-and-commit`) with the `apify/actions/signed-commit` action, which uses the GraphQL API under the hood.
1 parent a1e8619 commit ff1ff70

5 files changed

Lines changed: 39 additions & 35 deletions

File tree

.github/workflows/check-execute-workflow-dist.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ jobs:
3333
run: pnpm --filter execute-workflow build
3434

3535
- name: Commit and push if changed
36-
uses: EndBug/add-and-commit@v10
36+
uses: apify/actions/signed-commit@v1.0.0
3737
with:
38-
author_name: github-actions[bot]
39-
author_email: 41898282+github-actions[bot]@users.noreply.github.com
4038
message: "chore: rebuild execute-workflow dist [skip ci]"
4139
add: 'execute-workflow/dist/'
40+
github-token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}

.github/workflows/claude-md-maintenance.yml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,32 @@ jobs:
9797
echo "changed=false" >> "$GITHUB_OUTPUT"
9898
fi
9999
100+
- name: Prepare branch name
101+
if: steps.diff.outputs.changed == 'true'
102+
id: branch
103+
run: echo "name=chore/update-claude-md-$(date +%Y%m%d%H%M%S)" >> "$GITHUB_OUTPUT"
104+
105+
- name: Commit CLAUDE.md
106+
if: steps.diff.outputs.changed == 'true'
107+
uses: apify/actions/signed-commit@v1.0.0
108+
with:
109+
message: "docs: update CLAUDE.md [skip ci]"
110+
add: CLAUDE.md
111+
github-token: ${{ github.token }}
112+
branch: ${{ steps.branch.outputs.name }}
113+
create-branch: 'true'
114+
100115
- name: Create PR with updated CLAUDE.md
101116
if: steps.diff.outputs.changed == 'true'
102117
id: create-pr
103118
env:
104119
GH_TOKEN: ${{ github.token }}
105120
run: |
106-
git config user.name "github-actions[bot]"
107-
git config user.email "github-actions[bot]@users.noreply.github.com"
108-
BRANCH="chore/update-claude-md-$(date +%Y%m%d%H%M%S)"
109-
git checkout -b "$BRANCH"
110-
git add CLAUDE.md
111-
git commit -m "docs: update CLAUDE.md [skip ci]"
112-
git push origin "$BRANCH"
113121
PR_URL=$(gh pr create \
114122
--title "docs: update CLAUDE.md" \
115123
--body "Automated update of CLAUDE.md generated by the Claude MD Maintenance workflow." \
116124
--base "${{ github.ref_name }}" \
117-
--head "$BRANCH")
125+
--head "${{ steps.branch.outputs.name }}")
118126
echo "pr_url=$PR_URL" >> "$GITHUB_OUTPUT"
119127
120128
- name: Assign PR and request review

.github/workflows/python_bump_and_update_changelog.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
bump_and_update_changelog:
2828
runs-on: ubuntu-latest
2929
outputs:
30-
changelog_commitish: ${{ steps.commit.outputs.commit_long_sha || github.sha }}
30+
changelog_commitish: ${{ steps.commit.outputs.commit_long_sha }}
3131

3232
steps:
3333
- name: Checkout repository
@@ -61,9 +61,8 @@ jobs:
6161

6262
- name: Commit changes
6363
id: commit
64-
uses: EndBug/add-and-commit@v10
64+
uses: apify/actions/signed-commit@v1.0.0
6565
with:
66-
author_name: github-actions[bot]
67-
author_email: 41898282+github-actions[bot]@users.noreply.github.com
6866
message: "chore(release): Update changelog and package version [skip ci]"
6967
pull: '--rebase --autostash'
68+
github-token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}

.github/workflows/sync_branches_push.yaml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ jobs:
4545
push:
4646
runs-on: ubuntu-latest
4747
steps:
48-
- name: git
48+
- name: Merge head branch into base branch via GitHub API
49+
env:
50+
GH_TOKEN: ${{ secrets.githubToken }}
4951
run: |
5052
if [ "${GITHUB_EVENT_NAME}" = "pull_request" ]; then
5153
HEAD_BRANCH="${GITHUB_BASE_REF}"
@@ -55,17 +57,11 @@ jobs:
5557
echo ">>> Don't know how to handle event name: ${GITHUB_EVENT_NAME}"
5658
exit 1
5759
fi
58-
mkdir repo
59-
cd repo
60-
git clone https://github-actions:${{ secrets.githubToken }}@github.com/${{ github.repository }}.git .
6160
62-
git config --global user.email "${{ inputs.gitConfigEmail }}"
63-
git config --global user.name "${{ inputs.gitConfigUsername }}"
64-
git config pull.rebase false
65-
66-
git switch ${{ inputs.baseBranch }}
67-
git pull origin ${HEAD_BRANCH} --no-edit --no-ff
68-
git push https://github-actions:${{ secrets.githubToken }}@github.com/${{ github.repository }}.git ${{ inputs.baseBranch }}:${{ inputs.baseBranch }}
61+
gh api -X POST "repos/${GITHUB_REPOSITORY}/merges" \
62+
-f base="${{ inputs.baseBranch }}" \
63+
-f head="${HEAD_BRANCH}" \
64+
-f commit_message="Merge ${HEAD_BRANCH} into ${{ inputs.baseBranch }}"
6965
7066
- name: report failure to slack
7167
if: ${{ failure() }}

git-cliff-release/README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ jobs:
4747
path: CHANGELOG.md
4848
write-mode: overwrite
4949
contents: ${{ steps.metadata.outputs.changelog }}
50+
- name: Stage changes
51+
run: git add -A
5052
- name: Commit changes
51-
uses: EndBug/add-and-commit@v10
53+
uses: apify/workflows/commit@main
5254
with:
53-
author_name: Foo
54-
author_email: foo@bar.com
55-
message: "chore(release): Update changelog and package version [skip ci]"
55+
commit-message: "chore(release): Update changelog and package version [skip ci]"
56+
github-token: ${{ secrets.GITHUB_TOKEN }}
5657
```
5758
5859
Manually trigger a release:
@@ -93,18 +94,19 @@ jobs:
9394
path: CHANGELOG.md
9495
write-mode: overwrite
9596
contents: ${{ steps.metadata.outputs.changelog }}
97+
- name: Stage changes
98+
run: git add -A
9699
- name: Commit changes
97100
id: commit
98-
uses: EndBug/add-and-commit@v10
101+
uses: apify/workflows/commit@main
99102
with:
100-
author_name: Foo
101-
author_email: foo@bar.com
102-
message: "chore(release): Update changelog and package version [skip ci]"
103+
commit-message: "chore(release): Update changelog and package version [skip ci]"
104+
github-token: ${{ secrets.GITHUB_TOKEN }}
103105
- name: Create release
104106
uses: softprops/action-gh-release@v2
105107
with:
106108
tag_name: ${{ steps.metadata.outputs.tag_name }}
107109
name: ${{ steps.metadata.outputs.version_number }}
108-
target_commitish: ${{ steps.commit.commit_long_sha || github.sha }}
110+
target_commitish: ${{ steps.commit.outputs.commit_long_sha }}
109111
body: ${{ steps.metadata.outputs.release_notes }}
110112
```

0 commit comments

Comments
 (0)