-
Notifications
You must be signed in to change notification settings - Fork 312
Use commit-headless to create signed commits from GHA #9302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
b448d6a
3215bed
5d8d682
17d121b
04ea047
a9a1f75
2a47f6a
f8587d4
3e3c04f
7744e40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ jobs: | |
runs-on: ubuntu-latest | ||
name: Update Gradle dependencies | ||
permissions: | ||
contents: write # Required to create new branch | ||
contents: read | ||
id-token: write # Required for OIDC token federation | ||
steps: | ||
- uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3 | ||
|
@@ -22,16 +22,8 @@ jobs: | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2 | ||
with: | ||
submodules: "recursive" | ||
- name: Download ghcommit CLI | ||
run: | | ||
curl https://github.com/planetscale/ghcommit/releases/download/v0.1.48/ghcommit_linux_amd64 -o /usr/local/bin/ghcommit -L | ||
chmod +x /usr/local/bin/ghcommit | ||
- name: Pick a branch name | ||
run: echo "BRANCH_NAME=ci/update-gradle-dependencies-$(date +'%Y%m%d')" >> $GITHUB_ENV | ||
- name: Create branch | ||
run: | | ||
git checkout -b $BRANCH_NAME | ||
git push -u origin $BRANCH_NAME --force | ||
run: echo "branch=ci/update-gradle-dependencies-$(date +'%Y%m%d')" >> $GITHUB_OUTPUT | ||
- name: Update Gradle dependencies | ||
run: | | ||
GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx3G -Xms2G'" \ | ||
|
@@ -42,40 +34,58 @@ jobs: | |
JAVA_21_HOME=$JAVA_HOME_21_X64 \ | ||
./gradlew resolveAndLockAll --write-locks --parallel --stacktrace --no-daemon --max-workers=4 | ||
- name: Commit changes | ||
id: create-commits | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 suggestion: For this part, I would recommend to get rid of the logic that create small commits (ie commit with less than 10 files) and check how the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I adjusted the logic for now after not finding evidence that commits are limited. However, this will need another review / pass through before merging 😅 |
||
env: | ||
GITHUB_TOKEN: ${{ steps.octo-sts.outputs.token }} | ||
BRANCH_NAME: ${{ steps.define-branch.outputs.branch }} | ||
run: | | ||
GH_ADD_ARGS="" | ||
git config user.name "github-actions[bot]" | ||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
|
||
FILES="" | ||
COMMITS="" | ||
COUNT=0 | ||
# XXX: Could be replaced by ${{ github.sha }} | ||
BRANCH_HEAD=$(git rev-parse HEAD) | ||
for lockfile in $(git status --porcelain=v1 | awk '{ print $NF }'); do | ||
echo "Found lockfile: $lockfile" | ||
GH_ADD_ARGS="$GH_ADD_ARGS --add $lockfile" | ||
FILES="$FILES $lockfile" | ||
COUNT=$((COUNT+1)) | ||
if [ $COUNT -eq 10 ]; then | ||
echo "Creating a commit to $BRANCH_NAME@$BRANCH_HEAD with $GH_ADD_ARGS" | ||
OUTPUT=$(ghcommit --repository ${{ github.repository }} --branch $BRANCH_NAME --sha $BRANCH_HEAD $GH_ADD_ARGS --message "chore: Update Gradle dependencies" 2>&1) | ||
echo $OUTPUT | ||
if [[ $OUTPUT != *"Success. New commit"* ]]; then | ||
exit 1 | ||
fi | ||
BRANCH_HEAD=${OUTPUT##*/} | ||
echo "ghcommit output: $OUTPUT" | ||
GH_ADD_ARGS="" | ||
echo "Creating a commit to $BRANCH_NAME@$BRANCH_HEAD with files $FILES" | ||
git commit --no-verify --message="chore: Update Gradle dependencies" "${FILES}" | ||
COMMITS="$COMMITS $(git rev-parse HEAD)" | ||
FILES="" | ||
COUNT=0 | ||
fi | ||
done | ||
# Check at uncommited files | ||
echo "Checking uncommited files" | ||
git status | ||
# Create a PR from the created branch | ||
|
||
# Commit any remaining files | ||
if [ $COUNT -gt 0 ]; then | ||
echo "Creating a commit to $BRANCH_NAME@$BRANCH_HEAD with $GH_ADD_ARGS" | ||
ghcommit --repository ${{ github.repository }} --branch $BRANCH_NAME --sha $BRANCH_HEAD $GH_ADD_ARGS --message "chore: Update Gradle dependencies" | ||
echo "Creating a commit to $BRANCH_NAME@$BRANCH_HEAD with $FILES" | ||
git commit --no-verify --message="chore: Update Gradle dependencies" "${FILES}" | ||
COMMITS="$COMMITS $(git rev-parse HEAD)" | ||
fi | ||
|
||
echo "Commits to push: ${COMMITS}" | ||
echo "commits=\"${COMMITS}\"" >> $GITHUB_OUTPUT | ||
- name: Push changes | ||
uses: DataDog/commit-headless@1186485b788f57eedaaadb19919781698b4d262f # action/v1.0.0 | ||
if: ${{ steps.create-commits.outputs.commits != '' }} | ||
with: | ||
token: "${{ steps.octo-sts.outputs.token }}" | ||
branch: "${{ steps.define-branch.outputs.branch }}" | ||
# for scheduled runs, sha is the tip of the default branch | ||
# for dispatched runs, sha is the tip of the branch it was dispatched on | ||
branch-from: "${{ github.sha }}" | ||
command: push | ||
commits: "${{ steps.create-commits.outputs.commits }}" | ||
- name: Create pull request | ||
env: | ||
GH_TOKEN: ${{ steps.octo-sts.outputs.token }} | ||
BRANCH_NAME: ${{ steps.define-branch.outputs.branch }} | ||
run: | | ||
# use echo to set a multiline body for the PR | ||
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" | \ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❔ question: If
contents: write
is no more needed, should we remove it to fromadd-release-to-clouldfoundry
?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it seems so! content permissions are specifically for
GITHUB_TOKEN
(ref), andadd-release-to-cloudfoundry
doesn't use this token to push anymore.EDIT: just kidding - Since there is no use of
dd-octo-sts
, I think the workflow is still usingGITHUB_TOKEN
and needs the write permissions to push 🤔