-
Notifications
You must be signed in to change notification settings - Fork 19
74 lines (64 loc) · 2.4 KB
/
Copy pathlint-css.yml
File metadata and controls
74 lines (64 loc) · 2.4 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
name: Lint CSS
on:
# Run on direct pushes to integration branches and on all pull requests.
push:
branches:
- develop
- main
- master
- trunk
pull_request:
# Allow manually triggering the workflow.
workflow_dispatch:
# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
lint:
runs-on: ubuntu-latest
name: "Lint: CSS"
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Cache Node.js modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node_modules-
# The lint stage doesn't run the unit tests or use code style, so no need for PHPUnit, WPCS or phpcompatibility.
- name: 'Install NPM packages'
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --prefer-offline --no-audit --ignore-scripts
- name: Get only files changed in this PR
id: changed-files
uses: actions/github-script@v6
with:
script: |
if (!context.payload.pull_request) {
core.warning("No pull request context available. Skipping changed files retrieval.");
core.setOutput('files', '');
return '';
}
const changedFiles = await github.paginate(
github.rest.pulls.listFiles,
{
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
}
);
const cssFiles = changedFiles
.filter(file => file.status !== 'removed')
.map(file => file.filename)
.filter(filename => filename.endsWith('.scss') || filename.endsWith('.css'))
.join(' ');
core.setOutput('files', cssFiles);
return cssFiles;
# If this is a PR then lint only css/scss changed in the PR, if not a PR then lint them all.
- name: Run stylelint
run: npx wp-scripts lint-style ${{ steps.changed-files.outputs.files || '' }}