Skip to content

Commit b448d6a

Browse files
avidalsarahchen6
authored andcommitted
ci: use commit-headless to create signed commits from actions
Built on #9288
1 parent d7684b9 commit b448d6a

File tree

5 files changed

+124
-59
lines changed

5 files changed

+124
-59
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
issuer: https://token.actions.githubusercontent.com
2+
3+
subject: repo:DataDog/dd-trace-java:ref:refs/heads/master
4+
5+
claim_pattern:
6+
event_name: (schedule|workflow_dispatch)
7+
ref: refs/heads/master
8+
ref_protected: "true"
9+
job_workflow_ref: DataDog/dd-trace-java/\.github/workflows/update-jmxfetch-submodule\.yaml@refs/heads/master
10+
11+
permissions:
12+
contents: write
13+
pull_requests: write

.github/workflows/add-release-to-cloudfoundry.yaml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Add release to Cloud Foundry
2-
on:
2+
on:
33
release:
44
types:
55
- released
@@ -42,11 +42,23 @@ jobs:
4242
- name: Append release to Cloud Foundry repository
4343
run: |
4444
echo "${{ steps.get-release-version.outputs.VERSION }}: ${{ steps.get-release-url.outputs.URL }}" >> index.yml
45-
- name: Commit and push changes
46-
uses: planetscale/ghcommit-action@322be9669498a4be9ce66efc1169f8f43f6bd883 # v0.2.17
45+
- name: Commit changes
46+
id: create-commit
47+
run: |
48+
git config user.name "github-actions[bot]"
49+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
50+
51+
if [[ -z "$(git status -s)" ]]; then
52+
echo "No changes to commit, exiting."
53+
exit 0;
54+
fi
55+
56+
git commit -a -m "chore: Add version ${{ steps.get-release-version.outputs.VERSION }} to Cloud Foundry"
57+
echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
58+
- name: Push changes
59+
uses: DataDog/commit-headless@1186485b788f57eedaaadb19919781698b4d262f # action/v1.0.0
60+
if: ${{ steps.create-commit.outputs.commit != '' }}
4761
with:
48-
commit_message: "chore: Add version ${{ steps.get-release-version.outputs.VERSION }} to Cloud Foundry"
49-
repo: ${{ github.repository }}
5062
branch: cloudfoundry
51-
env:
52-
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
63+
command: push
64+
commits: "${{ steps.create-commit.outputs.commit }}"

.github/workflows/update-docker-build-image.yaml

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
update-docker-build-image:
1616
runs-on: ubuntu-latest
1717
permissions:
18-
contents: write # Required to create and push branch
18+
contents: read
1919
id-token: write # Required for OIDC token federation
2020
steps:
2121
- uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
@@ -26,17 +26,9 @@ jobs:
2626

2727
- name: Checkout the repository
2828
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
29-
- name: Download ghcommit CLI
30-
run: |
31-
curl https://github.com/planetscale/ghcommit/releases/download/v0.1.48/ghcommit_linux_amd64 -o /usr/local/bin/ghcommit -L
32-
chmod +x /usr/local/bin/ghcommit
3329
- name: Pick a branch name
3430
id: define-branch
3531
run: echo "branch=ci/update-docker-build-image-$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
36-
- name: Create branch
37-
run: |
38-
git checkout -b ${{ steps.define-branch.outputs.branch }}
39-
git push -u origin ${{ steps.define-branch.outputs.branch }} --force
4032
- name: Define the Docker build image tage to use
4133
id: define-tag
4234
run: |
@@ -59,11 +51,30 @@ jobs:
5951
- name: Update the Docker build image in GitLab CI config
6052
run: |
6153
sed -i '' -E 's|(BUILDER_IMAGE_VERSION_PREFIX:)[^#]*([#].*)|\1 "${{ steps.define-tag.outputs.tag }}-" \2|' .gitlab-ci.yml
62-
- name: Commit and push changes
63-
env:
64-
GITHUB_TOKEN: ${{ steps.octo-sts.outputs.token }}
54+
- name: Commit changes
55+
id: create-commit
6556
run: |
66-
ghcommit --repository ${{ github.repository }} --branch ${{ steps.define-branch.outputs.branch }} --add .gitlab-ci.yml --message "feat(ci): Update Docker build image"
57+
git config user.name "github-actions[bot]"
58+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
59+
60+
if [[ -z "$(git status -s)" ]]; then
61+
echo "No changes to commit, exiting."
62+
exit 0;
63+
fi
64+
65+
git commit --message "feat(ci): Update Docker build image" .gitlab-ci.yml
66+
echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
67+
- name: Push changes
68+
uses: DataDog/commit-headless@1186485b788f57eedaaadb19919781698b4d262f # action/v1.0.0
69+
if: ${{ steps.create-commit.outputs.commit != '' }}
70+
with:
71+
token: "${{ steps.octo-sts.outputs.token }}"
72+
branch: "${{ steps.define-branch.outputs.branch }}"
73+
# for scheduled runs, sha is the tip of the default branch
74+
# for dispatched runs, sha is the tip of the branch it was dispatched on
75+
branch-from: "${{ github.sha }}"
76+
command: push
77+
commits: "${{ steps.create-commit.outputs.commit }}"
6778
- name: Create pull request
6879
env:
6980
GH_TOKEN: ${{ steps.octo-sts.outputs.token }}

.github/workflows/update-gradle-dependencies.yaml

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
name: Update Gradle dependencies
1111
permissions:
12-
contents: write # Required to create new branch
12+
contents: read
1313
id-token: write # Required for OIDC token federation
1414
steps:
1515
- uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
@@ -22,16 +22,8 @@ jobs:
2222
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
2323
with:
2424
submodules: "recursive"
25-
- name: Download ghcommit CLI
26-
run: |
27-
curl https://github.com/planetscale/ghcommit/releases/download/v0.1.48/ghcommit_linux_amd64 -o /usr/local/bin/ghcommit -L
28-
chmod +x /usr/local/bin/ghcommit
2925
- name: Pick a branch name
30-
run: echo "BRANCH_NAME=ci/update-gradle-dependencies-$(date +'%Y%m%d')" >> $GITHUB_ENV
31-
- name: Create branch
32-
run: |
33-
git checkout -b $BRANCH_NAME
34-
git push -u origin $BRANCH_NAME --force
26+
run: echo "branch=ci/update-gradle-dependencies-$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
3527
- name: Update Gradle dependencies
3628
run: |
3729
GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx3G -Xms2G'" \
@@ -42,40 +34,58 @@ jobs:
4234
JAVA_21_HOME=$JAVA_HOME_21_X64 \
4335
./gradlew resolveAndLockAll --write-locks --parallel --stacktrace --no-daemon --max-workers=4
4436
- name: Commit changes
37+
id: create-commits
4538
env:
46-
GITHUB_TOKEN: ${{ steps.octo-sts.outputs.token }}
39+
BRANCH_NAME: ${{ steps.define-branch.outputs.branch }}
4740
run: |
48-
GH_ADD_ARGS=""
41+
git config user.name "github-actions[bot]"
42+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
43+
44+
FILES=""
45+
COMMITS=""
4946
COUNT=0
47+
# XXX: Could be replaced by ${{ github.sha }}
5048
BRANCH_HEAD=$(git rev-parse HEAD)
5149
for lockfile in $(git status --porcelain=v1 | awk '{ print $NF }'); do
5250
echo "Found lockfile: $lockfile"
53-
GH_ADD_ARGS="$GH_ADD_ARGS --add $lockfile"
51+
FILES="$FILES $lockfile"
5452
COUNT=$((COUNT+1))
5553
if [ $COUNT -eq 10 ]; then
56-
echo "Creating a commit to $BRANCH_NAME@$BRANCH_HEAD with $GH_ADD_ARGS"
57-
OUTPUT=$(ghcommit --repository ${{ github.repository }} --branch $BRANCH_NAME --sha $BRANCH_HEAD $GH_ADD_ARGS --message "chore: Update Gradle dependencies" 2>&1)
58-
echo $OUTPUT
59-
if [[ $OUTPUT != *"Success. New commit"* ]]; then
60-
exit 1
61-
fi
62-
BRANCH_HEAD=${OUTPUT##*/}
63-
echo "ghcommit output: $OUTPUT"
64-
GH_ADD_ARGS=""
54+
echo "Creating a commit to $BRANCH_NAME@$BRANCH_HEAD with files $FILES"
55+
git commit --no-verify --message="chore: Update Gradle dependencies" "${FILES}"
56+
COMMITS="$COMMITS $(git rev-parse HEAD)"
57+
FILES=""
6558
COUNT=0
6659
fi
6760
done
6861
# Check at uncommited files
6962
echo "Checking uncommited files"
7063
git status
71-
# Create a PR from the created branch
64+
65+
# Commit any remaining files
7266
if [ $COUNT -gt 0 ]; then
73-
echo "Creating a commit to $BRANCH_NAME@$BRANCH_HEAD with $GH_ADD_ARGS"
74-
ghcommit --repository ${{ github.repository }} --branch $BRANCH_NAME --sha $BRANCH_HEAD $GH_ADD_ARGS --message "chore: Update Gradle dependencies"
67+
echo "Creating a commit to $BRANCH_NAME@$BRANCH_HEAD with $FILES"
68+
git commit --no-verify --message="chore: Update Gradle dependencies" "${FILES}"
69+
COMMITS="$COMMITS $(git rev-parse HEAD)"
7570
fi
71+
72+
echo "Commits to push: ${COMMITS}"
73+
echo "commits=\"${COMMITS}\"" >> $GITHUB_OUTPUT
74+
- name: Push changes
75+
uses: DataDog/commit-headless@1186485b788f57eedaaadb19919781698b4d262f # action/v1.0.0
76+
if: ${{ steps.create-commits.outputs.commits != '' }}
77+
with:
78+
token: "${{ steps.octo-sts.outputs.token }}"
79+
branch: "${{ steps.define-branch.outputs.branch }}"
80+
# for scheduled runs, sha is the tip of the default branch
81+
# for dispatched runs, sha is the tip of the branch it was dispatched on
82+
branch-from: "${{ github.sha }}"
83+
command: push
84+
commits: "${{ steps.create-commits.outputs.commits }}"
7685
- name: Create pull request
7786
env:
7887
GH_TOKEN: ${{ steps.octo-sts.outputs.token }}
88+
BRANCH_NAME: ${{ steps.define-branch.outputs.branch }}
7989
run: |
8090
# use echo to set a multiline body for the PR
8191
echo -e "This PR updates the Gradle dependencies. ⚠️ Don't forget to squash commits before merging. ⚠️\n\n- [ ] Update PR title if a code change is needed to support one of those new dependencies" | \

.github/workflows/update-jmxfetch-submodule.yaml

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,51 @@ on:
88
jobs:
99
build:
1010
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
id-token: write
1114
steps:
15+
- uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
16+
id: octo-sts
17+
with:
18+
scope: ${{ github.repository }}
19+
policy: self.update-jmxfetch-submodule.create-pr
1220
- name: Checkout repository
1321
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
14-
1522
- name: Update Submodule
1623
run: |
1724
git submodule update --remote -- dd-java-agent/agent-jmxfetch/integrations-core
18-
- name: Download ghcommit CLI
19-
run: |
20-
curl https://github.com/planetscale/ghcommit/releases/download/v0.1.48/ghcommit_linux_amd64 -o /usr/local/bin/ghcommit -L
21-
chmod +x /usr/local/bin/ghcommit
2225
- name: Pick a branch name
2326
id: define-branch
2427
run: echo "branch=ci/update-jmxfetch-submodule-$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
25-
- name: Create branch
26-
run: |
27-
git checkout -b ${{ steps.define-branch.outputs.branch }}
28-
git push -u origin ${{ steps.define-branch.outputs.branch }} --force
29-
- name: Commit and push changes
30-
env:
31-
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
28+
- name: Commit changes
29+
id: create-commit
3230
run: |
33-
ghcommit --repository ${{ github.repository }} --branch ${{ steps.define-branch.outputs.branch }} --add dd-java-agent/agent-jmxfetch/integrations-core --message "Update agent-jmxfetch submodule"
31+
git config user.name "github-actions[bot]"
32+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
33+
34+
if [[ -z "$(git status -s)" ]]; then
35+
echo "No changes to commit, exiting."
36+
exit 0;
37+
fi
38+
39+
git commit -a -m "Update agent-jmxfetch submodule"
40+
echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
41+
- name: Push changes
42+
uses: DataDog/commit-headless@1186485b788f57eedaaadb19919781698b4d262f # action/v1.0.0
43+
if: ${{ steps.create-commit.outputs.commit != '' }}
44+
with:
45+
token: "${{ steps.octo-sts.outputs.token }}"
46+
branch: "${{ steps.define-branch.outputs.branch }}"
47+
# for scheduled runs, sha is the tip of the default branch
48+
# for dispatched runs, sha is the tip of the branch it was dispatched on
49+
branch-from: "${{ github.sha }}"
50+
command: push
51+
commits: "${{ steps.create-commit.outputs.commit }}"
3452
- name: Create pull request
53+
if: ${{ steps.create-commit.outputs.commit != '' }}
3554
env:
36-
GH_TOKEN: ${{ github.token }}
55+
GH_TOKEN: "${{ steps.octo-sts.outputs.token }}"
3756
run: |
3857
gh pr create --title "Update agent-jmxfetch submodule" \
3958
--base master \

0 commit comments

Comments
 (0)