Skip to content

Commit 8da29be

Browse files
committed
build: add workflow to test installation of main package
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent 1801ae1 commit 8da29be

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
- cron: '0 0 * * 0'
27+
28+
# Allow workflow to be manually run:
29+
workflow_dispatch:
30+
31+
# Workflow jobs:
32+
jobs:
33+
test-published:
34+
# Define a display name:
35+
name: 'Test running examples of published package'
36+
37+
# Define the type of virtual host machine:
38+
runs-on: ubuntu-latest
39+
40+
# Define environment variables:
41+
env:
42+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
43+
44+
# Define the job's steps:
45+
steps:
46+
# Checkout the repository:
47+
- name: 'Checkout repository'
48+
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
49+
50+
# Install Node.js:
51+
- name: 'Install Node.js'
52+
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
53+
with:
54+
node-version: 20
55+
timeout-minutes: 5
56+
57+
# Create test directory and run examples:
58+
- name: 'Create test directory and run examples'
59+
run: |
60+
cd ..
61+
mkdir test-published
62+
cd test-published
63+
64+
# Copy example file:
65+
cp $GITHUB_WORKSPACE/examples/index.js .
66+
67+
# Create a minimal package.json
68+
echo '{
69+
"name": "test-published",
70+
"version": "1.0.0",
71+
"main": "index.js",
72+
"dependencies": {}
73+
}' > package.json
74+
75+
# Get package name and modify example file:
76+
PACKAGE_NAME=$(jq -r '.name' $GITHUB_WORKSPACE/package.json)
77+
ESCAPED_PACKAGE_NAME=$(echo "$PACKAGE_NAME" | sed 's/[\/&]/\\&/g')
78+
79+
sed -i "s/require( '.\/..\/lib' )/require( '$ESCAPED_PACKAGE_NAME' )/g" index.js
80+
81+
# Extract and install dependencies:
82+
DEPS=$(grep -oP "require\(\s*'([^']+)'\s*\)" index.js | sed "s/require(\s*'//" | sed "s/'\s*)//" | grep -v "^\.")
83+
for dep in $DEPS; do
84+
npm install $dep --save
85+
done
86+
87+
# Run the example:
88+
node index.js
89+
90+
# Send Slack notification if job fails:
91+
- name: 'Send notification to Slack in case of failure'
92+
uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2
93+
with:
94+
status: ${{ job.status }}
95+
channel: '#npm-ci'
96+
if: failure()

0 commit comments

Comments
 (0)