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