(maint) - Update since_tag
[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: Run Static & Syntax Tests
59         if: ${{ github.repository_owner == 'puppetlabs' }}
60         run: |
61           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
62
63       - name: Setup Spec Test Matrix
64         id: get-matrix
65         run: |
66           if [ '${{ github.repository_owner }}' == 'puppetlabs' ]; then
67             buildevents cmd $TRACE_ID $STEP_ID matrix_from_metadata -- bundle exec matrix_from_metadata_v2
68           else
69             echo  "::set-output name=spec_matrix::{}"
70           fi
71
72       - name: "Honeycomb: Record Setup Test Matrix time"
73         if: ${{ always() }}
74         run: |
75           buildevents step $TRACE_ID $STEP_ID $STEP_START 'Setup Test Matrix'
76
77   Spec:
78     name: "Spec Tests (Puppet: ${{matrix.puppet_version}}, Ruby Ver: ${{matrix.ruby_version}})"
79     needs:
80       - setup_matrix
81     if: ${{ needs.setup_matrix.outputs.spec_matrix != '{}' }}
82
83     runs-on: ubuntu-20.04
84     strategy:
85       fail-fast: false
86       matrix: ${{fromJson(needs.setup_matrix.outputs.spec_matrix)}}
87
88     env:
89       BUILDEVENT_FILE: '../buildevents.txt'
90       PUPPET_GEM_VERSION: ${{ matrix.puppet_version }}
91       FACTER_GEM_VERSION: 'https://github.com/puppetlabs/facter#main'
92
93     steps:
94       - run: |
95           echo "SANITIZED_PUPPET_VERSION=$(echo '${{ matrix.puppet_version }}' | sed 's/~> //g')" >> $GITHUB_ENV
96
97       - run: |
98           echo 'puppet_version=${{ env.SANITIZED_PUPPET_VERSION }}' >> $BUILDEVENT_FILE
99
100       - name: "Honeycomb: Start first step"
101         run: |
102           echo "STEP_ID=${{ env.SANITIZED_PUPPET_VERSION }}-spec" >> $GITHUB_ENV
103           echo STEP_START=$(date +%s) >> $GITHUB_ENV
104
105       - name: "Honeycomb: Start recording"
106         uses: puppetlabs/kvrhdn-gha-buildevents@pdk-templates-v1
107         with:
108           apikey: ${{ env.HONEYCOMB_WRITEKEY }}
109           dataset: ${{ env.HONEYCOMB_DATASET }}
110           job-status: ${{ job.status }}
111           matrix-key: ${{ env.SANITIZED_PUPPET_VERSION }}
112
113       - name: Checkout Source
114         uses: actions/checkout@v2
115
116       - name: "Activate Ruby ${{ matrix.ruby_version }}"
117         uses: ruby/setup-ruby@v1
118         with:
119           ruby-version: ${{matrix.ruby_version}}
120           bundler-cache: true
121
122       - name: Print bundle environment
123         run: |
124           echo ::group::bundler environment
125           buildevents cmd $TRACE_ID $STEP_ID 'bundle env' -- bundle env
126           echo ::endgroup::
127
128       - name: Run parallel_spec tests
129         run: |
130           buildevents cmd $TRACE_ID $STEP_ID 'rake parallel_spec Puppet ${{ matrix.puppet_version }}, Ruby ${{ matrix.ruby_version }}' -- bundle exec rake parallel_spec