|
8 | 8 | # the jobs run only close to business hours of Central Time. |
9 | 9 | # Days were chosen to run only from Monday through Friday. |
10 | 10 | - cron: '45 13,17,21 * * 1,2,3,4,5' |
11 | | -jobs: |
12 | | - production-heartbeat: |
13 | | - strategy: |
14 | | - # By default, if any job in a matrix fails, all other jobs are immediately cancelled. This makes the jobs run to completion instead. |
15 | | - fail-fast: false |
16 | | - matrix: |
17 | | - os: [{vm: ubuntu-latest, exe: .sh}, {vm: windows-2019, exe: .cmd}] |
18 | | - node: ['lts/*'] |
19 | | - runs-on: ${{ matrix.os.vm }} |
20 | | - timeout-minutes: 60 |
21 | | - steps: |
22 | | - # === Setup. We need to get the code, set up nodejs, and create the results directory. === |
23 | | - - uses: actions/checkout@v4 |
24 | | - with: |
25 | | - ref: 'release' |
26 | | - - uses: actions/setup-node@v4 |
27 | | - with: |
28 | | - node-version: ${{ matrix.node }} |
29 | | - - uses: actions/setup-java@v4 |
30 | | - with: |
31 | | - distribution: 'temurin' |
32 | | - java-version: '11' |
33 | | - - run: mkdir smoke-test-results |
34 | | - |
35 | | - # === Set our environment variables, either using default values or the repo's secrets === |
36 | | - - name: Set environment variables |
37 | | - id: env_var_setup |
38 | | - # We'll want to use bash for this, to avoid any cross-platform shenanigans |
39 | | - shell: bash |
40 | | - run: | |
41 | | - # In the following script, the use of the `echo "name=value" >> $GITHUB_ENV` structure is used to set/update |
42 | | - # environment variables. Such updates are visible to all subsequent steps. |
43 | | - # |
44 | | - # If the CLI_VERSION repo secret is set, we want to install that version ofsf-cli, so we set an environment |
45 | | - # variable. Otherwise, we leave the environment variable unset, so it implicitly defaults to `latest`. |
46 | | - # Note: This can be used to intentionally fail the GHA by providing an invalid version number. |
47 | | - if [[ -n "${{ secrets.CLI_VERSION }}" ]]; then |
48 | | - echo "CLI_VERSION=@${{ secrets.CLI_VERSION}}" >> $GITHUB_ENV |
49 | | - fi |
50 | | - # If the SCANNER_VERSION repo secret is set, we want to install that version of sfdx-scanner, so we set an |
51 | | - # environment variable. Otherwise, we leave the environment variable unset, so it implicitly defaults to `latest`. |
52 | | - # Note: This can be used to intentionally fail the GHA by providing an invalid version number. |
53 | | - if [[ -n "${{ secrets.SCANNER_VERSION }}" ]]; then |
54 | | - echo "SCANNER_VERSION=@${{ secrets.SCANNER_VERSION }}" >> $GITHUB_ENV |
55 | | - fi |
56 | | - # If the FAIL_SMOKE_TESTS repo secret is set to ANY value, we should respond by deleting the `test/test-jars` |
57 | | - # folder. The smoke tests expect this folder's contents to exist, so an invocation of `scanner:rule:add` should |
58 | | - # fail, thereby failing the smoke tests as a whole. |
59 | | - # Note: This serves no purpose aside from providing a way to simulate a smoke test failure. |
60 | | - if [[ -n "${{ secrets.FAIL_SMOKE_TESTS }}" ]]; then |
61 | | - rm -rf ./test/test-jars |
62 | | - fi |
63 | | -
|
64 | | -
|
65 | | - # === Make three attempts to install SF through npm === |
66 | | - - name: Install SF |
67 | | - id: sf_install |
68 | | - # If the first attempt fails, wait a minute and try again. After a second failure, wait 5 minutes then try again. Then give up. |
69 | | - # Set an output parameter, `retry_count`, indicating the number of retry attempts that were made. |
70 | | - run: | |
71 | | - (echo "::set-output name=retry_count::0" && npm install -g @salesforce/cli${{ env.CLI_VERSION }}) || |
72 | | - (echo "::set-output name=retry_count::1" && sleep 60 && npm install -g @salesforce/cli${{ env.CLI_VERSION }}) || |
73 | | - (echo "::set-output name=retry_count::2" && sleep 300 && npm install -g @salesforce/cli${{ env.CLI_VERSION }}) |
74 | | -
|
75 | | - # === Make three attempts to install the scanner plugin through sf === |
76 | | - - name: Install Scanner Plugin |
77 | | - id: scanner_install |
78 | | - # If the first attempt fails, wait a minute and try again. After a second failure, wait 5 minutes then try again. Then give up. |
79 | | - # Set an output parameter, `retry_count`, indicating the number of retry attempts that were made. |
80 | | - run: | |
81 | | - (echo "::set-output name=retry_count::0" && sf plugins install @salesforce/sfdx-scanner${{ env.SCANNER_VERSION }}) || |
82 | | - (echo "::set-output name=retry_count::1" && sleep 60 && sf plugins install @salesforce/sfdx-scanner${{ env.SCANNER_VERSION }}) || |
83 | | - (echo "::set-output name=retry_count::2" && sleep 300 && sf plugins install @salesforce/sfdx-scanner${{ env.SCANNER_VERSION }}) |
84 | 11 |
|
85 | | - # === Log the installed plugins for easier debugging === |
86 | | - - name: Log plugins |
87 | | - run: sf plugins |
88 | | - |
89 | | - # === Attempt to execute the smoke tests === |
90 | | - - name: Run smoke tests |
91 | | - id: smoke_tests |
92 | | - run: smoke-tests/smoke-test${{ matrix.os.exe }} sf |
93 | | - |
94 | | - # === Upload the smoke-test-results folder as an artifact === |
95 | | - - name: Upload smoke-test-results folder as artifact |
96 | | - if: ${{ always() }} |
97 | | - uses: actions/upload-artifact@v4 |
98 | | - with: |
99 | | - name: smoke-test-results-${{ runner.os }} |
100 | | - path: smoke-test-results |
101 | | - |
102 | | - # === Report any problems === |
103 | | - - name: Report problems |
104 | | - # There are problems if any step failed or was skipped. |
105 | | - # Note that the `join()` call omits null values, so if any steps were skipped, they won't have a corresponding |
106 | | - # value in the string. |
107 | | - if: ${{ failure() || cancelled() }} |
108 | | - shell: bash |
109 | | - env: |
110 | | - # If we're here because steps failed or were skipped, then that's a critical problem. Otherwise it's a normal one. |
111 | | - # We can't use the `failure()` or `cancelled()` convenience methods outside of the `if` condition, hence the |
112 | | - # `contains()` calls. |
113 | | - IS_CRITICAL: ${{ contains(join(steps.*.outcome), 'failure') || contains(join(steps.*.outcome), 'skipped') }} |
114 | | - # Build the status strings for each step as environment variables to save space later. Null retry_count values |
115 | | - # will be replaced with `n/a` to maintain readability in the alert. |
116 | | - CLI_INSTALL_STATUS: ${{ steps.sf_install.outcome }} after ${{ steps.sf_install.outputs.retry_count || 'n/a' }} retries |
117 | | - SCANNER_INSTALL_STATUS: ${{ steps.scanner_install.outcome }} after ${{ steps.scanner_install.outputs.retry_count || 'n/a' }} retries |
118 | | - SMOKE_TESTS_STATUS: ${{ steps.smoke_tests.outcome }} |
119 | | - # A link to this run, so the PagerDuty assignee can quickly get here. |
120 | | - RUN_LINK: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} |
121 | | - run: | |
122 | | - # GHA env-vars don't have robust conditional logic, so we'll use this if-else branch to define some bash env-vars. |
123 | | - if [[ ${{ env.IS_CRITICAL }} == true ]]; then |
124 | | - ALERT_SEV="critical" |
125 | | - ALERT_SUMMARY="Production heartbeat script failed on ${{ runner.os }}" |
126 | | - else |
127 | | - ALERT_SEV="info" |
128 | | - ALERT_SUMMARY="Production heartbeat script succeeded with retries on ${{ runner.os }}" |
129 | | - fi |
130 | | - # Define a helper function to create our POST request's data, to sidestep issues with nested quotations. |
131 | | - generate_post_data() { |
132 | | - # This is known as a HereDoc, and it lets us declare multi-line input ending when the specified limit string, |
133 | | - # in this case EOF, is encountered. |
134 | | - cat <<EOF |
135 | | - {"payload": { |
136 | | - "summary": "${ALERT_SUMMARY}", |
137 | | - "source": "Github Actions", |
138 | | - "severity": "${ALERT_SEV}", |
139 | | - "custom_details": "SF install: ${{ env.CLI_INSTALL_STATUS }}. Scanner install: ${{ env.SCANNER_INSTALL_STATUS }}. Smoke tests: ${{ env.SMOKE_TESTS_STATUS }}." |
140 | | - }, |
141 | | - "links": [{ |
142 | | - "href": "${{ env.RUN_LINK }}", |
143 | | - "text": "Link to action execution" |
144 | | - }], |
145 | | - "event_action": "trigger", |
146 | | - "dedup_key": "GH-HB-${{ matrix.os.vm }}-${{ matrix.node }}", |
147 | | - "routing_key": "${{ secrets.PAGERDUTY_HEARTBEAT_KEY }}" |
148 | | - } |
149 | | - EOF |
150 | | - } |
151 | | - # Make our POST request |
152 | | - curl --request POST --data "$(generate_post_data)" https://events.pagerduty.com/v2/enqueue |
| 12 | +jobs: |
| 13 | + invoke-heartbeat-v4: |
| 14 | + uses: ./.github/workflows/heartbeat-v4.yml |
0 commit comments