building pipeline

This commit is contained in:
Letter N
2021-03-04 21:51:20 +08:00
parent 23c04cac12
commit dcab40cdb6
134 changed files with 10776 additions and 5991 deletions
+84
View File
@@ -0,0 +1,84 @@
#!/bin/sh
# bootstrap/node
#
# Node-finding script for all `sh` environments, including Linux, MSYS2,
# Git for Windows, and GitHub Desktop. Invokable from CLI or automation.
#
# If a node.exe installed by `node_.ps1` is present, it will be used.
# Otherwise, this script requires a system `node` to be provided.
set -e
# Convenience variables
Bootstrap="$(dirname "$0")"
Cache="$Bootstrap/.cache"
if [ "$TG_BOOTSTRAP_CACHE" ]; then
Cache="$TG_BOOTSTRAP_CACHE"
fi
OldPWD="$PWD"
cd "$Bootstrap/../.."
. ./dependencies.sh # sets NODE_VERSION_PRECISE
cd "$OldPWD"
NodeVersion="$NODE_VERSION_PRECISE"
NodeFullVersion="node-v$NodeVersion-win-x64"
NodeDir="$Cache/$NodeFullVersion"
NodeExe="$NodeDir/node.exe"
Log="$Cache/last-command.log"
# If a bootstrapped Node is not present, search on $PATH.
if [ "$(uname)" = "Linux" ] || [ ! -f "$NodeExe" ]; then
if [ "$TG_BOOTSTRAP_NODE_LINUX" ]; then
NodeFullVersion="node-v$NodeVersion-linux-x64"
NodeDir="$Cache/$NodeFullVersion/bin"
NodeExe="$NodeDir/node"
if [ ! -f "$NodeExe" ]; then
mkdir -p "$Cache"
Archive="$(realpath "$Cache/node-v$NodeVersion.tar.gz")"
curl "https://nodejs.org/download/release/v$NodeVersion/$NodeFullVersion.tar.gz" -o "$Archive"
(cd "$Cache" && tar xf "$Archive")
fi
elif command -v node >/dev/null 2>&1; then
NodeExe="node"
else
echo
if command -v apt-get >/dev/null 2>&1; then
# Ubuntu advice
echo "Please install Node using your system's package manager:"
echo " sudo apt-get install nodejs"
elif uname | grep -q MSYS; then
# MSYS2 (not packaged) or Git for Windows advice
echo "Please run bootstrap/node.bat instead of bootstrap/node once"
echo "to install Node automatically, or install it from https://nodejs.org/"
elif command -v pacman >/dev/null 2>&1; then
# Arch advice
echo "Please install Node using your system's package manager:"
echo " sudo pacman -S nodejs"
else
# Generic advice
echo "Please install Node from https://nodejs.org/ or using your system's package manager."
fi
echo
exit 1
fi
fi
# Cheap shell function if tee.exe is not available
if ! command -v tee >/dev/null 2>&1; then
tee() {
# Fudge: assume $1 is always "-a"
while read -r line; do
echo "$line" >> "$2"
echo "$line"
done
}
fi
# Invoke Node with all command-line arguments
mkdir -p "$Cache"
printf '%s\n' "$NodeExe" "$@" > "$Log"
printf -- '---\n' >> "$Log"
exec 4>&1
PATH="$(readlink -f "$NodeDir"):$PATH" # Set PATH so that recursive calls find it
exitstatus=$({ { set +e; "$NodeExe" "$@" 2>&1 3>&-; printf %s $? >&3; } 4>&- | tee -a "$Log" 1>&4; } 3>&1)
exec 4>&-
exit "$exitstatus"
+9
View File
@@ -0,0 +1,9 @@
@echo off
where node.exe >nul 2>nul
if %errorlevel% == 0 (
echo | set /p printed_str="Using system-wide Node "
call node.exe --version
call node.exe %*
) else (
call powershell.exe -NoLogo -ExecutionPolicy Bypass -File "%~dp0\node_.ps1" %*
)
+57
View File
@@ -0,0 +1,57 @@
## bootstrap/node_.ps1
##
## Node bootstrapping script for Windows.
##
## Automatically downloads a Node version to a cache directory and invokes it.
##
## The underscore in the name is so that typing `bootstrap/node` into
## PowerShell finds the `.bat` file first, which ensures this script executes
## regardless of ExecutionPolicy.
#Requires -Version 4.0
$Host.ui.RawUI.WindowTitle = "starting :: node $Args"
$ErrorActionPreference = "Stop"
## This forces UTF-8 encoding across all powershell built-ins
$OutputEncoding = [System.Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$PSDefaultParameterValues['*:Encoding'] = 'utf8'
function ExtractVersion {
param([string] $Path, [string] $Key)
foreach ($Line in Get-Content $Path) {
if ($Line.StartsWith("export $Key=")) {
return $Line.Substring("export $Key=".Length)
}
}
throw "Couldn't find value for $Key in $Path"
}
## Convenience variables
$BaseDir = Split-Path $script:MyInvocation.MyCommand.Path
$Cache = "$BaseDir/.cache"
if ($Env:TG_BOOTSTRAP_CACHE) {
$Cache = $Env:TG_BOOTSTRAP_CACHE
}
$NodeVersion = ExtractVersion -Path "$BaseDir/../../dependencies.sh" -Key "NODE_VERSION_PRECISE"
$NodeDir = "$Cache/node-v$NodeVersion"
$NodeExe = "$NodeDir/node.exe"
## Download and unzip Node
if (!(Test-Path $NodeExe -PathType Leaf)) {
$Host.ui.RawUI.WindowTitle = "Downloading Node $NodeVersion..."
New-Item $NodeDir -ItemType Directory -ErrorAction silentlyContinue | Out-Null
Invoke-WebRequest `
"https://nodejs.org/download/release/v$NodeVersion/win-x86/node.exe" `
-OutFile $NodeExe `
-ErrorAction Stop
}
## Set PATH so that recursive calls find it
$Env:PATH = "$NodeDir;$ENV:Path"
## Invoke Node with all command-line arguments
$Host.ui.RawUI.WindowTitle = "node $Args"
$ErrorActionPreference = "Continue"
& "$NodeExe" @Args
exit $LastExitCode
+1
View File
@@ -77,6 +77,7 @@ fi
# Use pip to install our requirements
if [ ! -f "$PythonDir/requirements.txt" ] || [ "$(b2sum < "$Sdk/requirements.txt")" != "$(b2sum < "$PythonDir/requirements.txt")" ]; then
echo "Updating dependencies..."
"$PythonExe" -m pip install -U wheel
"$PythonExe" -m pip install -U pip -r "$Sdk/requirements.txt"
cp "$Sdk/requirements.txt" "$PythonDir/requirements.txt"
echo "---"
Regular → Executable
View File