Skip to content

Commit a8ab514

Browse files
committed
add github workflows for unit spec tests
1 parent 68c1852 commit a8ab514

File tree

6 files changed

+145
-0
lines changed

6 files changed

+145
-0
lines changed

.github/workflows/ci.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: "ci"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "main"
7+
paths-ignore:
8+
- '**.md'
9+
- 'examples/**'
10+
- 'LICENSE'
11+
- 'CODEOWNERS'
12+
- 'AUTHORS'
13+
workflow_dispatch:
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
Spec:
21+
uses: ./.github/workflows/module_ci.yml
22+
secrets: inherit

.github/workflows/module_ci.yml

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# This is a generic workflow for Puppet module CI operations.
2+
name: "Module CI"
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
runs_on:
8+
description: "The operating system used for the runner."
9+
required: false
10+
default: "ubuntu-latest"
11+
type: "string"
12+
flags:
13+
description: "Additional flags to pass to matrix_from_metadata_v2."
14+
required: false
15+
default: ''
16+
type: "string"
17+
18+
jobs:
19+
setup_matrix:
20+
name: "Setup Test Matrix"
21+
runs-on: ${{ inputs.runs_on }}
22+
outputs:
23+
spec_matrix: ${{ steps.get-matrix.outputs.spec_matrix }}
24+
25+
steps:
26+
27+
- name: "Checkout"
28+
uses: "actions/checkout@v4"
29+
with:
30+
ref: ${{ github.event.pull_request.head.sha }}
31+
32+
- name: "Setup ruby"
33+
uses: "ruby/setup-ruby@v1"
34+
with:
35+
ruby-version: "2.7"
36+
bundler-cache: true
37+
38+
- name: "Bundle environment"
39+
run: |
40+
echo ::group::bundler environment
41+
bundle env
42+
echo ::endgroup::
43+
44+
- name: Setup Spec Test Matrix
45+
id: get-matrix
46+
run: |
47+
bundle exec matrix_from_metadata_v2 ${{ inputs.flags }}
48+
49+
spec:
50+
name: "Spec tests (Puppet: ${{matrix.puppet_version}}, Ruby Ver: ${{matrix.ruby_version}})"
51+
needs: "setup_matrix"
52+
runs-on: ${{ inputs.runs_on }}
53+
strategy:
54+
fail-fast: false
55+
matrix: ${{ fromJson( needs.setup_matrix.outputs.spec_matrix ) }}
56+
57+
env:
58+
PUPPET_GEM_VERSION: ${{ matrix.puppet_version }}
59+
FACTER_GEM_VERSION: 'https://github.com/puppetlabs/facter#main' # why is this set?
60+
61+
steps:
62+
- name: "Checkout"
63+
uses: "actions/checkout@v4"
64+
with:
65+
ref: ${{ github.event.pull_request.head.sha }}
66+
67+
- name: "Setup ruby"
68+
uses: "ruby/setup-ruby@v1"
69+
with:
70+
ruby-version: ${{matrix.ruby_version}}
71+
bundler-cache: true
72+
73+
- name: "Bundle environment"
74+
run: |
75+
echo ::group::bundler environment
76+
bundle env
77+
echo ::endgroup::
78+
79+
- name: "Run Static & Syntax Tests"
80+
run: |
81+
bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop
82+
bundle exec dependency-checker metadata.json || true # temporarily allow to fail
83+
84+
- name: "Run tests"
85+
run: |
86+
bundle exec rake parallel_spec

.rspec_parallel

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--format progress

.rubocop.yml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ AllCops:
77
TargetRubyVersion: '2.6'
88
Include:
99
- "**/*.rb"
10+
- "**/*.rake"
1011
Exclude:
1112
- bin/*
1213
- ".vendor/**/*"

.sync.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
default_configs:
44
AllCops:
55
NewCops: enable
6+
Include:
7+
- '**/*.rake'
68
.pdkignore:
79
paths:
810
- /.*.yml

rakelib/common.rake

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require 'dependency_checker'
2+
require 'metadata_json_lint'
3+
4+
# PDK validate behaviors
5+
MetadataJsonLint.options.fail_on_warnings = true
6+
MetadataJsonLint.options.strict_license = true
7+
MetadataJsonLint.options.strict_puppet_version = true
8+
MetadataJsonLint.options.strict_dependencies = true
9+
10+
PuppetLint.configuration.log_forat = '%{path}:%{line}:%{check}:%{KIND}:%{message}'
11+
PuppetLint.configuration.fail_on_warnings = true
12+
13+
desc 'Run dependency-checker'
14+
task :metadata_deps do
15+
dpc = DependencyChecker::Runner.new
16+
dpc.resolve_from_files(['metadata.json'])
17+
dpc.run
18+
raise 'dependency checker failed' unless dpc.problems.zero?
19+
end
20+
21+
# output task execution
22+
unless Rake.application.options.trace
23+
setup = ->(task, *_args) do
24+
puts "===> rake: #{task}"
25+
end
26+
27+
task :log_hooker do
28+
Rake::Task.tasks.reject { |t| t.to_s == 'log_hooker' }.each do |a_task|
29+
a_task.actions.prepend(setup)
30+
end
31+
end
32+
Rake.application.top_level_tasks.prepend(:log_hooker)
33+
end

0 commit comments

Comments
 (0)