Merge pull request #986 from puppetlabs/pdksync_pdk_update
[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: Setup Acceptance Test Matrix
55       id: get-matrix
56       run: |
57         if [ '${{ github.repository_owner }}' == 'puppetlabs' ]; then
58           buildevents cmd $TRACE_ID $STEP_ID matrix_from_metadata -- bundle exec matrix_from_metadata_v2
59         else
60           echo  "::set-output name=matrix::{}"
61         fi
62
63     - name: "Honeycomb: Record Setup Test Matrix time"
64       if: ${{ always() }}
65       run: |
66         buildevents step $TRACE_ID $STEP_ID $STEP_START 'Setup Test Matrix'
67
68   Acceptance:
69     name: "${{matrix.platforms.label}}, ${{matrix.collection}}"
70     needs:
71       - setup_matrix
72     if: ${{ needs.setup_matrix.outputs.matrix != '{}' }}
73
74     runs-on: ubuntu-20.04
75     strategy:
76       fail-fast: false
77       matrix: ${{fromJson(needs.setup_matrix.outputs.matrix)}}
78
79     env:
80       BUILDEVENT_FILE: '../buildevents.txt'
81
82     steps:
83     - run: |
84         echo 'platform=${{ matrix.platforms.image }}' >> $BUILDEVENT_FILE
85         echo 'collection=${{ matrix.collection }}' >> $BUILDEVENT_FILE
86         echo 'label=${{ matrix.platforms.label }}' >> $BUILDEVENT_FILE
87
88     - name: "Honeycomb: Start recording"
89       uses: puppetlabs/kvrhdn-gha-buildevents@pdk-templates-v1
90       with:
91         apikey: ${{ env.HONEYCOMB_WRITEKEY }}
92         dataset: ${{ env.HONEYCOMB_DATASET }}
93         job-status: ${{ job.status }}
94         matrix-key: ${{ matrix.platforms.label }}-${{ matrix.collection }}
95
96     - name: "Honeycomb: start first step"
97       run: |
98         echo STEP_ID=${{ matrix.platforms.image }}-${{ matrix.collection }}-1 >> $GITHUB_ENV
99         echo STEP_START=$(date +%s) >> $GITHUB_ENV
100
101     - name: Checkout Source
102       uses: actions/checkout@v2
103
104     - name: Activate Ruby 2.7
105       uses: ruby/setup-ruby@v1
106       with:
107         ruby-version: "2.7"
108         bundler-cache: true
109
110     - name: Print bundle environment
111       run: |
112         echo ::group::bundler environment
113         buildevents cmd $TRACE_ID $STEP_ID 'bundle env' -- bundle env
114         echo ::endgroup::
115
116     - name: "Honeycomb: Record Setup Environment time"
117       if: ${{ always() }}
118       run: |
119         buildevents step $TRACE_ID $STEP_ID $STEP_START 'Setup Environment'
120         echo STEP_ID=${{ matrix.platforms.image }}-${{ matrix.collection }}-2 >> $GITHUB_ENV
121         echo STEP_START=$(date +%s) >> $GITHUB_ENV
122
123     - name: Provision test environment
124       run: |
125         buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:provision ${{ matrix.platforms.image }}' -- bundle exec rake 'litmus:provision[${{matrix.platforms.provider}},${{ matrix.platforms.image }}]'
126         echo ::group::=== REQUEST ===
127         cat request.json || true
128         echo
129         echo ::endgroup::
130         echo ::group::=== INVENTORY ===
131         if [ -f 'spec/fixtures/litmus_inventory.yaml' ];
132         then
133           FILE='spec/fixtures/litmus_inventory.yaml'
134         elif [ -f 'inventory.yaml' ];
135         then
136           FILE='inventory.yaml'
137         fi
138         sed -e 's/password: .*/password: "[redacted]"/' < $FILE || true
139         echo ::endgroup::
140
141     - name: Install agent
142       run: |
143         buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:install_agent ${{ matrix.collection }}' -- bundle exec rake 'litmus:install_agent[${{ matrix.collection }}]'
144
145     - name: Install module
146       run: |
147         buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:install_module' -- bundle exec rake 'litmus:install_module'
148
149     - name: "Honeycomb: Record deployment times"
150       if: ${{ always() }}
151       run: |
152         echo ::group::honeycomb step
153         buildevents step $TRACE_ID $STEP_ID $STEP_START 'Deploy test system'
154         echo STEP_ID=${{ matrix.platforms.image }}-${{ matrix.collection }}-3 >> $GITHUB_ENV
155         echo STEP_START=$(date +%s) >> $GITHUB_ENV
156         echo ::endgroup::
157
158     - name: Run acceptance tests
159       run: |
160         buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:acceptance:parallel' -- bundle exec rake 'litmus:acceptance:parallel'
161
162     - name: "Honeycomb: Record acceptance testing times"
163       if: ${{ always() }}
164       run: |
165         buildevents step $TRACE_ID $STEP_ID $STEP_START 'Run acceptance tests'
166         echo STEP_ID=${{ matrix.platforms.image }}-${{ matrix.collection }}-4 >> $GITHUB_ENV
167         echo STEP_START=$(date +%s) >> $GITHUB_ENV
168
169     - name: Remove test environment
170       if: ${{ always() }}
171       continue-on-error: true
172       run: |
173         if [[ -f inventory.yaml || -f spec/fixtures/litmus_inventory.yaml ]]; then
174           buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:tear_down' -- bundle exec rake 'litmus:tear_down'
175           echo ::group::=== REQUEST ===
176           cat request.json || true
177           echo
178           echo ::endgroup::
179         fi
180
181     - name: "Honeycomb: Record removal times"
182       if: ${{ always() }}
183       run: |
184         buildevents step $TRACE_ID $STEP_ID $STEP_START 'Remove test environment'