-
-
Notifications
You must be signed in to change notification settings - Fork 629
179 lines (172 loc) · 6.84 KB
/
Copy pathlint-js-and-ruby.yml
File metadata and controls
179 lines (172 loc) · 6.84 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
name: Lint JS and Ruby
permissions:
contents: read
on:
push:
branches:
- 'main'
# Always trigger on main; docs-only detection handles skipping heavy jobs
pull_request:
paths-ignore:
- '**.md'
- 'docs/**'
- 'react_on_rails_pro/**'
workflow_dispatch:
inputs:
force_run:
description: 'Force run all jobs (bypass detect-changes)'
required: false
type: boolean
default: false
jobs:
detect-changes:
permissions:
contents: read
actions: read
runs-on: ubuntu-22.04
outputs:
docs_only: ${{ steps.detect.outputs.docs_only }}
run_lint: ${{ steps.detect.outputs.run_lint }}
run_js_tests: ${{ steps.detect.outputs.run_js_tests }}
run_ruby_tests: ${{ steps.detect.outputs.run_ruby_tests }}
run_dummy_tests: ${{ steps.detect.outputs.run_dummy_tests }}
run_generators: ${{ steps.detect.outputs.run_generators }}
has_full_ci_label: ${{ steps.check-label.outputs.result }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Check for full-ci label
id: check-label
uses: ./.github/actions/check-full-ci-label
- name: Detect relevant changes
id: detect
run: |
# If force_run is true OR full-ci label is present, run everything
if [ "${{ inputs.force_run }}" = "true" ] || [ "${{ steps.check-label.outputs.result }}" = "true" ]; then
echo "run_lint=true" >> "$GITHUB_OUTPUT"
echo "run_js_tests=true" >> "$GITHUB_OUTPUT"
echo "run_ruby_tests=true" >> "$GITHUB_OUTPUT"
echo "run_dummy_tests=true" >> "$GITHUB_OUTPUT"
echo "run_generators=true" >> "$GITHUB_OUTPUT"
echo "docs_only=false" >> "$GITHUB_OUTPUT"
exit 0
fi
BASE_REF="${{ github.event.pull_request.base.sha || github.event.before || 'origin/main' }}"
script/ci-changes-detector "$BASE_REF"
shell: bash
- name: Guard docs-only main pushes
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: ./.github/actions/ensure-main-docs-safety
with:
docs-only: ${{ steps.detect.outputs.docs_only }}
previous-sha: ${{ github.event.before }}
build:
needs: detect-changes
# Skip only if: main push AND docs-only changes
# Otherwise run if: on main OR lint needed
# This allows docs-only commits to skip linting while ensuring full CI on main for code changes
if: |
!(
github.event_name == 'push' &&
github.ref == 'refs/heads/main' &&
needs.detect-changes.outputs.docs_only == 'true'
) && (
github.ref == 'refs/heads/main' ||
needs.detect-changes.outputs.run_lint == 'true'
)
env:
BUNDLE_FROZEN: true
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
# No need for history in lint job
fetch-depth: 1
persist-credentials: false
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3
bundler: 2.5.9
- name: Setup Node
uses: ./.github/actions/setup-node-with-retry
with:
# Pin to 22.11.0 (LTS) to avoid V8 bug in 22.21.0
# https://github.com/nodejs/node/issues/56010
node-version: '22.11.0'
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Get pnpm store directory
shell: bash
run: echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Print system information
run: |
echo "Linux release: "; cat /etc/issue
echo "Current user: "; whoami
echo "Current directory: "; pwd
echo "Ruby version: "; ruby -v
echo "Node version: "; node -v
echo "pnpm version: "; pnpm --version
echo "Bundler version: "; bundle --version
- name: Save root ruby gems to cache
uses: actions/cache@v4
with:
path: vendor/bundle
key: package-app-gem-cache-${{ hashFiles('Gemfile.lock') }}-lint
- name: Install Node modules with pnpm
run: pnpm install --frozen-lockfile
- name: Install Ruby Gems for package
run: cd react_on_rails && bundle check --path=vendor/bundle || bundle _2.5.9_ install --path=vendor/bundle --jobs=4 --retry=3
- name: Lint Ruby
run: cd react_on_rails && bundle exec rubocop
- name: Validate RBS type signatures
run: cd react_on_rails && bundle exec rake rbs:validate
# TODO: Re-enable Steep once RBS signatures are complete for all checked files
# Currently disabled because 374 type errors need to be fixed first
# - name: Run Steep type checker
# run: bundle exec rake rbs:steep
- name: Save dummy app ruby gems to cache
uses: actions/cache@v4
with:
path: react_on_rails/spec/dummy/vendor/bundle
key: dummy-app-gem-cache-${{ hashFiles('react_on_rails/spec/dummy/Gemfile.lock') }}-lint
- name: Install Ruby Gems for dummy app
run: |
cd react_on_rails/spec/dummy
bundle lock --add-platform 'x86_64-linux'
if ! bundle check --path=vendor/bundle; then
bundle _2.5.9_ install --path=vendor/bundle --jobs=4 --retry=3
fi
- name: generate file system-based packs
run: cd react_on_rails/spec/dummy && RAILS_ENV="test" bundle exec rake react_on_rails:generate_packs
- name: Detect dead code
run: |
pnpm exec knip --exclude binaries
pnpm exec knip --production --exclude binaries
- name: Lint JS
run: pnpm run eslint --report-unused-disable-directives
- name: Check formatting
run: pnpm start format.listDifferent
- name: Lint SCSS with stylelint
run: pnpm run lint:scss
- name: Type-check TypeScript
run: pnpm run type-check
- name: Pack for attw and publint
run: cd packages/react-on-rails && pnpm pack
- name: Lint package types
# our package is ESM-only
# Exclude internal exports used for react-on-rails-pro communication
run: pnpm run attw packages/react-on-rails/react-on-rails-*.tgz --profile esm-only --exclude-entrypoints reactApis ReactDOMServer
- name: Lint package publishing
run: pnpm run publint --strict packages/react-on-rails/react-on-rails-*.tgz
# We only download and run Actionlint if there is any difference in GitHub Action workflows
# https://github.com/rhysd/actionlint/blob/main/docs/usage.md#on-github-actions