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