Skip to content

Commit b9f22d6

Browse files
authored
Implement KSM to pull a PAT for commits in format.yml (mlcommons#2011)
1 parent 2fdb814 commit b9f22d6

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

.github/workflows/format.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: "Code formatting"
33
on:
44
push:
55
branches:
6-
- "**"
6+
- "**"
77

88
env:
99
python_version: "3.9"
@@ -12,16 +12,25 @@ jobs:
1212
format-code:
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v4
15+
- name: Retrieve secrets from Keeper
16+
id: ksecrets
17+
uses: Keeper-Security/ksm-action@master
18+
with:
19+
keeper-secret-config: ${{ secrets.KSM_CONFIG }}
20+
secrets: |-
21+
v2h4jKiZlJywDSoKzRMnRw/field/Access Token > env:PAT # Fetch PAT and store in environment variable
22+
23+
- name: Checkout code
24+
uses: actions/checkout@v4
1625
with:
1726
fetch-depth: 0
18-
ssh-key: ${{ secrets.DEPLOY_KEY }}
27+
1928
- name: Set up Python ${{ env.python_version }}
2029
uses: actions/setup-python@v3
2130
with:
2231
python-version: ${{ env.python_version }}
2332

24-
- name: Format modified python files
33+
- name: Format modified Python files
2534
env:
2635
filter: ${{ github.event.before }}
2736
run: |
@@ -49,12 +58,15 @@ jobs:
4958
done
5059
5160
- name: Commit and push changes
61+
env:
62+
PAT: ${{ env.PAT }} # Use PAT fetched from Keeper
5263
run: |
5364
HAS_CHANGES=$(git diff --staged --name-only)
5465
if [ ${#HAS_CHANGES} -gt 0 ]; then
5566
git config --global user.name mlcommons-bot
5667
git config --global user.email "[email protected]"
5768
# Commit changes
5869
git commit -m '[Automated Commit] Format Codebase'
59-
git push
60-
fi
70+
# Use the PAT to push changes
71+
git push https://x-access-token:${PAT}@github.com/${{ github.repository }} HEAD:${{ github.ref_name }}
72+
fi

0 commit comments

Comments
 (0)