Merge pull request #987 from pmcmaw/IAC-1597
[puppet-modules/puppetlabs-apt.git] / .github / workflows / spec.yml
1 name: "Spec Tests"
2
3 on:
4   schedule:
5     - cron: '0 0 * * *'
6   workflow_dispatch:
7   pull_request:
8
9 env:
10   HONEYCOMB_WRITEKEY: 7f3c63a70eecc61d635917de46bea4e6
11   HONEYCOMB_DATASET: litmus tests
12
13 jobs:
14   setup_matrix:
15     name: "Setup Test Matrix"
16     runs-on: ubuntu-20.04
17     outputs:
18       spec_matrix: ${{ steps.get-matrix.outputs.spec_matrix }}
19
20     steps:
21       - name: "Honeycomb: Start recording"
22         uses: puppetlabs/kvrhdn-gha-buildevents@pdk-templates-v1
23         with:
24           apikey: ${{ env.HONEYCOMB_WRITEKEY }}
25           dataset: ${{ env.HONEYCOMB_DATASET }}
26           job-status: ${{ job.status }}
27
28       - name: "Honeycomb: Start first step"
29         run: |
30           echo STEP_ID=setup-environment >> $GITHUB_ENV
31           echo STEP_START=$(date +%s) >> $GITHUB_ENV
32
33       - name: Checkout Source
34         uses: actions/checkout@v2
35         if: ${{ github.repository_owner == 'puppetlabs' }}
36
37       - name: Activate Ruby 2.7
38         uses: ruby/setup-ruby@v1
39         if: ${{ github.repository_owner == 'puppetlabs' }}
40         with:
41           ruby-version: "2.7"
42           bundler-cache: true
43
44       - name: Print bundle environment
45         if: ${{ github.repository_owner == 'puppetlabs' }}
46         run: |
47           echo ::group::bundler environment
48           buildevents cmd $TRACE_ID $STEP_ID 'bundle env' -- bundle env
49           echo ::endgroup::
50
51       - name: "Honeycomb: Record Setup Environment time"
52         if: ${{ github.repository_owner == 'puppetlabs' }}
53         run: |
54           buildevents step $TRACE_ID $STEP_ID $STEP_START 'Setup Environment'
55           echo STEP_ID=Setup-Acceptance-Test-Matrix >> $GITHUB_ENV
56           echo STEP_START=$(date +%s) >> $GITHUB_ENV
57
58       - name: Setup Spec Test Matrix
59         id: get-matrix
60         run: |
61           if [ '${{ github.repository_owner }}' == 'puppetlabs' ]; then
62             buildevents cmd $TRACE_ID $STEP_ID matrix_from_metadata -- bundle exec matrix_from_metadata_v2
63           else
64             echo  "::set-output name=spec_matrix::{}"
65           fi
66
67       - name: "Honeycomb: Record Setup Test Matrix time"
68         if: ${{ always() }}
69         run: |
70           buildevents step $TRACE_ID $STEP_ID $STEP_START 'Setup Test Matrix'
71
72   Spec:
73     name: "Spec Tests (Puppet: ${{matrix.puppet_version}}, Ruby Ver: ${{matrix.ruby_version}})"
74     needs:
75       - setup_matrix
76     if: ${{ needs.setup_matrix.outputs.spec_matrix != '{}' }}
77
78     runs-on: ubuntu-20.04
79     strategy:
80       fail-fast: false
81       matrix: ${{fromJson(needs.setup_matrix.outputs.spec_matrix)}}
82
83     env:
84       BUILDEVENT_FILE: '../buildevents.txt'
85       PUPPET_GEM_VERSION: ${{ matrix.puppet_version }}
86
87     steps:
88       - run: |
89           echo "SANITIZED_PUPPET_VERSION=$(echo '${{ matrix.puppet_version }}' | sed 's/~> //g')" >> $GITHUB_ENV
90
91       - run: |
92           echo 'puppet_version=${{ env.SANITIZED_PUPPET_VERSION }}' >> $BUILDEVENT_FILE
93
94       - name: "Honeycomb: Start first step"
95         run: |
96           echo "STEP_ID=${{ env.SANITIZED_PUPPET_VERSION }}-spec" >> $GITHUB_ENV
97           echo STEP_START=$(date +%s) >> $GITHUB_ENV
98
99       - name: "Honeycomb: Start recording"
100         uses: puppetlabs/kvrhdn-gha-buildevents@pdk-templates-v1
101         with:
102           apikey: ${{ env.HONEYCOMB_WRITEKEY }}
103           dataset: ${{ env.HONEYCOMB_DATASET }}
104           job-status: ${{ job.status }}
105           matrix-key: ${{ env.SANITIZED_PUPPET_VERSION }}
106
107       - name: Checkout Source
108         uses: actions/checkout@v2
109
110       - name: "Activate Ruby ${{ matrix.ruby_version }}"
111         uses: ruby/setup-ruby@v1
112         with:
113           ruby-version: ${{matrix.ruby_version}}
114           bundler-cache: true
115
116       - name: Print bundle environment
117         run: |
118           echo ::group::bundler environment
119           buildevents cmd $TRACE_ID $STEP_ID 'bundle env' -- bundle env
120           echo ::endgroup::
121
122       - name: Run Static & Syntax Tests
123         run: |
124           buildevents cmd $TRACE_ID $STEP_ID 'static_syntax_checks Puppet ${{ matrix.puppet_version }}, Ruby ${{ matrix.ruby_version }}' -- bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop
125       
126       - name: Run parallel_spec tests
127         run: |
128           buildevents cmd $TRACE_ID $STEP_ID 'rake parallel_spec Puppet ${{ matrix.puppet_version }}, Ruby ${{ matrix.ruby_version }}' -- bundle exec rake parallel_spec