PDK Update for GA workflows
[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: kvrhdn/gha-buildevents@v1.0.2
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=0 >> $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: actions/setup-ruby@v1
35       if: ${{ github.repository_owner == 'puppetlabs' }}
36       with:
37         ruby-version: "2.7"
38
39     - name: Cache gems
40       uses: actions/cache@v2
41       if: ${{ github.repository_owner == 'puppetlabs' }}
42       with:
43         path: vendor/gems
44         key: ${{ runner.os }}-${{ github.event_name }}-${{ hashFiles('**/Gemfile') }}
45         restore-keys: |
46           ${{ runner.os }}-${{ github.event_name }}-
47           ${{ runner.os }}-
48
49     - name: Install gems
50       if: ${{ github.repository_owner == 'puppetlabs' }}
51       run: |
52         buildevents cmd $TRACE_ID $STEP_ID 'bundle config path vendor/gems' -- bundle config path vendor/gems
53         buildevents cmd $TRACE_ID $STEP_ID 'bundle config jobs 8' -- bundle config jobs 8
54         buildevents cmd $TRACE_ID $STEP_ID 'bundle config retry 3' -- bundle config retry 3
55         buildevents cmd $TRACE_ID $STEP_ID 'bundle install' -- bundle install
56         buildevents cmd $TRACE_ID $STEP_ID 'bundle clean' -- bundle clean
57
58     - name: Setup Acceptance Test Matrix
59       id: get-matrix
60       if: ${{ github.repository_owner == 'puppetlabs' }}
61       run: |
62         if [ '${{ github.repository_owner }}' == 'puppetlabs' ]; then
63           buildevents cmd $TRACE_ID $STEP_ID matrix_from_metadata -- bundle exec matrix_from_metadata
64         else
65           echo  "::set-output name=matrix::{}"
66         fi
67
68     - name: "Honeycomb: Record setup time"
69       if: ${{ always() }}
70       run: |
71         buildevents step $TRACE_ID $STEP_ID $STEP_START 'Setup Test Matrix'
72
73   Acceptance:
74     needs:
75       - setup_matrix
76
77     runs-on: ubuntu-20.04
78     strategy:
79       fail-fast: false
80       matrix: ${{fromJson(needs.setup_matrix.outputs.matrix)}}
81
82     env:
83       BUILDEVENT_FILE: '../buildevents.txt'
84
85     steps:
86     - run: |
87         echo 'platform=${{ matrix.platform }}' >> $BUILDEVENT_FILE
88         echo 'collection=${{ matrix.collection }}' >> $BUILDEVENT_FILE
89
90     - name: "Honeycomb: Start recording"
91       uses: kvrhdn/gha-buildevents@v1.0.2
92       with:
93         apikey: ${{ env.HONEYCOMB_WRITEKEY }}
94         dataset: ${{ env.HONEYCOMB_DATASET }}
95         job-status: ${{ job.status }}
96         matrix-key: ${{ matrix.platform }}-${{ matrix.collection }}
97
98     - name: "Honeycomb: start first step"
99       run: |
100         echo STEP_ID=${{ matrix.platform }}-${{ matrix.collection }}-1 >> $GITHUB_ENV
101         echo STEP_START=$(date +%s) >> $GITHUB_ENV
102
103     - name: Checkout Source
104       uses: actions/checkout@v2
105
106     - name: Activate Ruby 2.7
107       uses: actions/setup-ruby@v1
108       with:
109         ruby-version: "2.7"
110
111     - name: Cache gems
112       uses: actions/cache@v2
113       with:
114         path: vendor/gems
115         key: ${{ runner.os }}-${{ github.event_name }}-${{ hashFiles('**/Gemfile') }}
116         restore-keys: |
117           ${{ runner.os }}-${{ github.event_name }}-
118           ${{ runner.os }}-
119
120     - name: "Honeycomb: Record cache setup time"
121       if: ${{ always() }}
122       run: |
123         buildevents step $TRACE_ID $STEP_ID $STEP_START 'Cache retrieval'
124         echo STEP_ID=${{ matrix.platform }}-${{ matrix.collection }}-2 >> $GITHUB_ENV
125         echo STEP_START=$(date +%s) >> $GITHUB_ENV
126
127     - name: Bundler Setup
128       run: |
129         buildevents cmd $TRACE_ID $STEP_ID 'bundle config path vendor/gems' -- bundle config path vendor/gems
130         buildevents cmd $TRACE_ID $STEP_ID 'bundle config jobs 8' -- bundle config jobs 8
131         buildevents cmd $TRACE_ID $STEP_ID 'bundle config retry 3' -- bundle config retry 3
132         buildevents cmd $TRACE_ID $STEP_ID 'bundle install' -- bundle install
133         buildevents cmd $TRACE_ID $STEP_ID 'bundle clean' -- bundle clean
134         echo ::group::bundler environment
135         buildevents cmd $TRACE_ID $STEP_ID 'bundle env' -- bundle env
136         echo ::endgroup::
137
138     - name: "Honeycomb: Record Bundler Setup time"
139       if: ${{ always() }}
140       run: |
141         buildevents step $TRACE_ID $STEP_ID $STEP_START 'Bundler Setup'
142         echo STEP_ID=${{ matrix.platform }}-${{ matrix.collection }}-3 >> $GITHUB_ENV
143         echo STEP_START=$(date +%s) >> $GITHUB_ENV
144
145     - name: Provision test environment
146       run: |
147         buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:provision ${{ matrix.platform }}' -- bundle exec rake 'litmus:provision[provision::provision_service,${{ matrix.platform }}]'
148         echo ::group::=== REQUEST ===
149         cat request.json || true
150         echo
151         echo ::endgroup::
152         echo ::group::=== INVENTORY ===
153         sed -e 's/password: .*/password: "[redacted]"/' < inventory.yaml || true
154         echo ::endgroup::
155
156     # The provision service hands out machines as soon as they're provisioned.
157     # The GCP VMs might still take a while to spool up and configure themselves fully.
158     # This retry loop spins until all agents have been installed successfully.
159     - name: Install agent
160       uses: nick-invision/retry@v1
161       with:
162         timeout_minutes: 30
163         max_attempts: 5
164         retry_wait_seconds: 60
165         command: buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:install_agent ${{ matrix.collection }}' -- bundle exec rake 'litmus:install_agent[${{ matrix.collection }}]'
166
167     # The agent installer on windows does not finish in time for this to work. To
168     # work around this for now, retry after a minute if installing the module failed.
169     - name: Install module
170       uses: nick-invision/retry@v1
171       with:
172         timeout_minutes: 30
173         max_attempts: 2
174         retry_wait_seconds: 60
175         command: buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:install_module' -- bundle exec rake 'litmus:install_module'
176
177     - name: "Honeycomb: Record deployment times"
178       if: ${{ always() }}
179       run: |
180         echo ::group::honeycomb step
181         buildevents step $TRACE_ID $STEP_ID $STEP_START 'Deploy test system'
182         echo STEP_ID=${{ matrix.platform }}-${{ matrix.collection }}-4 >> $GITHUB_ENV
183         echo STEP_START=$(date +%s) >> $GITHUB_ENV
184         echo ::endgroup::
185
186     - name: Run acceptance tests
187       run: |
188         buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:acceptance:parallel' -- bundle exec rake 'litmus:acceptance:parallel'
189
190     - name: "Honeycomb: Record acceptance testing times"
191       if: ${{ always() }}
192       run: |
193         buildevents step $TRACE_ID $STEP_ID $STEP_START 'Run acceptance tests'
194         echo STEP_ID=${{ matrix.platform }}-${{ matrix.collection }}-5 >> $GITHUB_ENV
195         echo STEP_START=$(date +%s) >> $GITHUB_ENV
196
197     - name: Remove test environment
198       if: ${{ always() }}
199       run: |
200         if [ -f inventory.yaml ]; then
201           buildevents cmd $TRACE_ID $STEP_ID 'rake litmus:tear_down' -- bundle exec rake 'litmus:tear_down'
202           echo ::group::=== REQUEST ===
203           cat request.json || true
204           echo
205           echo ::endgroup::
206         fi
207
208     - name: "Honeycomb: Record removal times"
209       if: ${{ always() }}
210       run: |
211         buildevents step $TRACE_ID $STEP_ID $STEP_START 'Remove test environment'