diff --git a/.github/workflows/full_build.yml b/.github/workflows/full_build.yml new file mode 100644 index 00000000..10bcec63 --- /dev/null +++ b/.github/workflows/full_build.yml @@ -0,0 +1,111 @@ +name: Houdini build +on: [push, pull_request] +jobs: + notice_ruby: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, + # change this to (see https://github.com/ruby/setup-ruby#versioning): + # uses: ruby/setup-ruby@v1 + uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0 + - uses: actions/cache@v1 + name: Use Gem cache + with: + path: vendor/bundle + key: bundle-use-ruby-ubuntu-latest-2.6.6-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: | + bundle-use-ruby-ubuntu-latest-2.6.6- + - name: bundle install + run: | + bundle config deployment true + bundle config path vendor/bundle + bundle install --jobs 4 + - name: run notice:ruby:verify + run: | + bin/rails notice:ruby:verify + notice_js: + runs-on: ubuntu-latest + needs: notice_ruby + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, + # change this to (see https://github.com/ruby/setup-ruby#versioning): + # uses: ruby/setup-ruby@v1 + uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0 + - name: Setup Node.js environment + uses: actions/setup-node@v1.4.2 + - uses: actions/cache@v1 + name: Use Node package cache + with: + path: node_modules + key: bundle-use-node-js-ubuntu-latest-12-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + bundle-use-node-js-ubuntu-latest-12- + - uses: actions/cache@v1 + name: Use Gem cache + with: + path: vendor/bundle + key: bundle-use-ruby-ubuntu-latest-2.6.6-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: | + bundle-use-ruby-ubuntu-latest-2.6.6- + - name: bundle install + run: | + bundle config deployment true + bundle config path vendor/bundle + bundle install --jobs 4 + - name: install node packages + run: yarn install --frozen-lockfile + - name: run notice:js:verify + run: | + bin/rails notice:js:verify + main_build: + needs: [notice_js] + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + node: [12] + ruby: [2.6.6] + steps: + - uses: actions/checkout@v2 + - name: Setup PostgreSQL with PostgreSQL extensions and unprivileged user + uses: Daniel-Marynicz/postgresql-action@0.1.0 + with: + postgres_image_tag: 11-alpine + postgres_user: houdini_user + postgres_password: password + - name: Set up Ruby + # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, + # change this to (see https://github.com/ruby/setup-ruby#versioning): + # uses: ruby/setup-ruby@v1 + uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0 + - name: Setup Node.js environment + uses: actions/setup-node@v1.4.2 + - uses: actions/cache@v1 + name: Use Gem cache + with: + path: vendor/bundle + key: bundle-use-ruby-${{ matrix.os }}-${{ matrix.ruby }}-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: | + bundle-use-ruby-${{ matrix.os }}-${{ matrix.ruby }}- + - name: bundle install + run: | + bundle config deployment true + bundle config path vendor/bundle + bundle install --jobs 4 + - uses: actions/cache@v1 + name: Use Node package cache + with: + path: node_modules + key: bundle-use-node-js-${{ matrix.os }}-${{ matrix.node }}-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + bundle-use-node-js-${{ matrix.os }}-${{ matrix.node }}- + - name: run setup + run: bin/setup ci + - name: run spec + run: bin/rails spec + - name: run jest + run: yarn jest \ No newline at end of file diff --git a/bin/setup b/bin/setup index 39fcd7c5..233c15e7 100755 --- a/bin/setup +++ b/bin/setup @@ -19,15 +19,24 @@ FileUtils.chdir APP_ROOT do system('bundle check') || system!('bundle install') puts "\n== Installing dependencies (JS) ==" + yarn_cmd = 'yarn -s' + if ARGV.length > 0 && ARGV[0] == 'ci' + yarn_cmd += " --frozen-lockfile" + end system!('yarn -s') - puts "\n== Copying env file ==" - unless File.exist?('.env') - FileUtils.cp '.env.template', '.env' - end - puts "\n== Create new secrets ==" - File.write('.env', File.read('.env').gsub(/-- secret string --/) { SecureRandom.hex(64) }) + if ARGV.length == 0 || (ARGV.length > 0 && ARGV[0] != 'ci') + puts "\n== Copying env file ==" + unless File.exist?('.env') + FileUtils.cp '.env.template', '.env' + end + puts "\n== Create new secrets ==" + File.write('.env', File.read('.env').gsub(/-- secret string --/) { SecureRandom.hex(64) }) + else + puts "\n== Copying env file ==" + FileUtils.cp '.env.test', '.env' + end puts "\n== Preparing database ==" system! 'bin/rails db:prepare' diff --git a/lib/tasks/bundler_notice.rake b/lib/tasks/bundler_notice.rake deleted file mode 100644 index 23e3265b..00000000 --- a/lib/tasks/bundler_notice.rake +++ /dev/null @@ -1,22 +0,0 @@ -# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -desc "generating a notice for bundler" - -# Clear old activerecord sessions tables daily -task :bundler_notice => :environment do - require 'bundler' - require 'httparty' - parser = Bundler::LockfileParser.new(File.read(Rails.root.join("Gemfile.lock"))) - result = parser.specs.map do |spec| - "gem/rubygems/-/#{spec.name}/#{spec.version.to_s}" - end - - @options = { - :headers => { - 'Content-Type' => 'application/json', - 'Accept' => 'application/json' - } - } - - result = HTTParty.post("https://api.clearlydefined.io/notices", @options.merge(body:JSON::generate({coordinates: result}))) - byebug -end \ No newline at end of file diff --git a/lib/tasks/notice.rake b/lib/tasks/notice.rake new file mode 100644 index 00000000..6bac145f --- /dev/null +++ b/lib/tasks/notice.rake @@ -0,0 +1,59 @@ +# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later + +# Create notice files for dependencies +namespace :notice do + namespace :ruby do + require 'bundler' + require 'httparty' + def get_notice_ruby + parser = Bundler::LockfileParser.new(File.read(Rails.root.join("Gemfile.lock"))) + result = parser.specs.map do |spec| + "gem/rubygems/-/#{spec.name}/#{spec.version.to_s}" + end + + @options = { + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + }, + :timeout => 120 + } + result = HTTParty.post("https://api.clearlydefined.io/notices", @options.merge(body:JSON::generate({coordinates: result}))) + end + + desc "generating NOTICE-ruby from ClearlyDefined.io" + task :update do + result = get_notice_ruby + File.write('NOTICE-ruby', result.body) + end + + desc "checking whether NOTICE-ruby matches the one on ClearlyDefined.io" + task :verify do + result = get_notice_ruby + raise "NOTICE-ruby is not up to date. Run bin/rails notice:ruby:update to update the file." if result.body != File.read('NOTICE-ruby') + end + end + + namespace :js do + require 'fileutils' + def get_notice_js + raise "NOTICE-js could not be retrieved from Clearlydefined.io" unless system('yarn noticeme') + File.read('NOTICE') + end + + desc "generating NOTICE-js from ClearlyDefined.io" + task :update do + if (File.exists?('NOTICE')) + File.delete('NOTICE') + end + result = get_notice_js + FileUtils.mv('NOTICE', 'NOTICE-js', force: true) + end + + desc "checking whether NOTICE-js matches the one on ClearlyDefined.io" + task :verify do + result = get_notice_js + raise "NOTICE-js is not up to date. Run bin/rails notice:js:update to update the file." if result != File.read('NOTICE-js') + end + end +end \ No newline at end of file