Skip to content

Commit 66e238e

Browse files
authored
Grammar annotations and SD cache (#101)
* Grammar annotations and SD cache * Fix typo * Add npm cache * Resolve name conflict * Install and use fs * Use different annotation action * Change annotation schema * No restore key for cache
1 parent afe0e4b commit 66e238e

8 files changed

+115
-0
lines changed

.github/workflows/bioccheck.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ jobs:
7878
ref: ${{ steps.branch-name.outputs.head_ref_branch }}
7979
path: ${{ github.event.repository.name }}
8080

81+
- name: Restore SD cache 💰
82+
uses: actions/cache@v3
83+
with:
84+
key: sd-${{ runner.os }}-${{ github.event.repository.name }}
85+
path: ~/.staged.dependencies
86+
8187
- name: Run Staged dependencies 🎦
8288
uses: insightsengineering/staged-dependencies-action@v1
8389
with:

.github/workflows/build-check-install.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ jobs:
104104
ref: ${{ steps.branch-name.outputs.head_ref_branch }}
105105
path: ${{ github.event.repository.name }}
106106

107+
- name: Restore SD cache 💰
108+
uses: actions/cache@v3
109+
with:
110+
key: sd-${{ runner.os }}-${{ github.event.repository.name }}
111+
path: ~/.staged.dependencies
112+
107113
- name: Run Staged dependencies 🎦
108114
uses: insightsengineering/staged-dependencies-action@v1
109115
with:

.github/workflows/pkgdown.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ jobs:
7474
ref: ${{ steps.branch-name.outputs.head_ref_branch }}
7575
path: ${{ github.event.repository.name }}
7676

77+
- name: Restore SD cache 💰
78+
uses: actions/cache@v3
79+
with:
80+
key: sd-${{ runner.os }}-${{ github.event.repository.name }}
81+
path: ~/.staged.dependencies
82+
7783
- name: Run Staged dependencies 🎦
7884
uses: insightsengineering/staged-dependencies-action@v1
7985
with:

.github/workflows/roxygen.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ jobs:
6565
path: ${{ github.event.repository.name }}
6666
fetch-depth: 0
6767

68+
- name: Restore SD cache 💰
69+
uses: actions/cache@v3
70+
with:
71+
key: sd-${{ runner.os }}-${{ github.event.repository.name }}
72+
path: ~/.staged.dependencies
73+
6874
- name: Run Staged dependencies 🎦
6975
uses: insightsengineering/staged-dependencies-action@v1
7076
with:

.github/workflows/spelling.yaml

+70
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,73 @@ jobs:
4040
uses: insightsengineering/r-spellcheck-action@v2
4141
with:
4242
exclude: inst/extdata/*
43+
44+
grammar:
45+
name: Check grammar 🔡
46+
runs-on: ubuntu-latest
47+
if: >
48+
!contains(github.event.commits[0].message, '[skip spelling]')
49+
&& github.event.pull_request.draft == false
50+
51+
steps:
52+
- name: Checkout Code 🛎
53+
uses: actions/checkout@v3
54+
55+
- name: Restore npm cache 💰
56+
uses: actions/cache@v3
57+
with:
58+
key: npm-${{ runner.os }}-${{ github.job }}
59+
restore-keys: |
60+
npm-${{ runner.os }}-
61+
path: node_modules
62+
63+
- name: Setup NodeJS ☊
64+
uses: actions/setup-node@v3
65+
with:
66+
node-version: 18
67+
68+
- name: Install write-good ⏬
69+
run: npm install write-good glob fs
70+
71+
- name: Run write-good 🏃‍♀️
72+
uses: actions/github-script@v6
73+
with:
74+
github-token: ${{ secrets.GITHUB_TOKEN }}
75+
script: |
76+
const globber = require('glob');
77+
const writeGood = require('write-good');
78+
const path = require('path');
79+
const fs = require('fs');
80+
let files = globber.sync('**/*.@(Rd|Rmd|qmd|md)');
81+
let allSuggestions = [];
82+
files.forEach((file) => {
83+
if (fs.lstatSync(file).isFile() &&
84+
!path.dirname(file).startsWith("node_modules")) {
85+
const contents = fs.readFileSync(file, 'utf8');
86+
const suggestions = writeGood(contents);
87+
const annotations = writeGood.annotate(contents, suggestions, true);
88+
if (annotations.length) {
89+
for (var i=0; i < annotations.length; i++) {
90+
let ann = annotations[i];
91+
ann['message'] = ann['reason'];
92+
ann['start_column'] = ann['col'];
93+
ann['end_column'] = ann['col'];
94+
ann['start_line'] = ann['line'];
95+
ann['end_line'] = ann['line'];
96+
ann['annotation_level'] = 'notice';
97+
ann['path'] = file;
98+
delete ann['reason'];
99+
delete ann['col'];
100+
delete ann['line'];
101+
allSuggestions.push(ann);
102+
}
103+
}
104+
}
105+
});
106+
fs.writeFileSync('./annotations.json', JSON.stringify(allSuggestions, null, 2) , 'utf-8');
107+
108+
- name: Annotate files for grammar suggestions ✍️
109+
uses: kibalabs/[email protected]
110+
with:
111+
github-token: ${{ secrets.GITHUB_TOKEN }}
112+
json-file-path: ./annotations.json

.github/workflows/test-coverage.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ jobs:
7474
ref: ${{ steps.branch-name.outputs.head_ref_branch }}
7575
path: ${{ github.event.repository.name }}
7676

77+
- name: Restore SD cache 💰
78+
uses: actions/cache@v3
79+
with:
80+
key: sd-${{ runner.os }}-${{ github.event.repository.name }}
81+
path: ~/.staged.dependencies
82+
7783
- name: Run Staged dependencies 🎦
7884
uses: insightsengineering/staged-dependencies-action@v1
7985
with:
@@ -177,6 +183,12 @@ jobs:
177183
ref: ${{ steps.branch-name.outputs.head_ref_branch }}
178184
path: ${{ github.event.repository.name }}
179185

186+
- name: Restore SD cache 💰
187+
uses: actions/cache@v3
188+
with:
189+
key: sd-${{ runner.os }}-${{ github.event.repository.name }}
190+
path: ~/.staged.dependencies
191+
180192
- name: Run Staged dependencies 🎦
181193
uses: insightsengineering/staged-dependencies-action@v1
182194
with:

.github/workflows/validation.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ jobs:
5858
- name: Checkout repo 🛎
5959
uses: actions/checkout@v3
6060

61+
- name: Restore SD cache 💰
62+
uses: actions/cache@v3
63+
with:
64+
key: sd-${{ runner.os }}-${{ github.event.repository.name }}
65+
path: ~/.staged.dependencies
66+
6167
- name: Run Staged dependencies 🎦
6268
uses: insightsengineering/staged-dependencies-action@v1
6369
with:

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ vignettes/*.md
2828
vignettes/*.R
2929
coverage.*
3030
.vscode/
31+
node_modules/
32+
package-lock.json
33+
package.json

0 commit comments

Comments
 (0)