-
Notifications
You must be signed in to change notification settings - Fork 6
155 lines (142 loc) · 5.81 KB
/
wp-scripts-lint.yml
File metadata and controls
155 lines (142 loc) · 5.81 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: WP Scripts lint
on:
workflow_call:
inputs:
NODE_OPTIONS:
description: Space-separated list of command-line Node options.
type: string
default: ''
required: false
NODE_VERSION:
description: Node version with which the static code analysis is to be executed.
default: 18
required: false
type: string
NPM_REGISTRY_DOMAIN:
description: Domain of the private npm registry.
default: https://npm.pkg.github.com/
required: false
type: string
PACKAGE_MANAGER:
description: Package manager with which the dependencies should be installed (`npm` or `yarn`).
default: 'npm'
required: false
type: string
LINT_TOOLS:
description: Array of checks to be executed by @wordpress/scripts.
# [!] Note: "pkg-json" is not included by default. This is currently internally reviewed.
default: '["js", "style", "md-docs"]'
required: false
type: string
ESLINT_ARGS:
description: Set of arguments passed to `wp-scripts lint-js`.
default: ''
required: false
type: string
STYLELINT_ARGS:
description: Set of arguments passed to `wp-scripts lint-style`.
default: ''
required: false
type: string
MARKDOWNLINT_ARGS:
description: Set of arguments passed to `wp-scripts lint-md-docs`.
default: ''
required: false
type: string
PACKAGE_JSONLINT_ARGS:
description: Set of arguments passed to `wp-scripts lint-pkg-json`.
default: ''
required: false
type: string
secrets:
NPM_REGISTRY_TOKEN:
description: Authentication for the private npm registry.
required: false
GITHUB_USER_EMAIL:
description: Email address for the GitHub user configuration.
required: false
GITHUB_USER_NAME:
description: Username for the GitHub user configuration.
required: false
GITHUB_USER_SSH_KEY:
description: Private SSH key associated with the GitHub user passed as `GITHUB_USER_NAME`.
required: false
ENV_VARS:
description: Additional environment variables as a JSON formatted object.
required: false
jobs:
static-analysis-assets:
timeout-minutes: 5
runs-on: ubuntu-latest
env:
NODE_CACHE_MODE: ''
steps:
- name: PACKAGE_MANAGER deprecation warning
if: ${{ inputs.PACKAGE_MANAGER != '' }}
run: |
if [ "${{ inputs.PACKAGE_MANAGER }}" == 'npm' ]; then
echo "::warning::The PACKAGE_MANAGER input is deprecated and will be removed soon. Please remove it. The workflow already uses npm by default."
else
echo "::warning::The PACKAGE_MANAGER input is deprecated and will be removed soon. Please update your workflow to use npm."
fi
- name: Checkout
uses: actions/checkout@v4
- name: Set up custom environment variables
env:
ENV_VARS: ${{ secrets.ENV_VARS }}
if: ${{ env.ENV_VARS }}
uses: actions/github-script@v7
with:
script: |
JSON
.parse(process.env.ENV_VARS)
.forEach(envVar => core.exportVariable(envVar.name, envVar.value));
- name: Set up SSH
env:
GITHUB_USER_SSH_KEY: ${{ secrets.GITHUB_USER_SSH_KEY }}
if: ${{ env.GITHUB_USER_SSH_KEY != '' }}
uses: webfactory/ssh-agent@v0.10.0
with:
ssh-private-key: ${{ env.GITHUB_USER_SSH_KEY }}
- name: Set up Git
env:
GITHUB_USER_EMAIL: ${{ secrets.GITHUB_USER_EMAIL }}
GITHUB_USER_NAME: ${{ secrets.GITHUB_USER_NAME }}
if: ${{ env.GITHUB_USER_EMAIL != '' && env.GITHUB_USER_NAME != '' }}
run: |
git config --global user.email "${{ env.GITHUB_USER_EMAIL }}"
git config --global user.name "${{ env.GITHUB_USER_NAME }}"
- name: Set up node cache mode
run: |
if [ "${{ inputs.PACKAGE_MANAGER }}" == 'npm' ] && { [ -f "${GITHUB_WORKSPACE}/package-lock.json" ] || [ -f "${GITHUB_WORKSPACE}/npm-shrinkwrap.json" ]; }; then
echo "NODE_CACHE_MODE=npm" >> $GITHUB_ENV
elif [ "${{ inputs.PACKAGE_MANAGER }}" == 'yarn' ] && [ -f "${GITHUB_WORKSPACE}/yarn.lock" ]; then
echo "NODE_CACHE_MODE=yarn" >> $GITHUB_ENV
else
echo "No lock files found or unknown package manager"
fi
- name: Set up node
uses: actions/setup-node@v4
env:
NODE_OPTIONS: ${{ inputs.NODE_OPTIONS }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }}
with:
node-version: ${{ inputs.NODE_VERSION }}
registry-url: ${{ inputs.NPM_REGISTRY_DOMAIN }}
cache: ${{ env.NODE_CACHE_MODE }}
- name: Install dependencies
env:
ARGS: ${{ env.NODE_CACHE_MODE == 'yarn' && '--frozen-lockfile' || env.NODE_CACHE_MODE == 'npm' && 'ci' || 'install' }}
run: ${{ format('{0} {1}', inputs.PACKAGE_MANAGER, env.ARGS) }}
- name: Lint script files
if: ${{ contains(fromJSON(inputs.LINT_TOOLS), 'js') }}
run: ./node_modules/.bin/wp-scripts lint-js ${{ inputs.ESLINT_ARGS }}
- name: Lint style files
if: ${{ contains(fromJSON(inputs.LINT_TOOLS), 'style') }}
run: ./node_modules/.bin/wp-scripts lint-style ${{ inputs.STYLELINT_ARGS }} --formatter github
- name: Lint markdown files
if: ${{ contains(fromJSON(inputs.LINT_TOOLS), 'md-docs') }}
run: ./node_modules/.bin/wp-scripts lint-md-docs ${{ inputs.MARKDOWNLINT_ARGS }}
- name: Lint `package.json` files
if: ${{ contains(fromJSON(inputs.LINT_TOOLS), 'pkg-json') }}
run: ./node_modules/.bin/wp-scripts lint-pkg-json ${{ inputs.PACKAGE_JSONLINT_ARGS }}