(MAINT) 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         sed -e 's/password: .*/password: "[redacted]"/' < inventory.yaml || true
132         echo ::endgroup::
133
134     - name: Install agent
135       run: |
136         buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:install_agent ${{ matrix.collection }}' -- bundle exec rake 'litmus:install_agent[${{ matrix.collection }}]'
137
138     - name: Install module
139       run: |
140         buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:install_module' -- bundle exec rake 'litmus:install_module'
141
142     - name: "Honeycomb: Record deployment times"
143       if: ${{ always() }}
144       run: |
145         echo ::group::honeycomb step
146         buildevents step $TRACE_ID $STEP_ID $STEP_START 'Deploy test system'
147         echo STEP_ID=${{ matrix.platforms.image }}-${{ matrix.collection }}-3 >> $GITHUB_ENV
148         echo STEP_START=$(date +%s) >> $GITHUB_ENV
149         echo ::endgroup::
150
151     - name: Run acceptance tests
152       run: |
153         buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:acceptance:parallel' -- bundle exec rake 'litmus:acceptance:parallel'
154
155     - name: "Honeycomb: Record acceptance testing times"
156       if: ${{ always() }}
157       run: |
158         buildevents step $TRACE_ID $STEP_ID $STEP_START 'Run acceptance tests'
159         echo STEP_ID=${{ matrix.platforms.image }}-${{ matrix.collection }}-4 >> $GITHUB_ENV
160         echo STEP_START=$(date +%s) >> $GITHUB_ENV
161
162     - name: Remove test environment
163       if: ${{ always() }}
164       continue-on-error: true
165       run: |
166         if [ -f inventory.yaml ]; then
167           buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:tear_down' -- bundle exec rake 'litmus:tear_down'
168           echo ::group::=== REQUEST ===
169           cat request.json || true
170           echo
171           echo ::endgroup::
172         fi
173
174     - name: "Honeycomb: Record removal times"
175       if: ${{ always() }}
176       run: |
177         buildevents step $TRACE_ID $STEP_ID $STEP_START 'Remove test environment'