Skip to content

Update Default Keybindings #1889

Update Default Keybindings

Update Default Keybindings #1889

# This workflow will retrieve the default keybindings JSON of latest stable version of VS Code across different OSs
name: Update Default Keybindings
on:
schedule:
- cron: '0 */12 * * *' # Every 12 hours
workflow_dispatch:
pull_request:
branches:
- master
paths:
- '.github/workflows/*'
- 'scripts/**'
jobs:
get-default-keybindings:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- run: npm ci
working-directory: ./scripts/get_default_keybindings
- name: Run get-default-keybindings (Linux)
run: xvfb-run -a npm start
working-directory: ./scripts/get_default_keybindings
if: runner.os == 'Linux'
- name: Run get-default-keybindings (macOS, Windows)
run: npm start
working-directory: ./scripts/get_default_keybindings
if: runner.os != 'Linux'
- name: Upload the output file
uses: actions/upload-artifact@v4
with:
name: raw-default-keybindings-${{ matrix.os }}
path: scripts/*.keybindings.raw.json
update-files-and-make-pr:
needs: get-default-keybindings
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download three JSON files
uses: actions/download-artifact@v4
- name: Copy JSON files
shell: bash
run: |
cp raw-default-keybindings-ubuntu-latest/linux.keybindings.raw.json scripts/
cp raw-default-keybindings-macos-latest/macos.keybindings.raw.json scripts/
cp raw-default-keybindings-windows-latest/windows.keybindings.raw.json scripts/
- name: Update keybindings files
run: python3 process_json.py
working-directory: ./scripts
- name: Check for the diff
id: diff
shell: bash
run: |
if git diff --exit-code; then
echo "has-diff=false" >> $GITHUB_OUTPUT
else
echo "has-diff=true" >> $GITHUB_OUTPUT
fi
- name: Extract version numbers
id: ver
shell: bash
run: |
ver_linux=$(head -n 1 scripts/linux.keybindings.raw.json | sed -E "s/.*(([0-9]+\.){2}[0-9]+).*/\1/")
ver_macos=$(head -n 1 scripts/macos.keybindings.raw.json | sed -E "s/.*(([0-9]+\.){2}[0-9]+).*/\1/")
ver_windows=$(head -n 1 scripts/windows.keybindings.raw.json | sed -E "s/.*(([0-9]+\.){2}[0-9]+).*/\1/")
echo "ver_linux: ${ver_linux}"
echo "ver_macos: ${ver_macos}"
echo "ver_windows: ${ver_windows}"
echo "linux=${ver_linux}" >> $GITHUB_OUTPUT
echo "macos=${ver_macos}" >> $GITHUB_OUTPUT
echo "windows=${ver_windows}" >> $GITHUB_OUTPUT
- name: Check for existing PR for the same version
id: pr
shell: bash
run: |
version=${{ steps.ver.outputs.linux }}
title="Update for VSCode ${version}"
openprs=$(gh pr list --json number,author,title --search 'is:open')
closedprs=$(gh pr list --json number,author,title --search 'is:closed')
prlist=$(jq --argjson openprs "$openprs" --argjson closedprs "$closedprs" -n '$openprs + $closedprs | unique_by(.number)')
echo "prlist: ${prlist}"
echo "title: ${title}"
match=$(echo ${prlist} | jq "map(select(.author.login==\"app/github-actions\") | select(.title==\"${title}\"))[0]")
echo "match: ${match}"
if [ "${match}" = "null" ]; then
echo "no PR for the same version found"
echo "exists=false" >> $GITHUB_OUTPUT
else
echo "a PR for the same version found"
echo "exists=true" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Make a unique branch name
id: branch-name
shell: bash
run: |
datetime=$(date +'%Y-%m-%d-%H-%M')
echo "branch-name=update-default-keybindings-${datetime}" >> $GITHUB_OUTPUT
- name: Make a commit and push a branch
if: steps.diff.outputs.has-diff == 'true' && steps.pr.outputs.exists == 'false'
shell: bash
run: |
echo "Has diff!"
git checkout -b ${{ steps.branch-name.outputs.branch-name }}
git config user.name "gh-workflow"
git config user.email "[email protected]"
git add *.keybindings.json
version=${{ steps.ver.outputs.linux }}
git commit -m "Update for VSCode ${version}"
echo "Created a commit successfully"
git push origin ${{ steps.branch-name.outputs.branch-name }}
echo "Pushed a branch successfully"
- name: Make a PR
if: steps.diff.outputs.has-diff == 'true' && steps.pr.outputs.exists == 'false'
shell: bash
run: |
head=${{ steps.branch-name.outputs.branch-name }}
version=${{ steps.ver.outputs.linux }}
title="Update for VSCode ${version}"
body="This pull request has been generated by the automated workflow [Update Default Keybindings](https://github.com/codebling/vs-code-default-keybindings/actions/workflows/update-default-keybindings.yml)."
gh pr create --base master --head ${head} --title "${title}" --body "${body}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}