|
| 1 | +#/ |
| 2 | +# @license Apache-2.0 |
| 3 | +# |
| 4 | +# Copyright (c) 2023 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: update_error_databases |
| 21 | + |
| 22 | +# Workflow triggers: |
| 23 | +on: |
| 24 | + schedule: |
| 25 | + # Run the workflow once a week (Sunday at midnight): |
| 26 | + - cron: '0 0 * * 0' |
| 27 | + |
| 28 | + # Allow the workflow to be manually run: |
| 29 | + workflow_dispatch: |
| 30 | + |
| 31 | +# Workflow jobs: |
| 32 | +jobs: |
| 33 | + |
| 34 | + # Define a job for updating the error databases: |
| 35 | + update: |
| 36 | + |
| 37 | + # Define a display name: |
| 38 | + name: 'Update Error Databases' |
| 39 | + |
| 40 | + # Define the type of virtual host machine: |
| 41 | + runs-on: ubuntu-latest |
| 42 | + |
| 43 | + # Define the sequence of job steps... |
| 44 | + steps: |
| 45 | + |
| 46 | + # Checkout the repository: |
| 47 | + - name: 'Checkout repository' |
| 48 | + uses: actions/checkout@v3 |
| 49 | + with: |
| 50 | + # Specify whether to remove untracked files before checking out the repository: |
| 51 | + clean: true |
| 52 | + |
| 53 | + # Limit clone depth to the most recent commit: |
| 54 | + fetch-depth: 1 |
| 55 | + |
| 56 | + # Specify whether to download Git-LFS files: |
| 57 | + lfs: false |
| 58 | + timeout-minutes: 10 |
| 59 | + |
| 60 | + # Install Node.js: |
| 61 | + - name: 'Install Node.js' |
| 62 | + uses: actions/setup-node@v3 |
| 63 | + with: |
| 64 | + node-version: '16' # 'lts/*' |
| 65 | + timeout-minutes: 5 |
| 66 | + |
| 67 | + # Install dependencies (accounting for possible network failures, etc, when installing node module dependencies): |
| 68 | + - name: 'Install dependencies' |
| 69 | + run: | |
| 70 | + make install-node-modules || make install-node-modules || make install-node-modules |
| 71 | + timeout-minutes: 15 |
| 72 | + |
| 73 | + # Update the error databases: |
| 74 | + - name: 'Update error databases' |
| 75 | + run: | |
| 76 | + node lib/node_modules/@stdlib/error/tools/database/scripts/build.js |
| 77 | + node lib/node_modules/@stdlib/error/tools/pkg2id/scripts/build.js |
| 78 | + node lib/node_modules/@stdlib/error/tools/id2pkg/scripts/build.js |
| 79 | + |
| 80 | + # Generate comment with Markdown table of added error codes: |
| 81 | + - name: 'Generate comment body with Markdown table of added error codes' |
| 82 | + run: | |
| 83 | + # Save the added lines from the diff to a temporary file: |
| 84 | + git diff lib/node_modules/@stdlib/error/tools/database/data/data.csv | grep '^+' | sed 's/^+//' > /tmp/diff.csv |
| 85 | + |
| 86 | + # Convert the CSV file to a TSV file (and drop first line and double quotes): |
| 87 | + awk -F '",' 'NR > 1 && !/^++/ { gsub(/^"|"$/, "", $1); gsub(/^"|"$/, "", $2); gsub(/^"|"$/, "", $3); print $1 "\t" $2 "\t" $3 }' /tmp/diff.csv > /tmp/diff.tsv |
| 88 | +
|
| 89 | + # Create the Markdown table header: |
| 90 | + table="| Code | Error Message | Type |\n|------|---------------|------|\n" |
| 91 | +
|
| 92 | + # Extract added lines from the diff and append them to the Markdown table: |
| 93 | + while IFS=$'\t' read -r code error_message type; do |
| 94 | + # Check if the table length exceeds a maximum length: |
| 95 | + if [ ${#table} -gt 65000 ]; then |
| 96 | + table+="| ... | ... | ... |\nThis table has been truncated due to GitHub's comment character limit.\n" |
| 97 | + break |
| 98 | + fi |
| 99 | + |
| 100 | + # Append the TSV row to the Markdown table: |
| 101 | + table+="| ${code} | ${error_message} | ${type} |\n" |
| 102 | + done < /tmp/diff.tsv |
| 103 | +
|
| 104 | + # Generate a comment body: |
| 105 | + body="This PR\n\n- updates the error databases\n\nThe following error codes were added:\n\n${table}" |
| 106 | + |
| 107 | + # Escape '%' characters, which are interpreted as format specifiers by `printf`: |
| 108 | + body="${body//%/%%}" |
| 109 | + |
| 110 | + # Write the comment body to a temporary file: |
| 111 | + printf "$body" > /tmp/body.md |
| 112 | + shell: bash |
| 113 | + |
| 114 | + # Disable Git hooks: |
| 115 | + - name: 'Disable Git hooks' |
| 116 | + run: | |
| 117 | + rm -rf .git/hooks |
| 118 | +
|
| 119 | + # Create a pull request with the updated declarations: |
| 120 | + - name: 'Create pull request' |
| 121 | + id: cpr |
| 122 | + uses: peter-evans/create-pull-request@v5 |
| 123 | + with: |
| 124 | + title: 'feat: update error databases' |
| 125 | + body-path: /tmp/body.md |
| 126 | + commit-message: 'feat: update error databases' |
| 127 | + committer: 'stdlib-bot <noreply@stdlib.io>' |
| 128 | + token: ${{ secrets.PULL_REQUEST_TOKEN }} |
| 129 | + labels: | |
| 130 | + documentation |
| 131 | + automated-pr |
| 132 | + team-reviewers: | |
| 133 | + reviewers |
| 134 | + branch: update-error-databases |
| 135 | + delete-branch: true |
0 commit comments