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