Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3; defaults to pkgx^2; pure js rewrite #256

Merged
merged 4 commits into from
Jan 15, 2025
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
25 changes: 25 additions & 0 deletions .github/workflows/cd.vx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: cd·vx

on:
release:
types:
- published

concurrency:
group: cd/vx/${{ github.event.release.tag_name }}
cancel-in-progress: true

permissions:
contents: write

jobs:
retag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: fischerscode/tagger@v0
with:
prefix: v
- run: |
git tag -f latest
git push origin latest --force
66 changes: 0 additions & 66 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,69 +9,3 @@ jobs:
uses: ./.github/workflows/ci.installer.yml
qa-action:
uses: ./.github/workflows/ci.action.yml

dist:
needs: [qa-installer, qa-action]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: curl -Ssf https://pkgx.sh/$(uname)/$(uname -m).tgz | sudo tar xz -C /usr/local/bin
- run: ./scripts/dist.sh --minify
- uses: actions/upload-artifact@v3
with:
name: dist
path: dist

put:
permissions:
contents: write
deployments: write
needs: dist
runs-on: ubuntu-latest
steps:
- name: Create Deployment
uses: bobheadxi/deployments@v1
id: deployment
with:
step: start
env: aws

- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
name: dist
path: dist

- uses: git-actions/set-user@v1

- run: |
if ! git diff --exit-code; then
git add dist
git commit -m v${{ github.event.inputs.version }}
git tag v${{ github.event.inputs.version }}
git push origin v${{ github.event.inputs.version }} main
fi
- uses: softprops/action-gh-release@v1
with:
files: ./installer.sh
tag_name: v${{ github.event.inputs.version }}
fail_on_unmatched_files: true

- uses: fischerscode/tagger@v0
with:
prefix: v
tag: v${{ github.event.inputs.version }}

- run: |
git tag --force latest
git push origin latest
- name: Seal Deployment
uses: bobheadxi/deployments@v1
if: always()
with:
env: aws
step: finish
status: ${{ job.status }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
42 changes: 14 additions & 28 deletions .github/workflows/ci.action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,27 @@ on:
workflow_call:
pull_request:
paths:
- action.ts
- action.js
- action.yml
- package.json
- installer.sh

concurrency:
group: ${{ github.ref || 'ci' }}/action.ts
cancel-in-progress: true

jobs:
dist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: ./scripts/dist.sh
- uses: actions/upload-artifact@v3
with:
name: dist
path: dist

std:
needs: dist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
name: dist
path: dist
- run: npm i
- uses: ./
with:
version: null
- run: pkgx --version

plus-pkgs:
needs: dist
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -46,7 +34,7 @@ jobs:
- [self-hosted, linux, ARM64] # works in arm64 environments
prefix:
- null
- /opt
- /tmp/pkgx
container:
- null
include:
Expand All @@ -55,31 +43,29 @@ jobs:
container: ${{ matrix.container }}
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3

- uses: actions/setup-node@v4
with:
name: dist
path: dist
node-version: latest
- run: npm i

- uses: ./
with:
PKGX_DIR: ${{ matrix.prefix }}
+: node@18 deno.land

- run: test -f '${{ matrix.prefix }}/pkgx.sh/v*/bin/pkgx'
- run: test -f '${{ matrix.prefix }}/deno.land/v*/bin/deno'
if: ${{ matrix.prefix }}

- run: pkgx --version
- run: node --eval 'console.log(1)'
- run: if [[ "$(node --version)" != v18.* ]]; then exit 1; fi
- run: deno --version

multiple-apply-is-ok:
runs-on: ubuntu-latest
needs: dist
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
name: dist
path: dist
- run: npm i
- uses: ./
- run: pkgx --version
- uses: ./
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci.installer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,7 @@ jobs:
tar xz --strip-components=3
- run: mv pkgx /usr/local/bin
- run: test "$(pkgx --version)" = 'pkgx 1.0.0'
- run: PKGX_UPDATE=no ./installer.sh
- run: test "$(pkgx --version)" = 'pkgx 1.0.0'
- run: ./installer.sh
- run: pkgx semverator gt $(pkgx --version | awk '{print $2}') 1.0.0
152 changes: 152 additions & 0 deletions action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
const { execSync } = require('child_process');
const semver = require('semver');
const https = require('https');
const path = require('path');
const tar = require('tar');
const fs = require('fs');
const os = require('os');

const dstdir = (() => {
try {
fs.accessSync('/usr/local/bin', fs.constants.W_OK);
return '/usr/local/bin';
} catch (err) {
return path.join(process.env.INPUT_PKGX_DIR || path.join(process.env.HOME, '.pkgx'), 'bin');
}
})();

fs.writeFileSync(process.env["GITHUB_PATH"], `${dstdir}\n`);

function platform_key() {
const platform = os.platform(); // 'darwin', 'linux', 'win32', etc.
let arch = os.arch(); // 'x64', 'arm64', etc.
if (arch == 'x64') arch = 'x86-64';
if (arch == 'arm64') arch = 'aarch64';
return `${platform}/${arch}`;
}

function downloadAndExtract(url, destination) {
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: 3 });

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

tar_stream.on('error', reject);

}).on('error', reject);
});
}

function parse_pkgx_output(output) {

const stripQuotes = (str) =>
str.startsWith('"') || str.startsWith("'") ? str.slice(1, -1) : str;

const replaceEnvVars = (str) => {
const value = str
.replaceAll(
/\$\{([a-zA-Z0-9_]+):\+:\$[a-zA-Z0-9_]+\}/g,
(_, key) => ((v) => v ? `:${v}` : "")(process.env[key]),
)
.replaceAll(/\$\{([a-zA-Z0-9_]+)\}/g, (_, key) => process.env[key] ?? "")
.replaceAll(/\$([a-zA-Z0-9_]+)/g, (_, key) => process.env[key] ?? "");
return value;
};

for (const line of output.split("\n")) {
const match = line.match(/^([^=]+)=(.*)$/);
if (match) {
const [_, key, value_] = match;
const value = stripQuotes(value_);
if (key === "PATH") {
value
.replaceAll("${PATH:+:$PATH}", "")
.replaceAll("$PATH", "")
.replaceAll("${PATH}", "")
.split(":").forEach((path) => {
fs.appendFileSync(process.env["GITHUB_PATH"], `${path}\n`);
});
} else {
let v = replaceEnvVars(value);
fs.appendFileSync(process.env["GITHUB_ENV"], `${key}=${v}\n`);
}
}
}
}

async function install_pkgx() {
let url = `https://dist.pkgx.dev/pkgx.sh/${platform_key()}/versions.txt`;

console.log(`::group::installing ${dstdir}/pkgx`);
console.log(`fetching ${url}`);

const rsp = await fetch(url);
const txt = await rsp.text();

const versions = txt.split('\n');
const version = process.env.INPUT_VERSION
? semver.maxSatisfying(versions, process.env.INPUT_VERSION)
: versions.slice(-1)[0];

if (!version) {
throw new Error(`no version found for ${process.env.INPUT_VERSION}`);
}

console.log(`selected pkgx v${version}`);

url = `https://dist.pkgx.dev/pkgx.sh/${platform_key()}/v${version}.tar.gz`;

console.log(`fetching ${url}`);

if (!fs.existsSync(dstdir)) {
fs.mkdirSync(dstdir, {recursive: true});
}

await downloadAndExtract(url, dstdir);

console.log(`::endgroup::`);
}

(async () => {
await install_pkgx();

if (process.env.INPUT_PKGX_DIR) {
fs.appendFileSync(process.env["GITHUB_ENV"], `PKGX_DIR=${process.env.INPUT_PKGX_DIR}\n`);
}

if (os.platform() != 'darwin') {
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`);
const args = process.env['INPUT_+'].split(' ');
const cmd = `${dstdir}/pkgx ${args.map(x => `+${x}`).join(' ')}`;
console.log(`running: \`${cmd}\``);
let env = undefined;
if (process.env.INPUT_PKGX_DIR) {
env = process.env
env['PKGX_DIR'] = process.env.INPUT_PKGX_DIR;
}
const output = execSync(cmd, {env});
parse_pkgx_output(output.toString());
console.log(`::endgroup::`);
}
})().catch(err => {
console.error(`::error::${err.message}`)
process.exit(1);
});
Loading
Loading