Skip to content

Commit 99bf908

Browse files
authored
Merge pull request github#31541 from github/repo-sync
Repo sync
2 parents 1bb59f8 + 1ef1608 commit 99bf908

File tree

10 files changed

+129
-21
lines changed

10 files changed

+129
-21
lines changed

.github/workflows/content-lint-markdown.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ jobs:
4040
content/**
4141
data/**
4242
43+
- name: Print content linter annotations if changed content/data files
44+
if: steps.changed-files.outputs.any_changed == 'true'
45+
env:
46+
# Make it an environment variable so that its value doesn't need to be escaped.
47+
# See https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
48+
CHANGED_FILES: |-
49+
${{ steps.changed-files.outputs.all_changed_files }}
50+
# If there are errors, using `--print-annotations` will make it
51+
# so it does *not* exit non-zero.
52+
# This is so that all warnings and errors are printed.
53+
run: npm run lint-content -- --print-annotations --paths $CHANGED_FILES
54+
4355
- name: Run content linter if changed content/data files
4456
if: steps.changed-files.outputs.any_changed == 'true'
4557
env:

.github/workflows/move-content.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ on:
1111
- src/content-render/scripts/test-move-content.ts
1212
- 'src/frame/lib/**/*.js'
1313
- .github/workflows/move-content.yml
14+
# In case any of the dependencies affect the script
15+
- 'package*.json'
16+
- src/fixtures/fixtures/content/get-started/
17+
- src/fixtures/fixtures/content/code-security/
1418

1519
permissions:
1620
contents: read
@@ -38,12 +42,12 @@ jobs:
3842
ROOT: src/fixtures/fixtures
3943
run: |
4044
npm run move-content -- \
41-
src/fixtures/fixtures/content/get-started/quickstart/hello-world.md \
42-
src/fixtures/fixtures/content/get-started/quickstart/hello-wurld.md
45+
src/fixtures/fixtures/content/get-started/start-your-journey/hello-world.md \
46+
src/fixtures/fixtures/content/get-started/start-your-journey/hello-wurld.md
4347
4448
npm run test-moved-content -- \
45-
src/fixtures/fixtures/content/get-started/quickstart/hello-world.md \
46-
src/fixtures/fixtures/content/get-started/quickstart/hello-wurld.md
49+
src/fixtures/fixtures/content/get-started/start-your-journey/hello-world.md \
50+
src/fixtures/fixtures/content/get-started/start-your-journey/hello-wurld.md
4751
4852
# TODO: Add tests that inspects the git log
4953
git log | head -n 100

.github/workflows/orphaned-assets-check.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ on:
88
workflow_dispatch:
99
schedule:
1010
- cron: '20 16 * * 1' # Run every Monday at 16:20 UTC / 8:20 PST
11+
pull_request:
12+
paths:
13+
- .github/workflows/orphaned-assets-check.yml
14+
# In case any of the dependencies affect the script
15+
- 'package*.json'
16+
- src/assets/scripts/find-orphaned-assets.js
17+
- src/workflows/walk-files.js
18+
- src/languages/lib/languages.js
19+
- .github/actions/clone-translations/action.yml
20+
- .github/actions/node-npm-setup/action.yml
1121

1222
permissions:
1323
contents: read
@@ -38,6 +48,7 @@ jobs:
3848
env:
3949
# Needed for gh
4050
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_READPUBLICKEY }}
51+
DRY_RUN: ${{ github.event_name == 'pull_request'}}
4152
run: |
4253
set -e
4354
@@ -53,6 +64,13 @@ jobs:
5364
# If nothing to commit, exit now. It's fine. No orphans.
5465
git status -- ':!translations*' | grep 'nothing to commit' && exit 0
5566
67+
# When run on a pull_request, we're just testing the tooling.
68+
# Exit before it actually pushes the possible changes.
69+
if [ "$DRY_RUN" = "true" ]; then
70+
echo "Dry-run mode when run in a pull request"
71+
exit 0
72+
fi
73+
5674
# Replicated from the translation pipeline PR-maker Action
5775
git config --global user.name "docs-bot"
5876
git config --global user.email "[email protected]"
@@ -82,7 +100,7 @@ jobs:
82100
--label docs-content-fr
83101
84102
- uses: ./.github/actions/slack-alert
85-
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}
103+
if: ${{ failure() && github.event_name == 'schedule' }}
86104
with:
87105
slack_channel_id: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }}
88106
slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}

content/actions/using-workflows/events-that-trigger-workflows.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ redirect_from:
1010
versions:
1111
fpt: '*'
1212
ghes: '*'
13-
ghae: '*'
1413
ghec: '*'
1514
shortTitle: Events that trigger workflows
1615
---

content/actions/using-workflows/manually-running-a-workflow.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ intro: 'When a workflow is configured to run on the `workflow_dispatch` event, y
44
versions:
55
fpt: '*'
66
ghes: '*'
7-
ghae: '*'
87
ghec: '*'
98
shortTitle: Manually run a workflow
109
redirect_from:

package-lock.json

Lines changed: 14 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@
334334
"@typescript-eslint/parser": "6.17.0",
335335
"chalk": "^5.0.1",
336336
"change-case": "^5.0.2",
337-
"commander": "^11.0.0",
337+
"commander": "^12.0.0",
338338
"cross-env": "^7.0.3",
339339
"csp-parse": "0.0.2",
340340
"dedent": "^1.0.1",
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* This function is meant to be used by the code that runs the linter,
3+
* but only within Actions workflows. That means, if it works, it
4+
* posts all the annotations as inline comments on the PR.
5+
*
6+
*/
7+
8+
export function printAnnotationResults(results, { skippableRules = [] } = {}) {
9+
for (const [file, flaws] of Object.entries(results)) {
10+
for (const flaw of flaws) {
11+
if (intersection(flaw.ruleNames, skippableRules)) {
12+
continue
13+
}
14+
15+
let annotation = `::${flaw.severity === 'error' ? 'error' : 'warning'} `
16+
const bits = [`file=${file}`]
17+
if (flaw.lineNumber) {
18+
bits.push(`line=${flaw.lineNumber}`)
19+
// Note: it's possible to use a endLine property
20+
// if you can "lump" together the same error description on
21+
// consecutive lines.
22+
// See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-error-message
23+
}
24+
25+
if (flaw.ruleDescription) {
26+
bits.push(`title=${flaw.ruleDescription}`)
27+
}
28+
29+
annotation += `${bits.join(',')}`
30+
31+
if (flaw.errorDetail) {
32+
annotation += `::${flaw.errorDetail}`
33+
}
34+
35+
// Why console.log and not `core.error()` (from @actions/core)?
36+
// Because, this way you can debug this more easily on you own
37+
// terminal.
38+
console.log(annotation)
39+
}
40+
}
41+
}
42+
43+
function intersection(arr1, arr2) {
44+
return arr1.some((item) => arr2.includes(item))
45+
}

src/content-linter/scripts/lint-content.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { allConfig, allRules, customRules } from '../lib/helpers/get-rules.js'
1414
import { customConfig, githubDocsFrontmatterConfig } from '../style/github-docs.js'
1515
import { defaultConfig } from '../lib/default-markdownlint-options.js'
1616
import { prettyPrintResults } from './pretty-print-results.js'
17+
import { printAnnotationResults } from '../lib/helpers/print-annotations.js'
1718

1819
program
1920
.description('Run GitHub Docs Markdownlint rules.')
@@ -45,6 +46,7 @@ program
4546
.addOption(
4647
new Option('-o, --output-file <filepath>', `Outputs the errors/warnings to the filepath.`),
4748
)
49+
.option('--print-annotations', 'Print annotations for GitHub Actions check runs.', false)
4850
.parse(process.argv)
4951

5052
const {
@@ -56,6 +58,7 @@ const {
5658
outputFile,
5759
verbose,
5860
precommit: isPrecommit,
61+
printAnnotations,
5962
} = program.opts()
6063

6164
const ALL_CONTENT_DIR = ['content', 'data']
@@ -91,7 +94,7 @@ async function main() {
9194
customRules: configuredRules.data,
9295
})
9396

94-
// Run Markdownlint for data directory
97+
// Run Markdownlint for content directory (frontmatter only)
9598
const resultFrontmatter = await markdownlint.promises.markdownlint({
9699
frontMatter: null,
97100
files: files.content,
@@ -154,6 +157,18 @@ async function main() {
154157
})
155158
}
156159
}
160+
161+
if (printAnnotations) {
162+
printAnnotationResults(formattedResults, {
163+
skippableRules: [
164+
// As of Feb 2024, this rule is quite noisy. It's present in
165+
// many files and is not always a problem. And besides, when it
166+
// does warn, it's usually a very long one.
167+
'code-fence-line-length', // a.k.a. GHD030
168+
],
169+
})
170+
}
171+
157172
const end = Date.now()
158173
// Ensure previous console logging is not truncated
159174
console.log('\n')
@@ -214,9 +229,15 @@ async function main() {
214229
}
215230

216231
if (errorFileCount) {
217-
process.exit(1)
232+
if (printAnnotations) {
233+
console.warn('When printing annotations, the exit code is always 0')
234+
process.exit(0)
235+
} else {
236+
process.exit(1)
237+
}
238+
} else {
239+
spinner.succeed('No errors found')
218240
}
219-
spinner.succeed('No errors found')
220241
}
221242

222243
function pluralize(things, word, pluralForm = null) {

src/versions/tests/ghae-versioning.js renamed to src/versions/tests/ghes-versioning.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { allVersions } from '#src/versions/lib/all-versions.js'
22
import { liquid } from '#src/content-render/index.js'
3+
import { supported } from '#src/versions/lib/enterprise-server-releases.js'
34
import shortVersionsMiddleware from '#src/versions/middleware/short-versions.js'
45

56
const contextualize = (req) => {
@@ -12,14 +13,14 @@ describe('ifversion conditionals', () => {
1213
beforeAll(async () => {
1314
req.context = {
1415
allVersions,
15-
currentVersion: 'github-ae@latest',
16+
currentVersion: `enterprise-server@${supported[0]}`,
1617
}
1718
contextualize(req)
1819
})
1920

2021
test('greater than', async () => {
2122
const template = `
22-
{% ifversion ghae > 3.2 %}
23+
{% ifversion ghes > 3.2 %}
2324
FOO
2425
{% else %}
2526
BAR
@@ -31,7 +32,7 @@ describe('ifversion conditionals', () => {
3132

3233
test('less than', async () => {
3334
const template = `
34-
{% ifversion ghae < 3.2 %}
35+
{% ifversion ghes < 3.2 %}
3536
FOO
3637
{% else %}
3738
BAR
@@ -43,7 +44,7 @@ describe('ifversion conditionals', () => {
4344

4445
test('Equal', async () => {
4546
const template = `
46-
{% ifversion ghae %}
47+
{% ifversion ghes %}
4748
FOO
4849
{% else %}
4950
BAR
@@ -55,7 +56,7 @@ describe('ifversion conditionals', () => {
5556

5657
test('Not', async () => {
5758
const template = `
58-
{% ifversion not ghae %}
59+
{% ifversion not ghes %}
5960
FOO
6061
{% else %}
6162
BAR

0 commit comments

Comments
 (0)