Skip to content

Commit

Permalink
User docs github action: push via ssh / deploy key (nvaccess#17100)
Browse files Browse the repository at this point in the history
Due to very good and strict permissions on branches such as beta, A normal GitHub action token cannot push to the branch.
Description of development approach
Push via ssh using a deploy key.
  • Loading branch information
michaelDCurran authored Sep 3, 2024
1 parent 3524568 commit 8b48583
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,29 @@ jobs:
if: success()

- name: Commit and Push changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$ErrorActionPreference = 'Stop'
git config --local user.name "GitHub Actions"
git config --local user.email "[email protected]"
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git
$filesChanged = git diff --name-only -- *.xliff
if ($filesChanged) {
Write-Host "xliff files were changed. Committing and pushing changes."
foreach ($file in $filesChanged) {
git add $file
Write-Host "Committing $file"
git commit -m "Update $file"
}
Write-Host "Setting up ssh for push"
# Ensure .ssh directory exists
New-Item -ItemType Directory -Force -Path ~/.ssh
# Add github.com to the list of known hosts for ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts
# set the private key of the Github deploy key as the ssh key
$privateKey = "${{ secrets.XLIFF_DEPLOY_PRIVATE_KEY }}"
$privateKey | Out-File -FilePath ~/.ssh/id_rsa -Encoding ascii
# Tell git to use ssh for pushing
git remote set-url origin [email protected]:${{ github.repository }}
Write-Host "Pushing changes"
git push origin HEAD
} else {
Write-Host "No xliff files were changed. Skipping commit and push."
Expand Down

0 comments on commit 8b48583

Please sign in to comment.