|
| 1 | +#/ |
| 2 | +# @license Apache-2.0 |
| 3 | +# |
| 4 | +# Copyright (c) 2021 The Stdlib Authors. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +#/ |
| 18 | + |
| 19 | +# Workflow name: |
| 20 | +name: markdown_src_attributes |
| 21 | + |
| 22 | +# Workflow triggers: |
| 23 | +on: |
| 24 | + schedule: |
| 25 | + # Run the workflow once a month on the 1st day of every month: |
| 26 | + - cron: "0 0 1 * *" |
| 27 | + |
| 28 | + # Allow the workflow to be manually run: |
| 29 | + workflow_dispatch: |
| 30 | + |
| 31 | +# Workflow jobs: |
| 32 | +jobs: |
| 33 | + |
| 34 | + # Define a job for detecting broken `src` in Markdown files... |
| 35 | + markdown_src_attributes: |
| 36 | + |
| 37 | + # Define a display name: |
| 38 | + name: 'Check `src` attribute URLs' |
| 39 | + |
| 40 | + # Define the type of virtual host machine: |
| 41 | + runs-on: ubuntu-latest |
| 42 | + |
| 43 | + # Define environment variables: |
| 44 | + env: |
| 45 | + LOG_DIR: "${{ github.workspace }}/tmp/var/log" |
| 46 | + LOG_FILE_FAILURES: "${{ github.workspace }}/tmp/var/log/failures.json" |
| 47 | + LOG_FILE_WARNINGS: "${{ github.workspace }}/tmp/var/log/warnings.json" |
| 48 | + |
| 49 | + # Set defaults: |
| 50 | + defaults: |
| 51 | + run: |
| 52 | + # Set the default shell to `bash`: |
| 53 | + shell: bash --noprofile --norc -eo pipefail {0} |
| 54 | + |
| 55 | + # Define the sequence of job steps... |
| 56 | + steps: |
| 57 | + |
| 58 | + # Checkout the repository: |
| 59 | + - name: 'Checkout repository' |
| 60 | + uses: actions/checkout@v2 |
| 61 | + with: |
| 62 | + # Specify whether to remove untracked files before checking out the repository: |
| 63 | + clean: true |
| 64 | + |
| 65 | + # Limit clone depth to the most recent commit: |
| 66 | + fetch-depth: 1 |
| 67 | + |
| 68 | + # Specify whether to download Git-LFS files: |
| 69 | + lfs: false |
| 70 | + timeout-minutes: 10 |
| 71 | + |
| 72 | + # Initialize log files: |
| 73 | + - name: 'Initialize log files' |
| 74 | + run: | |
| 75 | + mkdir -p "${{ env.LOG_DIR }}" |
| 76 | + touch "${{ env.LOG_FILE_FAILURES }}" |
| 77 | + touch "${{ env.LOG_FILE_WARNINGS }}" |
| 78 | + timeout-minutes: 2 |
| 79 | + |
| 80 | + # Check for broken `src` attribute URLs: |
| 81 | + - name: 'Check `src` attribute URLs' |
| 82 | + uses: stdlib-js/broken-markdown-src-action@main |
| 83 | + id: results |
| 84 | + with: |
| 85 | + exclude: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules |
| 86 | + timeout-minutes: 120 |
| 87 | + |
| 88 | + # Log the results: |
| 89 | + - name: 'Log results' |
| 90 | + run: | |
| 91 | + echo ${{ steps.results.outputs.failures }} >> "${{ env.LOG_FILE_FAILURES }}" |
| 92 | + echo ${{ steps.results.outputs.warnings }} >> "${{ env.LOG_FILE_WARNINGS }}" |
| 93 | + timeout-minutes: 2 |
| 94 | + |
| 95 | + # Fail the workflow if the status is not "success": |
| 96 | + - name: 'Check status' |
| 97 | + if: ${{ steps.results.outputs.status }} != 'success' |
| 98 | + run: | |
| 99 | + exit 1 |
| 100 | +
|
| 101 | + # View the log file if the previous step fails: |
| 102 | + - name: 'View log file' |
| 103 | + if: failure() |
| 104 | + run: | |
| 105 | + echo "Printing the list of failures..." |
| 106 | + cat "${{ env.LOG_FILE_FAILURES }}" |
| 107 | + timeout-minutes: 5 |
| 108 | + |
| 109 | + # Upload the log files: |
| 110 | + - name: 'Upload log files' |
| 111 | + uses: actions/upload-artifact@v2 |
| 112 | + if: always() |
| 113 | + with: |
| 114 | + # Define a name for the uploaded artifact: |
| 115 | + name: results |
| 116 | + |
| 117 | + # Specify the paths to upload: |
| 118 | + path: | |
| 119 | + ${{ env.LOG_FILE_FAILURES }} |
| 120 | + ${{ env.LOG_FILE_WARNINGS }} |
| 121 | +
|
| 122 | + # Specify the number of days to retain the artifact (default is 90 days): |
| 123 | + retention-days: 10 |
| 124 | + timeout-minutes: 10 |
| 125 | + |
| 126 | + # Define a job for sending notifications to Slack... |
| 127 | + slack: |
| 128 | + |
| 129 | + # Define a display name: |
| 130 | + name: 'Slack notification' |
| 131 | + |
| 132 | + # Define the type of virtual host machine: |
| 133 | + runs-on: 'ubuntu-latest' |
| 134 | + |
| 135 | + # Indicate that this job depends on the prior job finishing: |
| 136 | + needs: markdown_src_attributes |
| 137 | + |
| 138 | + # Run this job regardless of the outcome of the prior job: |
| 139 | + if: always() |
| 140 | + |
| 141 | + # Set defaults: |
| 142 | + defaults: |
| 143 | + run: |
| 144 | + # Set the default shell to `bash`: |
| 145 | + shell: bash --noprofile --norc -eo pipefail {0} |
| 146 | + |
| 147 | + # Define the sequence of job steps... |
| 148 | + steps: |
| 149 | + |
| 150 | + # Resolve notification data: |
| 151 | + - name: 'Resolve notification data' |
| 152 | + run: | |
| 153 | + echo 'NOTIFICATION_STATUS=${{ needs.markdown_src_attributes.result}}' >> $GITHUB_ENV |
| 154 | + if [[ "${{ needs.markdown_src_attributes.result }}" = "success" ]]; then |
| 155 | + echo 'NOTIFICATION_TEXT=**markdown_src_attributes** workflow succeeded' >> $GITHUB_ENV |
| 156 | + echo 'NOTIFICATION_AUTHOR_NAME=Success' >> $GITHUB_ENV |
| 157 | + elif [[ "${{ needs.markdown_src_attributes.result }}" = "failure" ]]; then |
| 158 | + echo 'NOTIFICATION_TEXT=**markdown_src_attributes** workflow failed' >> $GITHUB_ENV |
| 159 | + echo 'NOTIFICATION_AUTHOR_NAME=Failure' >> $GITHUB_ENV |
| 160 | + elif [[ "${{ needs.markdown_src_attributes.result }}" = "cancelled" ]]; then |
| 161 | + echo 'NOTIFICATION_TEXT=**markdown_src_attributes** workflow was canceled' >> $GITHUB_ENV |
| 162 | + echo 'NOTIFICATION_AUTHOR_NAME=Canceled' >> $GITHUB_ENV |
| 163 | + else |
| 164 | + exit 1 |
| 165 | + fi |
| 166 | + timeout-minutes: 5 |
| 167 | + |
| 168 | + # Send notification to Slack: |
| 169 | + - name: 'Send notification' |
| 170 | + uses: 8398a7/action-slack@v3 |
| 171 | + if: success() |
| 172 | + with: |
| 173 | + status: "${{ env.NOTIFICATION_STATUS }}" |
| 174 | + fields: repo,commit,message |
| 175 | + text: "${{ env.NOTIFICATION_TEXT }}" |
| 176 | + author_name: "${{ env.NOTIFICATION_AUTHOR_NAME }}" |
| 177 | + env: |
| 178 | + SLACK_WEBHOOK_URL: ${{ secrets.REPO_SLACK_WEBHOOK_URL }} |
| 179 | + timeout-minutes: 5 |
0 commit comments