|
| 1 | +#/ |
| 2 | +# @license Apache-2.0 |
| 3 | +# |
| 4 | +# Copyright (c) 2022 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: deprecate_package |
| 21 | + |
| 22 | +# Workflow triggers: |
| 23 | +on: |
| 24 | + # Allow the workflow to be manually run: |
| 25 | + workflow_dispatch: |
| 26 | + inputs: |
| 27 | + packages: |
| 28 | + description: Space-separated list of packages to deprecate |
| 29 | + required: true |
| 30 | + message: |
| 31 | + description: Custom deprecation message |
| 32 | + |
| 33 | +# Workflow concurrency group: |
| 34 | +concurrency: |
| 35 | + |
| 36 | + # Specify a group name: |
| 37 | + group: ${{ github.workflow }} |
| 38 | + |
| 39 | + # Specify whether to cancel any currently running workflow in the same concurrency group: |
| 40 | + cancel-in-progress: false |
| 41 | + |
| 42 | +# Workflow jobs: |
| 43 | +jobs: |
| 44 | + |
| 45 | + # Define a job for deprecating packages... |
| 46 | + deprecate: |
| 47 | + |
| 48 | + # Define a display name: |
| 49 | + name: 'Deprecate' |
| 50 | + |
| 51 | + # Define the type of virtual host machine: |
| 52 | + runs-on: ubuntu-latest |
| 53 | + |
| 54 | + # Define the sequence of job steps... |
| 55 | + steps: |
| 56 | + # Deprecate the specified packages on `npm` and the respective `GitHub` repositories: |
| 57 | + - name: 'Deprecate packages' |
| 58 | + run: | |
| 59 | + pkgs=${{ github.event.inputs.packages }} |
| 60 | + npm_names="" |
| 61 | + github_repos="" |
| 62 | + for pkg in $pkgs; do |
| 63 | + # Replace `/` with `-`: |
| 64 | + pkg=$(echo $pkg | sed -e 's/\//-/g') |
| 65 | + if [[ $pkg == @* ]]; then |
| 66 | + npm_names+="$pkg " |
| 67 | + # Replace leading `@stdlib` with `stdlib-js` for GitHub repos: |
| 68 | + github_repos+="$(echo $pkg | sed 's/^@stdlib/stdlib-js/') " |
| 69 | + else |
| 70 | + npm_names+="@stdlib/$pkg " |
| 71 | + github_repos+="stdlib-js/$pkg " |
| 72 | + fi |
| 73 | + done |
| 74 | +
|
| 75 | + # Construct the deprecation message: |
| 76 | + msg="${{ github.event.inputs.message || 'Package no longer supported.' }}" |
| 77 | +
|
| 78 | + # Deprecate the packages on `npm`: |
| 79 | + for pkg in $npm_names; do |
| 80 | + echo "Deprecating $pkg..." |
| 81 | + npm deprecate $pkg $msg |
| 82 | + done |
| 83 | +
|
| 84 | + # Deprecate the packages on `GitHub` by adding a section to the `README.md` file: |
| 85 | + for repo in $github_repos; do |
| 86 | + echo "Deprecating $repo..." |
| 87 | + # Get the current contents of the `README.md` file: |
| 88 | + readme=$(curl -s https://raw.githubusercontent.com/$repo/master/README.md) |
| 89 | +
|
| 90 | + # Add the `msg` deprecation message to the `README.md` file in the `## Installation` section: |
| 91 | + readme=$(echo "$readme" | sed -e "s/## Installation/## Installation\n\n$msg/") |
| 92 | +
|
| 93 | + # Update the `README.md` file: |
| 94 | + curl -s -X PATCH -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/$repo/contents/README.md \ |
| 95 | + -d '{ |
| 96 | + "message": "Deprecated", |
| 97 | + "content": "'$(echo -n "$readme" | base64)'", |
| 98 | + "sha": "'$(echo -n "$readme" | base64 | awk '{print $2}')'" |
| 99 | + }' |
| 100 | + done |
0 commit comments