-
Notifications
You must be signed in to change notification settings - Fork 5.8k
93 lines (78 loc) · 3.13 KB
/
Copy pathavocado-code.yaml
File metadata and controls
93 lines (78 loc) · 3.13 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
name: "Swagger Avocado - Analyze Code"
on:
pull_request:
types:
# default
- opened
- synchronize
- reopened
# re-run if base branch is changed, since previous merge commit may generate incorrect diff
- edited
permissions:
contents: read
jobs:
avocado-code:
name: "Swagger Avocado - Analyze Code"
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
with:
# Must include all branches, for git branch logic in Avocado to work correctly
fetch-depth: 0
- name: Setup Node and install deps
uses: ./.github/actions/setup-node-install-deps
- name: Run Avocado
id: run-avocado
run: |
set -x
AVOCADO_OUTPUT_FILE=$RUNNER_TEMP/avocado.ndjson
echo "output-file=$AVOCADO_OUTPUT_FILE" >> "$GITHUB_OUTPUT"
npm exec --no -- avocado \
--excludePaths \
"/common-types/" \
"/scenarios/" \
"/package.json" \
"/package-lock.json" \
"/cadl/examples/" \
'(?=/examples/)(?!(?:/stable/|/preview/))' \
"/\\.github/" \
"/eng/" \
--includePaths \
"data-plane" \
"resource-manager" \
--file \
"$AVOCADO_OUTPUT_FILE"
TIME=$(node -p 'JSON.stringify(new Date())')
# Avocado doesn't write any output if it was successful, so we add some to simplify later processing
[[ -e $AVOCADO_OUTPUT_FILE ]] || \
echo "{\"type\":\"Raw\",\"level\":\"Info\",\"message\":\"success\",\"time\":$TIME}" > "$AVOCADO_OUTPUT_FILE"
env:
# Tells Avocado to analyze the files changed between the PR head (default checkout)
# and the PR base branch.
SYSTEM_PULLREQUEST_TARGETBRANCH: ${{ github.event.pull_request.base.ref }}
# Avocado hardcodes these env vars to get repo and SHA
TRAVIS_REPO_SLUG: ${{ github.repository }}
TRAVIS_PULL_REQUEST_SHA: ${{ github.sha }}
- if: ${{ always() && (steps.run-avocado.outputs.output-file) }}
name: Install dependencies for github-script actions
uses: ./.github/actions/install-deps-github-script
- if: ${{ always() && (steps.run-avocado.outputs.output-file) }}
name: Generate job summary
id: generate-job-summary
uses: actions/github-script@v8
with:
script: |
const { default: generateJobSummary } =
await import('${{ github.workspace }}/.github/workflows/src/avocado-code.js');
return await generateJobSummary({ core });
env:
AVOCADO_OUTPUT_FILE: ${{ steps.run-avocado.outputs.output-file }}
# Used by other workflows like set-status
- if: ${{ always() && steps.generate-job-summary.outputs.summary }}
name: Set job-summary artifact
uses: actions/upload-artifact@v7
with:
name: job-summary
path: ${{ steps.generate-job-summary.outputs.summary }}
# If the file doesn't exist, just don't add the artifact
if-no-files-found: ignore