Merge pull request #1006 from puppetlabs/release-prep
[puppet-modules/puppetlabs-apt.git] / .github / workflows / pr_test.yml
1 name: "PR Testing"
2
3 on: [pull_request]
4
5 env:
6   HONEYCOMB_WRITEKEY: 7f3c63a70eecc61d635917de46bea4e6
7   HONEYCOMB_DATASET: litmus tests
8
9 jobs:
10   setup_matrix:
11     name: "Setup Test Matrix"
12     runs-on: ubuntu-20.04
13     outputs:
14       matrix: ${{ steps.get-matrix.outputs.matrix }}
15
16     steps:
17     - name: "Honeycomb: Start recording"
18       uses: puppetlabs/kvrhdn-gha-buildevents@pdk-templates-v1
19       with:
20         apikey: ${{ env.HONEYCOMB_WRITEKEY }}
21         dataset: ${{ env.HONEYCOMB_DATASET }}
22         job-status: ${{ job.status }}
23
24     - name: "Honeycomb: Start first step"
25       run: |
26         echo STEP_ID=setup-environment >> $GITHUB_ENV
27         echo STEP_START=$(date +%s) >> $GITHUB_ENV
28
29     - name: Checkout Source
30       uses: actions/checkout@v2
31       if: ${{ github.repository_owner == 'puppetlabs' }}
32
33     - name: Activate Ruby 2.7
34       uses: ruby/setup-ruby@v1
35       if: ${{ github.repository_owner == 'puppetlabs' }}
36       with:
37         ruby-version: "2.7"
38         bundler-cache: true
39
40     - name: Print bundle environment
41       if: ${{ github.repository_owner == 'puppetlabs' }}
42       run: |
43         echo ::group::bundler environment
44         buildevents cmd $TRACE_ID $STEP_ID 'bundle env' -- bundle env
45         echo ::endgroup::
46
47     - name: "Honeycomb: Record Setup Environment time"
48       if: ${{ github.repository_owner == 'puppetlabs' }}
49       run: |
50         buildevents step $TRACE_ID $STEP_ID $STEP_START 'Setup Environment'
51         echo STEP_ID=Setup-Acceptance-Test-Matrix >> $GITHUB_ENV
52         echo STEP_START=$(date +%s) >> $GITHUB_ENV
53
54     - name: Run validation steps
55       run: |
56         bundle exec rake validate
57       if: ${{ github.repository_owner == 'puppetlabs' }}
58
59     - name: Setup Acceptance Test Matrix
60       id: get-matrix
61       run: |
62         if [ '${{ github.repository_owner }}' == 'puppetlabs' ]; then
63           buildevents cmd $TRACE_ID $STEP_ID matrix_from_metadata -- bundle exec matrix_from_metadata_v2
64         else
65           echo  "::set-output name=matrix::{}"
66         fi
67
68     - name: "Honeycomb: Record Setup Test Matrix time"
69       if: ${{ always() }}
70       run: |
71         buildevents step $TRACE_ID $STEP_ID $STEP_START 'Setup Test Matrix'
72
73   Acceptance:
74     name: "${{matrix.platforms.label}}, ${{matrix.collection}}"
75     needs:
76       - setup_matrix
77     if: ${{ needs.setup_matrix.outputs.matrix != '{}' }}
78
79     runs-on: ubuntu-20.04
80     strategy:
81       fail-fast: false
82       matrix: ${{fromJson(needs.setup_matrix.outputs.matrix)}}
83
84     env:
85       BUILDEVENT_FILE: '../buildevents.txt'
86
87     steps:
88     - run: |
89         echo 'platform=${{ matrix.platforms.image }}' >> $BUILDEVENT_FILE
90         echo 'collection=${{ matrix.collection }}' >> $BUILDEVENT_FILE
91         echo 'label=${{ matrix.platforms.label }}' >> $BUILDEVENT_FILE
92
93     - name: "Honeycomb: Start recording"
94       uses: puppetlabs/kvrhdn-gha-buildevents@pdk-templates-v1
95       with:
96         apikey: ${{ env.HONEYCOMB_WRITEKEY }}
97         dataset: ${{ env.HONEYCOMB_DATASET }}
98         job-status: ${{ job.status }}
99         matrix-key: ${{ matrix.platforms.label }}-${{ matrix.collection }}
100
101     - name: "Honeycomb: start first step"
102       run: |
103         echo STEP_ID=${{ matrix.platforms.image }}-${{ matrix.collection }}-1 >> $GITHUB_ENV
104         echo STEP_START=$(date +%s) >> $GITHUB_ENV
105
106     - name: Checkout Source
107       uses: actions/checkout@v2
108
109     - name: Activate Ruby 2.7
110       uses: ruby/setup-ruby@v1
111       with:
112         ruby-version: "2.7"
113         bundler-cache: true
114
115     - name: Print bundle environment
116       run: |
117         echo ::group::bundler environment
118         buildevents cmd $TRACE_ID $STEP_ID 'bundle env' -- bundle env
119         echo ::endgroup::
120
121     - name: "Honeycomb: Record Setup Environment time"
122       if: ${{ always() }}
123       run: |
124         buildevents step $TRACE_ID $STEP_ID $STEP_START 'Setup Environment'
125         echo STEP_ID=${{ matrix.platforms.image }}-${{ matrix.collection }}-2 >> $GITHUB_ENV
126         echo STEP_START=$(date +%s) >> $GITHUB_ENV
127
128     - name: Provision test environment
129       run: |
130         buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:provision ${{ matrix.platforms.image }}' -- bundle exec rake 'litmus:provision[${{matrix.platforms.provider}},${{ matrix.platforms.image }}]'
131         echo ::group::=== REQUEST ===
132         cat request.json || true
133         echo
134         echo ::endgroup::
135         echo ::group::=== INVENTORY ===
136         if [ -f 'spec/fixtures/litmus_inventory.yaml' ];
137         then
138           FILE='spec/fixtures/litmus_inventory.yaml'
139         elif [ -f 'inventory.yaml' ];
140         then
141           FILE='inventory.yaml'
142         fi
143         sed -e 's/password: .*/password: "[redacted]"/' < $FILE || true
144         echo ::endgroup::
145
146     - name: Install agent
147       run: |
148         buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:install_agent ${{ matrix.collection }}' -- bundle exec rake 'litmus:install_agent[${{ matrix.collection }}]'
149
150     - name: Install module
151       run: |
152         buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:install_module' -- bundle exec rake 'litmus:install_module'
153
154     - name: "Honeycomb: Record deployment times"
155       if: ${{ always() }}
156       run: |
157         echo ::group::honeycomb step
158         buildevents step $TRACE_ID $STEP_ID $STEP_START 'Deploy test system'
159         echo STEP_ID=${{ matrix.platforms.image }}-${{ matrix.collection }}-3 >> $GITHUB_ENV
160         echo STEP_START=$(date +%s) >> $GITHUB_ENV
161         echo ::endgroup::
162
163     - name: Run acceptance tests
164       run: |
165         buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:acceptance:parallel' -- bundle exec rake 'litmus:acceptance:parallel'
166
167     - name: "Honeycomb: Record acceptance testing times"
168       if: ${{ always() }}
169       run: |
170         buildevents step $TRACE_ID $STEP_ID $STEP_START 'Run acceptance tests'
171         echo STEP_ID=${{ matrix.platforms.image }}-${{ matrix.collection }}-4 >> $GITHUB_ENV
172         echo STEP_START=$(date +%s) >> $GITHUB_ENV
173
174     - name: Remove test environment
175       if: ${{ always() }}
176       continue-on-error: true
177       run: |
178         if [[ -f inventory.yaml || -f spec/fixtures/litmus_inventory.yaml ]]; then
179           buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:tear_down' -- bundle exec rake 'litmus:tear_down'
180           echo ::group::=== REQUEST ===
181           cat request.json || true
182           echo
183           echo ::endgroup::
184         fi
185
186     - name: "Honeycomb: Record removal times"
187       if: ${{ always() }}
188       run: |
189         buildevents step $TRACE_ID $STEP_ID $STEP_START 'Remove test environment'