From 4da7fd5a885358a0669b5e27b1d8cb7615c0d972 Mon Sep 17 00:00:00 2001 From: Jamil Date: Fri, 27 May 2022 19:07:59 -0700 Subject: [PATCH] Cache deps for static analysis tools (#654) --- .github/workflows/ci.yml | 31 +++++++++++++++++++++++++++---- .pre-commit-config.yaml | 2 +- .rubocop.yml | 1 + .tool-versions | 3 +++ Gemfile | 5 +++++ Gemfile.lock | 32 ++++++++++++++++++++++++++++++++ requirements.txt | 1 + 7 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 requirements.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6cb670ea3..ccd9cd4c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,11 +36,14 @@ jobs: with: ruby-version: '2.7' - uses: actions/setup-python@v2 + with: + python-version: '3.9' - uses: erlef/setup-beam@v1 with: otp-version: '25.0' elixir-version: '1.13.4' - uses: actions/cache@v2 + name: Setup Elixir cache with: path: | deps @@ -48,8 +51,29 @@ jobs: key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} restore-keys: | ${{ runner.os }}-mix- - - name: Install Dependencies + - uses: actions/cache@v2 + name: Setup ruby cache + with: + path: vendor/bundle + key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: | + ${{ runner.os }}-gems- + - uses: actions/cache@v2 + name: Setup Python cache + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + - name: Install Elixir Dependencies run: mix deps.get --only dev + - name: Install Ruby Dependencies + run: | + bundle config path vendor/bundle + bundle install --jobs 4 --retry 3 + - name: Install Python Dependencies + run: | + pip install -r requirements.txt # Don't cache PLTs based on mix.lock hash, as Dialyzer can incrementally update even old ones # Cache key based on Elixir & Erlang version (also usefull when running in matrix) - name: Restore PLT cache @@ -66,9 +90,8 @@ jobs: - name: Create PLTs if: steps.plt_cache.outputs.cache-hit != 'true' run: mix dialyzer --plt - - run: | - gem install rubocop - pip install pre-commit + - name: Run pre-commit + run: | pre-commit install SKIP=no-commit-to-branch pre-commit run --all-files diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ebe2afba9..8ff84c7f0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,7 +27,7 @@ repos: files: \.ex$ - id: rubocop name: 'ruby: rubocop' - entry: rubocop + entry: bundle exec rubocop language: system pass_filenames: false files: \.rb$ diff --git a/.rubocop.yml b/.rubocop.yml index d00fa9c49..2a553250e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,6 @@ AllCops: TargetRubyVersion: 2.7 Exclude: + - "vendor/**/*" - "apps/fz_http/assets/node_modules/**/*" - "omnibus/cookbooks/firezone/attributes/default.rb" diff --git a/.tool-versions b/.tool-versions index be70fd219..aec1f4ede 100644 --- a/.tool-versions +++ b/.tool-versions @@ -3,4 +3,7 @@ nodejs 14.19.3 elixir 1.13.4-otp-25 erlang 25.0 + +# Used for static analysis ruby 2.7.5 +python 3.9.13 diff --git a/Gemfile b/Gemfile new file mode 100644 index 000000000..11d1436b6 --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +source 'https://rubygems.org' + +gem 'rubocop' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 000000000..1c141db8d --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,32 @@ +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.2) + parallel (1.22.1) + parser (3.1.2.0) + ast (~> 2.4.1) + rainbow (3.1.1) + regexp_parser (2.4.0) + rexml (3.2.5) + rubocop (1.30.0) + parallel (~> 1.10) + parser (>= 3.1.0.0) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.18.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.18.0) + parser (>= 3.1.1.0) + ruby-progressbar (1.11.0) + unicode-display_width (2.1.0) + +PLATFORMS + ruby + +DEPENDENCIES + rubocop + +BUNDLED WITH + 2.1.4 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..416634f52 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pre-commit