Update Default Keybindings #201
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will retrieve the default keybindings JSON of latest stable version of VS Code across different OSs | |
name: Update Default Keybindings | |
on: | |
schedule: | |
# weekly | |
- cron: '38 16 * * 5' | |
workflow_dispatch: | |
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: 18 | |
- run: npm ci | |
- run: npm run build --if-present | |
- name: Run get-default-keybindings (Linux) | |
run: xvfb-run -a npm run get-default-keybindings | |
if: runner.os == 'Linux' | |
- name: Run get-default-keybindings (macOS) | |
run: | | |
node generator/_patch_for_ci_on_macos.js | |
npm run get-default-keybindings | |
if: runner.os == 'macOS' | |
- name: Run get-default-keybindings (Windows) | |
run: npm run get-default-keybindings | |
if: runner.os == 'Windows' | |
- name: Upload the output file | |
uses: actions/upload-artifact@v4 | |
with: | |
name: default-keybindings-${{ matrix.os }} | |
path: default-keybindings-*.json | |
check-for-diff: | |
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 default-keybindings-ubuntu-latest/default-keybindings-linux.json generator/ | |
cp default-keybindings-macos-latest/default-keybindings-mac.json generator/ | |
cp default-keybindings-windows-latest/default-keybindings-win.json generator/ | |
- name: Generate wrapper | |
run: npm run gen-wrapper | |
- name: Check for the diff | |
id: diff | |
shell: bash | |
run: | | |
if git diff --exit-code; then | |
echo "has-diff=false" >> $GITHUB_OUTPUT | |
echo "No diff found" | |
echo "### No diff found :+1:" >> $GITHUB_STEP_SUMMARY | |
else | |
echo "has-diff=true" >> $GITHUB_OUTPUT | |
fi | |
- name: Extract version numbers | |
id: ver | |
shell: bash | |
run: | | |
ver_linux=$(head -n 1 generator/default-keybindings-linux.json | sed -E "s/.*(([0-9]+\.){2}[0-9]+).*/\1/") | |
ver_macos=$(head -n 1 generator/default-keybindings-mac.json | sed -E "s/.*(([0-9]+\.){2}[0-9]+).*/\1/") | |
ver_windows=$(head -n 1 generator/default-keybindings-win.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 | |
echo "Versions:" >> $GITHUB_STEP_SUMMARY | |
echo "- VS Code for Linux: ${ver_linux}" >> $GITHUB_STEP_SUMMARY | |
echo "- VS Code for macOS: ${ver_macos}" >> $GITHUB_STEP_SUMMARY | |
echo "- VS Code for Windows: ${ver_windows}" >> $GITHUB_STEP_SUMMARY | |
- name: Make a unique branch name | |
id: branch-name | |
shell: bash | |
run: | | |
datetime=$(date +'%Y-%m-%d-%H-%M') | |
echo "branch-name=update-default-keybinding-${datetime}" >> $GITHUB_OUTPUT | |
- name: Make a commit and push a branch | |
if: steps.diff.outputs.has-diff == 'true' | |
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 generator package.json | |
version=${{ steps.ver.outputs.linux }} | |
git commit -m "Update for VSCode ${version}" | |
echo "Made 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' | |
shell: bash | |
run: | | |
head=${{ steps.branch-name.outputs.branch-name }} | |
version=${{ steps.ver.outputs.linux }} | |
title="Update wrappers based on VS Code ${version}" | |
body="This pull request has been generated by the automated workflow [Update Default Keybindings](https://github.com/tshino/vscode-kb-macro/actions/workflows/get-default-keybindings.yml)." | |
gh pr create --base main --head ${head} --title "${title}" --body "${body}" | |
echo "### Created a PR :rocket:" >> $GITHUB_STEP_SUMMARY | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |