Last active
July 31, 2018 11:52
-
-
Save ianfixes/69213572dcfd8077c2316370a6c41d2c to your computer and use it in GitHub Desktop.
Test that your NPM prepare scripts are working properly as a part of GitLab CI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This script is for testing coffeescript (or other transpiled npm packages) on GitLab | |
# | |
# Designed to be put in a subdirectory of the repo under test, it generates a package.json and index.js | |
# for a dummy test project -- it will check that whatever project is in the parent directory (i.e. the | |
# root of your repo where package.json is) can properly prepare itself for installation when specified | |
# as a git:// dependency | |
# | |
# To do this, it literally specifies your package under test as a git:// dependency -- | |
# the ONLY non-semver dependency option that appears to trigger an `npm prepare` action to fire. It | |
# does this using the same git checkout info that the CI machine would use to get the repo. | |
# | |
# It's possible that this script could be adapted for GitHub (e.g. Travis CI or some such) but I'm | |
# not certain what the checkout token would be nor what the environment variables would be. | |
# | |
# The relevant addition to your .gitlab-ci.yml would be: | |
# - rm -rf lib/* # destroy any previously-compiled stuff in lib (if that's where you compiled to) | |
# - cd whatever_directory_you_put_this_script_in | |
# - bash build-npm-packaging-tester.sh | |
# - npm install | |
# - npm test | |
# | |
NPM_PACKAGE=$(cat ../package.json | grep -Eow "\"name\":\s+\"[^\"]*\"" | cut -d "\"" -f 4) | |
cat > package.json <<JSON | |
{ | |
"name": "coffeescript_packaging_test", | |
"version": "1.0.0", | |
"description": "Tests that $NPM_PACKAGE successfully prepares itself when installed from a repository URL", | |
"main": "index.js", | |
"scripts": { | |
"test": "node index.js" | |
}, | |
"author": "Ian Katz", | |
"license": "Apache-2.0", | |
"repository": { | |
"type": "git", | |
"url": "../" | |
}, | |
"dependencies": { | |
"$NPM_PACKAGE": "git+$CI_REPOSITORY_URL#$CI_COMMIT_REF_NAME" | |
} | |
} | |
JSON | |
cat > index.js <<JAVASCRIPT | |
require('$NPM_PACKAGE'); | |
JAVASCRIPT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment