Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/ci.action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,32 @@ jobs:
- run: git clean -xfd
- uses: ./
- run: pkgx --version
- uses: actions/upload-artifact@v4
with:
path: |
./action.js
./action.yml
name: action

linuxen:
needs: dist
continue-on-error: true
runs-on: ubuntu-latest
strategy:
matrix:
container:
- debian:buster-slim
- debian:bullseye-slim
- debian:bookworm-slim
- archlinux:latest
- ubuntu:focal
- ubuntu:jammy
- ubuntu:noble
- fedora:latest
container: ${{ matrix.container }}
steps:
- uses: actions/download-artifact@v4
with:
name: action
- uses: ./
- run: pkgx node -e 'console.log(1)'
4 changes: 2 additions & 2 deletions .github/workflows/ci.installer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ jobs:
env:
PATH: ${{ github.workspace }}/bin:/usr/bin:/bin

- run: pkgx deno eval 'console.log(1)'
- run: pkgx node -e 'console.log(1)'

windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- run: .\\installer.ps1
- run: |
$env:Path += ";C:\Program Files\pkgx"
$env:Path += ";$env:LOCALAPPDATA\pkgx"
pkgx +zlib.net

upgrades:
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@ just slow things down.

## Version History

* `v4` defaults to `pkgx`^2, uses node^20 and doesn’t install any pre-reqs on Linux†
* `v3` defaults to `pkgx`^2 and uses node^20
* `v2` defaults to `pkgx`^1 and uses node^20
* `v1` defaults to `pkgx`@latest and uses node^16
* `v0` should not be used

> † `pkgx` requires glibc>=2.28, libgcc, libstdc++ and libatomic. Generally
> images come installed with these. If you are building binaries you may need
> the `-dev` versions of these packages also.

 


Expand Down
36 changes: 19 additions & 17 deletions action.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { execSync } = require('child_process');
const unzipper = require('unzipper');
const semver = require('semver');
const https = require('https');
const path = require('path');
Expand Down Expand Up @@ -27,23 +28,31 @@ function platform_key() {
}

function downloadAndExtract(url, destination, strip) {

return new Promise((resolve, reject) => {
https.get(url, (response) => {
if (response.statusCode !== 200) {
reject(new Error(`Failed to get '${url}' (${response.statusCode})`));
return;
}

console.log(`extracting tarball…`);

const tar_stream = tar.x({ cwd: destination, strip });
console.log(`extracting pkgx archive…`);

response
.pipe(tar_stream) // Extract directly to destination
.on('finish', resolve)
.on('error', reject);

tar_stream.on('error', reject);
if (platform_key().startsWith('windows')) {
const unzip_stream = unzipper.Extract({ path: destination });
response
.pipe(unzip_stream)
.promise()
.then(resolve, reject);
unzip_stream.on('error', reject);
} else {
const tar_stream = tar.x({ cwd: destination, strip });
response
.pipe(tar_stream)
.on('finish', resolve)
.on('error', reject);
tar_stream.on('error', reject);
}

}).on('error', reject);
});
Expand Down Expand Up @@ -93,7 +102,7 @@ async function install_pkgx() {
if (platform_key().startsWith('windows')) {
// not yet versioned
strip = 0;
return 'https://pkgx.sh/Windows/x86_64.tgz';
return 'https://pkgx.sh/Windows/x86_64.zip';
}

let url = `https://dist.pkgx.dev/pkgx.sh/${platform_key()}/versions.txt`;
Expand Down Expand Up @@ -139,13 +148,6 @@ async function install_pkgx() {
fs.appendFileSync(process.env["GITHUB_ENV"], `PKGX_DIR=${process.env.INPUT_PKGX_DIR}\n`);
}

if (os.platform() == 'linux') {
console.log(`::group::installing pre-requisites`);
const installer_script_path = path.join(path.dirname(__filename), "installer.sh");
execSync(installer_script_path, {env: {PKGX_INSTALL_PREREQS: '1', ...process.env}});
console.log(`::endgroup::`);
}

if (process.env['INPUT_+']) {
console.log(`::group::installing pkgx input packages`);
let args = process.env['INPUT_+'].split(' ');
Expand Down
10 changes: 5 additions & 5 deletions installer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

$ErrorActionPreference = "Stop"

# Determine install location
$installDir = "$env:ProgramFiles\pkgx"
# Determine install location for the current user
$installDir = "$env:LOCALAPPDATA\pkgx"

# Create directory if it doesn't exist
if (!(Test-Path $installDir)) {
Expand All @@ -17,10 +17,10 @@ Invoke-WebRequest -Uri $zipUrl -OutFile $zipFile
Expand-Archive -Path $zipFile -DestinationPath $installDir -Force
Remove-Item $zipFile

# Ensure PATH is updated
$envPath = [System.Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)
# Ensure user's PATH is updated
$envPath = [System.Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
if ($envPath -notlike "*$installDir*") {
[System.Environment]::SetEnvironmentVariable("Path", "$envPath;$installDir", [System.EnvironmentVariableTarget]::Machine)
[System.Environment]::SetEnvironmentVariable("Path", "$envPath;$installDir", [System.EnvironmentVariableTarget]::User)
}

Write-Host "pkgx installed successfully! Restart your terminal to use it."
90 changes: 13 additions & 77 deletions installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
_main() {
if _should_install_pkgx; then
_install_pkgx "$@"
_install_pre_reqs
elif [ $# -eq 0 ]; then
echo /usr/local/bin/"$(pkgx --version) already installed" >&2
echo /usr/local/bin/"$(pkgm --version) already installed" >&2
Expand All @@ -19,7 +18,7 @@
if ! [ "$major_version" ]; then
major_version=$(pkgx --version | cut -d' ' -f2 | cut -d. -f1)
fi
if [ $major_version -lt 2 ]; then

Check warning on line 21 in installer.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./installer.sh:21:12: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)
eval "$(pkgx --shellcode)" 2>/dev/null
fi
fi
Expand All @@ -44,73 +43,9 @@
}

_is_ci() {
[ -n "$CI" ] && [ $CI != 0 ]

Check warning on line 46 in installer.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./installer.sh:46:21: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)
}

_install_pre_reqs() {
if _is_ci; then
apt() {
# we should use apt-get not apt in CI
# weird shit ref: https://askubuntu.com/a/668859
export DEBIAN_FRONTEND=noninteractive
cmd=$1
shift
$SUDO apt-get $cmd --yes -qq -o=Dpkg::Use-Pty=0 $@
}
else
apt() {
case "$1" in
update)
echo "ensure you have the \`pkgx\` pre-requisites installed:" >&2
;;
install)
echo " apt-get" "$@" >&2
;;
esac
}
yum() {
echo "ensure you have the \`pkgx\` pre-requisites installed:" >&2
echo " yum" "$@" >&2
}
pacman() {
echo "ensure you have the \`pkgx\` pre-requisites installed:" >&2
echo " pacman" "$@" >&2
}
fi

if test -f /etc/debian_version; then
apt update

# minimal but required or networking doesn’t work
# https://packages.debian.org/buster/all/netbase/filelist
A="netbase"

# difficult to pkg in our opinion
B=libudev-dev

# ca-certs needed until we bundle our own root cert
C=ca-certificates

case $(cat /etc/debian_version) in
jessie/sid|8.*|stretch/sid|9.*)
apt install libc-dev libstdc++-4.8-dev libgcc-4.7-dev $A $B $C;;
buster/sid|10.*)
apt install libc-dev libstdc++-8-dev libgcc-8-dev $A $B $C;;
bullseye/sid|11.*)
apt install libc-dev libstdc++-10-dev libgcc-9-dev $A $B $C;;
bookworm/sid|12.*|*)
apt install libc-dev libstdc++-11-dev libgcc-11-dev $A $B $C;;
esac
elif test -f /etc/fedora-release; then
$SUDO yum --assumeyes install libatomic
elif test -f /etc/arch-release; then
# installing gcc isn't my favorite thing, but even clang depends on it
# on archlinux. it provides libgcc. since we use it for testing, the risk
# to our builds is very low.
$SUDO pacman --noconfirm -Sy gcc libatomic_ops libxcrypt-compat
fi
}

_install_pkgx() {
if _is_ci; then
progress="--no-progress-meter"
Expand All @@ -122,23 +57,27 @@

if [ $# -eq 0 ]; then
if [ -f /usr/local/bin/pkgx ]; then
echo "upgrading: /usr/local/bin/pkg[xm]" >&2
echo "upgrading: /usr/local/bin/pkgx" >&2
else
echo "installing: /usr/local/bin/pkg[xm]" >&2
echo "installing: /usr/local/bin/pkgx" >&2
fi

# using a named pipe to prevent curl progress output trumping the sudo password prompt
pipe="$tmpdir/pipe"
mkfifo "$pipe"

curl --silent --fail --proto '=https' -o "$tmpdir/pkgm" \
https://pkgxdev.github.io/pkgm/pkgm.ts

curl $progress --fail --proto '=https' "https://pkgx.sh/$(uname)/$(uname -m)".tgz > "$pipe" &
$SUDO sh -c "
mkdir -p /usr/local/bin
tar xz --directory /usr/local/bin < '$pipe'
install -m 755 "$tmpdir/pkgm" /usr/local/bin
if [ ! -f /usr/local/bin/pkgm ]; then
echo '#!/usr/bin/env -S pkgx -q! pkgm' > /usr/local/bin/pkgm
chmod +x /usr/local/bin/pkgm
fi
if [ ! -f /usr/local/bin/mash ]; then
echo '#!/usr/bin/env -S pkgx -q! mash' > /usr/local/bin/mash
chmod +x /usr/local/bin/mash
fi
" &
wait

Expand All @@ -151,7 +90,8 @@

# tell the user what version we just installed
pkgx --version
pkgm --version
pkgx pkgm@latest --version
pkgx mash@latest --version

else
curl $progress --fail --proto '=https' \
Expand All @@ -171,10 +111,10 @@
else
new_version=$(curl -Ssf https://pkgx.sh/VERSION)
old_version=$(/usr/local/bin/pkgx --version || echo pkgx 0)
old_version=$(echo $old_version | cut -d' ' -f2)

Check warning on line 114 in installer.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./installer.sh:114:24: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)
major_version=$(echo $new_version | cut -d. -f1)

Check warning on line 115 in installer.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./installer.sh:115:26: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

/usr/local/bin/pkgx --silent semverator gt $new_version $old_version

Check warning on line 117 in installer.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./installer.sh:117:48: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

Check warning on line 117 in installer.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./installer.sh:117:61: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)
fi
}

Expand All @@ -184,9 +124,9 @@
else
new_version=$(curl -Ssf https://pkgxdev.github.io/pkgm/version.txt)
old_version=$(pkgm --version || echo pkgm 0)
old_version=$(echo $old_version | cut -d' ' -f2)

Check warning on line 127 in installer.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./installer.sh:127:24: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

/usr/local/bin/pkgx --silent semverator gt $new_version $old_version

Check warning on line 129 in installer.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./installer.sh:129:48: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

Check warning on line 129 in installer.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./installer.sh:129:61: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)
fi
}

Expand All @@ -201,8 +141,4 @@
}

_prep
if [ "$PKGX_INSTALL_PREREQS" != 1 ]; then
_main "$@"
else
_install_pre_reqs
fi
_main "$@"
Loading