-
Notifications
You must be signed in to change notification settings - Fork 73
137 lines (129 loc) · 5.35 KB
/
update-default-keybindings.yml
File metadata and controls
137 lines (129 loc) · 5.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# 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@v6
- uses: actions/setup-node@v6
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@v7
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@v6
- name: Download three JSON files
uses: actions/download-artifact@v8
- 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 "gh-workflow@example.com"
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 }}