diff --git a/.github/workflows/foreman_plugin.yml b/.github/workflows/foreman_plugin.yml index 8fedd45..8b85519 100644 --- a/.github/workflows/foreman_plugin.yml +++ b/.github/workflows/foreman_plugin.yml @@ -52,7 +52,7 @@ jobs: exclude: ${{ inputs.matrix_exclude }} test: - name: "Foreman ${{ inputs.foreman_version }} with Ruby ${{ matrix.ruby }} and Node ${{ matrix.node }} on PostgreSQL ${{ matrix.postgresql }}" + name: "${{ matrix.task }} - Foreman ${{ inputs.foreman_version }} with Ruby ${{ matrix.ruby }} and Node ${{ matrix.node }} on PostgreSQL ${{ matrix.postgresql }}" needs: setup_matrix runs-on: ubuntu-latest services: @@ -64,7 +64,14 @@ jobs: POSTGRES_PASSWORD: password strategy: fail-fast: false - matrix: ${{ fromJson(needs.setup_matrix.outputs.matrix) }} + matrix: + ruby: ${{ fromJson(needs.setup_matrix.outputs.matrix).ruby }} + node: ${{ fromJson(needs.setup_matrix.outputs.matrix).node }} + postgresql: ${{ fromJson(needs.setup_matrix.outputs.matrix).postgresql }} + task: + - 'test:${{ inputs.plugin }}' + - 'db:seed' + - 'plugin:assets:precompile[${{ inputs.plugin }}] RAILS_ENV=production DATABASE_URL=nulldb://nohost' steps: - run: sudo apt-get update - run: sudo apt-get install -y build-essential libcurl4-openssl-dev zlib1g-dev libpq-dev @@ -91,18 +98,53 @@ jobs: - name: Archive Gemfile.lock uses: actions/upload-artifact@v3 with: - name: Gemfile.lock + name: Gemfile-ruby-${{ matrix.ruby }}-node-${{ matrix.node }}-pg-${{ matrix.postgresql }}.lock path: Gemfile.lock - name: "Set up Node ${{ matrix.node }}" uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} + - name: Setup NPM Cache + if: ${{ hashFiles(format('{0}/package.json', inputs.plugin)) != '' && !contains(matrix.task, 'seed') }} + uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ matrix.node }}-${{ hashFiles('**/package.json') }} + restore-keys: | + ${{ runner.os }}-node-${{ matrix.node }}- + - name: "Build package-lock.json" + if: ${{ hashFiles(format('{0}/package.json', inputs.plugin)) != '' && !contains(matrix.task, 'seed') }} + run: bundle exec npm install --package-lock-only --no-audit + - name: Archive package-lock.json + if: ${{ hashFiles(format('{0}/package.json', inputs.plugin)) != '' && !contains(matrix.task, 'seed') }} + uses: actions/upload-artifact@v3 + with: + name: package-lock-ruby-${{ matrix.ruby }}-node-${{ matrix.node }}-pg-${{ matrix.postgresql }}.json + path: package-lock.json + - name: "Install NPM packages" + if: ${{ hashFiles(format('{0}/package.json', inputs.plugin)) != '' && !contains(matrix.task, 'seed') }} + run: bundle exec npm ci --no-audit - name: Prepare test env + if: ${{ !contains(matrix.task, 'nulldb') }} run: | bundle exec rake db:create bundle exec rake db:migrate - - name: Run plugin tests - run: bundle exec rake test:${{ inputs.plugin }} + - name: "Compile webpack" + if: ${{ hashFiles(format('{0}/package.json', inputs.plugin)) != '' && contains(matrix.task, 'test') }} + run: + bundle exec rake webpack:compile + - name: Add nulldb DB schema + run: cp -f db/schema.rb.nulldb db/schema.rb + if: ${{ contains(matrix.task, 'nulldb') }} + - name: Run rake ${{ matrix.task }} + run: bundle exec rake ${{ matrix.task }} + - name: Upload logs + uses: actions/upload-artifact@v3 + if: ${{ failure() && contains(matrix.task, 'test') }} + with: + name: logs-ruby-${{ matrix.ruby }}-node-${{ matrix.node }}-pg-${{ matrix.postgresql }} + path: log/*.log + retention-days: 5 database: name: "Database - Foreman ${{ inputs.foreman_version }} with Ruby ${{ matrix.ruby }} and Node ${{ matrix.node }} on PostgreSQL ${{ matrix.postgresql }}"