|
| 1 | +name: Lint JS and Ruby |
| 2 | + |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - 'master' |
| 8 | + pull_request: |
| 9 | + |
| 10 | +jobs: |
| 11 | + build: |
| 12 | + runs-on: ubuntu-22.04 |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v4 |
| 15 | + with: |
| 16 | + persist-credentials: false |
| 17 | + - name: Setup Ruby |
| 18 | + uses: ruby/setup-ruby@v1 |
| 19 | + with: |
| 20 | + ruby-version: 3 |
| 21 | + bundler: 2.5.9 |
| 22 | + - name: Setup Node |
| 23 | + uses: actions/setup-node@v4 |
| 24 | + with: |
| 25 | + node-version: 20 |
| 26 | + - name: Print system information |
| 27 | + run: | |
| 28 | + echo "Linux release: "; cat /etc/issue |
| 29 | + echo "Current user: "; whoami |
| 30 | + echo "Current directory: "; pwd |
| 31 | + echo "Ruby version: "; ruby -v |
| 32 | + echo "Node version: "; node -v |
| 33 | + echo "Yarn version: "; yarn --version |
| 34 | + echo "Bundler version: "; bundle --version |
| 35 | + - name: Save root node_modules to cache |
| 36 | + uses: actions/cache@v4 |
| 37 | + with: |
| 38 | + path: node_modules |
| 39 | + key: v5-package-node-modules-cache-${{ hashFiles('yarn.lock') }} |
| 40 | + - name: Save root ruby gems to cache |
| 41 | + uses: actions/cache@v4 |
| 42 | + with: |
| 43 | + path: vendor/bundle |
| 44 | + key: package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}-${{ hashFiles('Gemfile.development_dependencies') }}-oldest |
| 45 | + - name: Install Node modules with Yarn for renderer package |
| 46 | + run: | |
| 47 | + yarn install --no-progress --no-emoji |
| 48 | + sudo yarn global add yalc |
| 49 | + - name: yalc publish for react-on-rails |
| 50 | + run: yalc publish |
| 51 | + - name: Save spec/dummy/node_modules to cache |
| 52 | + uses: actions/cache@v4 |
| 53 | + with: |
| 54 | + path: spec/dummy/node_modules |
| 55 | + key: dummy-app-node-modules-cache-${{ hashFiles('spec/dummy/package.json') }}-newest |
| 56 | + - name: yalc add react-on-rails |
| 57 | + run: cd spec/dummy && yalc add react-on-rails |
| 58 | + - name: Install Node modules with Yarn for dummy app |
| 59 | + run: cd spec/dummy && yarn install --no-progress --no-emoji |
| 60 | + - name: Install Ruby Gems for package |
| 61 | + run: bundle check --path=vendor/bundle || bundle _2.5.9_ install --path=vendor/bundle --jobs=4 --retry=3 |
| 62 | + - name: Lint Ruby |
| 63 | + run: bundle exec rubocop |
| 64 | + - name: Install Node modules with Yarn for dummy app |
| 65 | + run: cd spec/dummy && yarn install --ignore-scripts --no-progress --no-emoji |
| 66 | + - name: Save dummy app ruby gems to cache |
| 67 | + uses: actions/cache@v4 |
| 68 | + with: |
| 69 | + path: spec/dummy/vendor/bundle |
| 70 | + key: dummy-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}-${{ hashFiles('Gemfile.development_dependencies') }}-oldest |
| 71 | + - name: Install Ruby Gems for dummy app |
| 72 | + run: | |
| 73 | + cd spec/dummy |
| 74 | + bundle lock --add-platform 'x86_64-linux' |
| 75 | + if ! bundle check --path=vendor/bundle; then |
| 76 | + bundle _2.5.9_ install --path=vendor/bundle --jobs=4 --retry=3 |
| 77 | + fi |
| 78 | + - name: generate file system-based packs |
| 79 | + run: cd spec/dummy && RAILS_ENV="test" bundle exec rake react_on_rails:generate_packs |
| 80 | + - name: Detect dead code |
| 81 | + run: | |
| 82 | + yarn run knip |
| 83 | + yarn run knip --production |
| 84 | + - name: Lint JS |
| 85 | + run: yarn start lint |
| 86 | + - name: Check formatting |
| 87 | + run: yarn start format.listDifferent |
| 88 | + - name: Type-check TypeScript |
| 89 | + run: yarn run type-check |
| 90 | + # We only download and run Actionlint if there is any difference in GitHub Action workflows |
| 91 | + # https://github.com/rhysd/actionlint/blob/main/docs/usage.md#on-github-actions |
| 92 | + - name: Check for GitHub Actions changes |
| 93 | + id: check-workflows |
| 94 | + run: | |
| 95 | + git fetch origin ${{ github.event.pull_request.base.sha }} |
| 96 | + if git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -q '^.github/workflows'; then |
| 97 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 98 | + response=$(curl -sf https://api.github.com/repos/rhysd/actionlint/releases/latest) |
| 99 | + if [ $? -eq 0 ]; then |
| 100 | + actionlint_version=$(echo "$response" | jq -r .tag_name) |
| 101 | + if [ -z "$actionlint_version" ]; then |
| 102 | + echo "Failed to parse Actionlint version" |
| 103 | + exit 1 |
| 104 | + fi |
| 105 | + else |
| 106 | + echo "Failed to fetch latest Actionlint version" |
| 107 | + exit 1 |
| 108 | + fi |
| 109 | + echo "actionlint_version=\"$actionlint_version\"" >> "$GITHUB_OUTPUT" |
| 110 | + fi |
| 111 | + - name: Setup Actionlint |
| 112 | + if: steps.check-workflows.outputs.changed == 'true' |
| 113 | + uses: actions/cache@v4 |
| 114 | + id: cache-actionlint |
| 115 | + with: |
| 116 | + path: ./actionlint |
| 117 | + key: ${{ runner.os }}-actionlint-${{ steps.check-workflows.outputs.actionlint_version }} |
| 118 | + - name: Download Actionlint |
| 119 | + if: steps.check-workflows.outputs.changed == 'true' && steps.cache-actionlint.outputs.cache-hit != 'true' |
| 120 | + run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) |
| 121 | + - name: Lint GitHub Actions |
| 122 | + if: steps.check-workflows.outputs.changed == 'true' |
| 123 | + run: | |
| 124 | + echo "::add-matcher::.github/actionlint-matcher.json" |
| 125 | + SHELLCHECK_OPTS="-S warning" ./actionlint -color |
| 126 | + shell: bash |
0 commit comments