| 
 | 1 | +#/  | 
 | 2 | +# @license Apache-2.0  | 
 | 3 | +#  | 
 | 4 | +# Copyright (c) 2024 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: test_published_package  | 
 | 21 | + | 
 | 22 | +# Workflow triggers:  | 
 | 23 | +on:  | 
 | 24 | +  # Run workflow on a weekly schedule:  | 
 | 25 | +  schedule:  | 
 | 26 | +    # * is a special character in YAML so you have to quote this string  | 
 | 27 | +    - cron:  '46 10 * * 1'  | 
 | 28 | + | 
 | 29 | +  # Run workflow upon completion of `publish` workflow run:  | 
 | 30 | +  workflow_run:  | 
 | 31 | +    workflows: ["publish"]  | 
 | 32 | +    types: [completed]  | 
 | 33 | + | 
 | 34 | +  # Allow workflow to be manually run:  | 
 | 35 | +  workflow_dispatch:  | 
 | 36 | + | 
 | 37 | +# Workflow jobs:  | 
 | 38 | +jobs:  | 
 | 39 | +  test-published:  | 
 | 40 | +    # Define a display name:  | 
 | 41 | +    name: 'Test running examples of published package'  | 
 | 42 | + | 
 | 43 | +    # Define the type of virtual host machine:  | 
 | 44 | +    runs-on: ubuntu-latest  | 
 | 45 | + | 
 | 46 | +    # Define environment variables:  | 
 | 47 | +    env:  | 
 | 48 | +      SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}  | 
 | 49 | + | 
 | 50 | +    # Run workflow job if `publish` workflow run is successful or when the workflow is manually run:  | 
 | 51 | +    if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}  | 
 | 52 | + | 
 | 53 | +    # Define the job's steps:  | 
 | 54 | +    steps:  | 
 | 55 | +      # Checkout the repository:  | 
 | 56 | +      - name: 'Checkout repository'  | 
 | 57 | +        uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0  | 
 | 58 | + | 
 | 59 | +      # Install Node.js:  | 
 | 60 | +      - name: 'Install Node.js'  | 
 | 61 | +        uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1  | 
 | 62 | +        with:  | 
 | 63 | +          node-version: 20  | 
 | 64 | +        timeout-minutes: 5  | 
 | 65 | + | 
 | 66 | +      # Create test directory and run examples:  | 
 | 67 | +      - name: 'Create test directory and run examples'  | 
 | 68 | +        run: |  | 
 | 69 | +          cd ..  | 
 | 70 | +          mkdir test-published  | 
 | 71 | +          cd test-published  | 
 | 72 | +
  | 
 | 73 | +          # Copy example file:  | 
 | 74 | +          cp $GITHUB_WORKSPACE/examples/index.js .  | 
 | 75 | +
  | 
 | 76 | +          # Create a minimal package.json  | 
 | 77 | +          echo '{  | 
 | 78 | +            "name": "test-published",  | 
 | 79 | +            "version": "1.0.0",  | 
 | 80 | +            "main": "index.js",  | 
 | 81 | +            "dependencies": {}  | 
 | 82 | +          }' > package.json  | 
 | 83 | +
  | 
 | 84 | +          # Get package name and modify example file:  | 
 | 85 | +          PACKAGE_NAME=$(jq -r '.name' $GITHUB_WORKSPACE/package.json)  | 
 | 86 | +          ESCAPED_PACKAGE_NAME=$(echo "$PACKAGE_NAME" | sed 's/[\/&]/\\&/g')  | 
 | 87 | +
  | 
 | 88 | +          sed -i "s/require( '.\/..\/lib' )/require( '$ESCAPED_PACKAGE_NAME' )/g" index.js  | 
 | 89 | +
  | 
 | 90 | +          # Extract and install dependencies:  | 
 | 91 | +          DEPS=$(grep -oP "require\(\s*'([^']+)'\s*\)" index.js | sed "s/require(\s*'//" | sed "s/'\s*)//" | grep -v "^\.")  | 
 | 92 | +          for dep in $DEPS; do  | 
 | 93 | +            npm install $dep --save  | 
 | 94 | +          done  | 
 | 95 | +
  | 
 | 96 | +          # Run the example:  | 
 | 97 | +          node index.js  | 
 | 98 | +
  | 
 | 99 | +      # Send Slack notification if job fails:  | 
 | 100 | +      - name: 'Send notification to Slack in case of failure'  | 
 | 101 | +        uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2  | 
 | 102 | +        with:  | 
 | 103 | +          status: ${{ job.status }}  | 
 | 104 | +          channel: '#npm-ci'  | 
 | 105 | +        if: failure()  | 
0 commit comments