Skip to content

feat: use npm for managing js packages #1604

feat: use npm for managing js packages

feat: use npm for managing js packages #1604

Workflow file for this run

name: Rails Template CI
on:
workflow_dispatch:
pull_request:
push:
branches:
- main
schedule:
# * is a special character in YAML so you have to quote this string
# * At 05:00 UTC every Monday, run the latest commit on the default or base branch
- cron: '0 5 * * MON'
concurrency:
# Pushing new changes to a branch will cancel any in-progress CI runs
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# Restrict jobs in this workflow to have no permissions by default; permissions
# should be granted per job as needed using a dedicated `permissions` block
permissions: {}
env:
# reduces noise from npm install
DISABLE_OPENCOLLECTIVE: true
OPEN_SOURCE_CONTRIBUTOR: true
NPM_CONFIG_FUND: false
NPM_CONFIG_AUDIT: false
jobs:
audit_dependencies:
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Audit dependencies for security vulnerabilities
uses: g-rath/check-with-osv-detector@main
with:
osv-detector-version: 0.13.0
test:
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-node@v4
with:
node-version-file: '.node-version'
cache: 'npm'
- run: npm ci
- run: npm run format-check
rubocop:
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install Ruby and Bundler
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: 'ruby'
- name: Run Rubocop
run: bundle exec rubocop
test_generated_apps:
permissions:
contents: read
runs-on: ubuntu-latest
strategy:
# don't stop all variants if one of them fails (we usually want to know
# how many fail)
fail-fast: false
matrix:
variant:
- name: defaults
config_path: 'ackama_rails_template.config.yml'
install_actionlint: 'yes'
- name: all
config_path: 'ci/configs/all.yml'
install_actionlint: 'yes'
- name: all-typescript
config_path: 'ci/configs/all-typescript.yml'
install_actionlint: 'yes'
- name: basic
config_path: 'ci/configs/basic.yml'
- name: basic-typescript
config_path: 'ci/configs/basic-typescript.yml'
- name: github_actions
config_path: 'ci/configs/github_actions.yml'
install_actionlint: 'yes'
- name: react
config_path: 'ci/configs/react.yml'
- name: react-typescript
config_path: 'ci/configs/react-typescript.yml'
- name: sidekiq
config_path: 'ci/configs/sidekiq.yml'
- name: devise
config_path: 'ci/configs/devise.yml'
- name: basic_with_skips
config_path: 'ci/configs/basic.yml'
skips: --skip-spring --skip-javascript
- name: bootstrap
config_path: 'ci/configs/bootstrap.yml'
- name: bootstrap-typescript
config_path: 'ci/configs/bootstrap-typescript.yml'
- name: capistrano
config_path: 'ci/configs/deploy_with_capistrano.yml'
- name: ackama_ec2_capistrano
config_path: 'ci/configs/deploy_with_ackama_ec2_capistrano.yml'
services:
db:
image: postgres
env:
# The Postgres service fails its docker health check unless you
# specify these environment variables
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: anything # can be anything, is ignored by the tests
ports: ['5432:5432']
# prettier-ignore
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout this repo
uses: actions/checkout@v4
with:
persist-credentials: false
# this ensures that osv-detector is available for running bin/ci-run
- name: Check dependencies for vulnerabilities (and setup osv-detector)
uses: g-rath/check-with-osv-detector@main
with:
osv-detector-version: 0.13.0
# this ensures that actionlint is available for running bin/ci-run
- name: Setup ActionLint
if: matrix.variant.install_actionlint == 'yes'
run: |
bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
sudo ln -s "$PWD/actionlint" /usr/local/bin/actionlint
- name: Install NodeJS
uses: actions/setup-node@v4
with:
node-version-file: '.node-version'
- name: Install latest version of npm
run: npm i -g npm
# We don't cache gems or JS packages because we are actually testing how
# installation and setup works in this project so, while caching would
# make CI faster, it might hide problems.
- name: Install Ruby and Bundler
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: 'ruby'
- name: Setup git for committing
run: |
# We do some git commits during our testing so these need to be set
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
- run: ./ci/bin/create-fake-js-package-managers npm
- name: Run CI script
env:
# Remember that your app name becomes a top-level constant in the
# Rails app so you'll run into issues if that constant shares a name
# with a class provided by a gem. Basically, don't name your app
# "react", "sidekiq" etc.
APP_NAME: ${{ matrix.variant.name }}-demo
CONFIG_PATH: ${{ matrix.variant.config_path }}
SKIPS: '--skip-javascript --skip-docker ${{ matrix.variant.skips }}'
PGUSER: postgres
PGPASSWORD: postgres
PGHOST: localhost
run: ./ci/bin/build-and-test