From 391a920866ed64009a859d7722d39ef18a8b7fa7 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Tue, 31 Oct 2023 18:17:35 +0100 Subject: [PATCH 1/7] Install NPM packages & compile webpack This only happens if package.json exists. --- .github/workflows/foreman_plugin.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/foreman_plugin.yml b/.github/workflows/foreman_plugin.yml index 8fedd45..8d0b596 100644 --- a/.github/workflows/foreman_plugin.yml +++ b/.github/workflows/foreman_plugin.yml @@ -97,10 +97,26 @@ jobs: uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} + - name: "Build package-lock.json" + if: ${{ hashFiles('${{ inputs.plugin }}/package.json') != '' }} + run: bundle exec npm install --package-lock-only --no-audit + - name: "Set up Node ${{ matrix.node }} cache" + if: ${{ hashFiles('${{ inputs.plugin }}/package.json') != '' }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + cache: 'npm' + - name: "Install NPM packages" + if: ${{ hashFiles('${{ inputs.plugin }}/package.json') != '' }} + run: bundle exec npm ci --no-audit - name: Prepare test env run: | bundle exec rake db:create bundle exec rake db:migrate + - name: "Compile webpack" + if: ${{ hashFiles('${{ inputs.plugin }}/package.json') != '' }} + run: + bundle exec rake webpack:compile - name: Run plugin tests run: bundle exec rake test:${{ inputs.plugin }} From 5bcb9beae7be00472d52d9890e4a70f1d525e673 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Thu, 30 Nov 2023 14:38:31 +0100 Subject: [PATCH 2/7] use format() to build the path to package.json https://github.com/orgs/community/discussions/25718 --- .github/workflows/foreman_plugin.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/foreman_plugin.yml b/.github/workflows/foreman_plugin.yml index 8d0b596..95dcc86 100644 --- a/.github/workflows/foreman_plugin.yml +++ b/.github/workflows/foreman_plugin.yml @@ -98,23 +98,23 @@ jobs: with: node-version: ${{ matrix.node }} - name: "Build package-lock.json" - if: ${{ hashFiles('${{ inputs.plugin }}/package.json') != '' }} + if: ${{ hashFiles(format('{0}/package.json', inputs.plugin)) != '' }} run: bundle exec npm install --package-lock-only --no-audit - name: "Set up Node ${{ matrix.node }} cache" - if: ${{ hashFiles('${{ inputs.plugin }}/package.json') != '' }} + if: ${{ hashFiles(format('{0}/package.json', inputs.plugin)) != '' }} uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} cache: 'npm' - name: "Install NPM packages" - if: ${{ hashFiles('${{ inputs.plugin }}/package.json') != '' }} + if: ${{ hashFiles(format('{0}/package.json', inputs.plugin)) != '' }} run: bundle exec npm ci --no-audit - name: Prepare test env run: | bundle exec rake db:create bundle exec rake db:migrate - name: "Compile webpack" - if: ${{ hashFiles('${{ inputs.plugin }}/package.json') != '' }} + if: ${{ hashFiles(format('{0}/package.json', inputs.plugin)) != '' }} run: bundle exec rake webpack:compile - name: Run plugin tests From 2a804c63fc59d1b52de399baf74941260454635f Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Thu, 30 Nov 2023 15:47:49 +0100 Subject: [PATCH 3/7] more caching and archiving --- .github/workflows/foreman_plugin.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/foreman_plugin.yml b/.github/workflows/foreman_plugin.yml index 95dcc86..e4a98c3 100644 --- a/.github/workflows/foreman_plugin.yml +++ b/.github/workflows/foreman_plugin.yml @@ -97,15 +97,23 @@ jobs: uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} + - name: Setup NPM Cache + if: ${{ hashFiles(format('{0}/package.json', inputs.plugin)) != '' }} + 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)) != '' }} run: bundle exec npm install --package-lock-only --no-audit - - name: "Set up Node ${{ matrix.node }} cache" + - name: Archive package-lock.json if: ${{ hashFiles(format('{0}/package.json', inputs.plugin)) != '' }} - uses: actions/setup-node@v4 + uses: actions/upload-artifact@v3 with: - node-version: ${{ matrix.node }} - cache: 'npm' + 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)) != '' }} run: bundle exec npm ci --no-audit From bdb7889115ad505ff4c6b00098ec0fd7c9490c9a Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Tue, 12 Dec 2023 09:36:11 +0100 Subject: [PATCH 4/7] run more tests for plugins --- .github/workflows/foreman_plugin.yml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/foreman_plugin.yml b/.github/workflows/foreman_plugin.yml index e4a98c3..469152f 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 @@ -125,8 +132,11 @@ jobs: if: ${{ hashFiles(format('{0}/package.json', inputs.plugin)) != '' }} run: bundle exec rake webpack:compile - - name: Run plugin tests - run: bundle exec rake test:${{ inputs.plugin }} + - name: Add nulldb DB schema + run: cp -f db/schema.rb.nulldb db/schema.rb + if: contains(matrix.task, 'precompile') + - name: Run rake ${{ matrix.task }} + run: bundle exec rake ${{ matrix.task }} database: name: "Database - Foreman ${{ inputs.foreman_version }} with Ruby ${{ matrix.ruby }} and Node ${{ matrix.node }} on PostgreSQL ${{ matrix.postgresql }}" From d7c06d3dc2a0971bd88eb2177ee1edb72f8d2068 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Tue, 12 Dec 2023 10:07:10 +0100 Subject: [PATCH 5/7] only install/compile Node stuff for specific tests --- .github/workflows/foreman_plugin.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/foreman_plugin.yml b/.github/workflows/foreman_plugin.yml index 469152f..77f5c71 100644 --- a/.github/workflows/foreman_plugin.yml +++ b/.github/workflows/foreman_plugin.yml @@ -105,7 +105,7 @@ jobs: with: node-version: ${{ matrix.node }} - name: Setup NPM Cache - if: ${{ hashFiles(format('{0}/package.json', inputs.plugin)) != '' }} + if: ${{ hashFiles(format('{0}/package.json', inputs.plugin)) != '' && !contains(matrix.task, 'seed') }} uses: actions/cache@v3 with: path: ~/.npm @@ -113,28 +113,29 @@ jobs: restore-keys: | ${{ runner.os }}-node-${{ matrix.node }}- - name: "Build package-lock.json" - if: ${{ hashFiles(format('{0}/package.json', inputs.plugin)) != '' }} + 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)) != '' }} + 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)) != '' }} + 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: "Compile webpack" - if: ${{ hashFiles(format('{0}/package.json', inputs.plugin)) != '' }} + 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, 'precompile') + if: ${{ contains(matrix.task, 'nulldb') }} - name: Run rake ${{ matrix.task }} run: bundle exec rake ${{ matrix.task }} From 28d66c82e5e41937b3001e5b5ca4819e6cfb8df3 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Tue, 12 Dec 2023 10:43:57 +0100 Subject: [PATCH 6/7] upload logs if test task fails --- .github/workflows/foreman_plugin.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/foreman_plugin.yml b/.github/workflows/foreman_plugin.yml index 77f5c71..f57ae15 100644 --- a/.github/workflows/foreman_plugin.yml +++ b/.github/workflows/foreman_plugin.yml @@ -138,6 +138,13 @@ jobs: 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 }}" From bb356f053c5bfd425d542462cad47f0d7193ce39 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Tue, 12 Dec 2023 10:58:02 +0100 Subject: [PATCH 7/7] use expressive gemfile lock name --- .github/workflows/foreman_plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/foreman_plugin.yml b/.github/workflows/foreman_plugin.yml index f57ae15..8b85519 100644 --- a/.github/workflows/foreman_plugin.yml +++ b/.github/workflows/foreman_plugin.yml @@ -98,7 +98,7 @@ 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