-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v3; defaults to pkgx^2; pure js rewrite
- Loading branch information
Showing
19 changed files
with
833 additions
and
451 deletions.
There are no files selected for viewing
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
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 |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
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'); | ||
|
||
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…`); | ||
|
||
response | ||
.pipe(tar.x({ cwd: destination, strip: 3 })) // Extract directly to destination | ||
.on('finish', resolve) | ||
.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() { | ||
const dstdir = process.env.INPUT_BINDIR || '/usr/local/bin'; | ||
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').filter(ln => ln.trim().length).map(ln => new SemVer(ln)); | ||
// get github actions input `version` | ||
let version = ''; | ||
if (process.env.INPUT_VERSION) { | ||
// create semver.Range from input | ||
const range = new SemVer.Range(process.env.INPUT_VERSION); | ||
// find the latest version that satisfies the range | ||
version = versions.filter(v => range.test(v)).sort((a, b) => -a.compare(b))[0]; | ||
} else { | ||
version = versions.slice(-1)[0]; | ||
} | ||
|
||
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); | ||
} | ||
|
||
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 (process.env['INPUT_+']) { | ||
console.log(`::group::installing pkgx input packages`); | ||
const args = process.env['INPUT_+'].split(' '); | ||
const cmd = `/usr/local/bin/pkgx ${args.map(x => `+${x}`).join(' ')}`; | ||
console.log(`running: \`${cmd}\``); | ||
const output = execSync(cmd, {env: {PKGX_DIR: process.env.INPUT_PKGX_DIR}}); | ||
parse_pkgx_output(output.toString()); | ||
console.log(`::endgroup::`); | ||
} | ||
|
||
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_UPDATE: 'no'}}); | ||
console.log(`::endgroup::`); | ||
} | ||
})(); |
Oops, something went wrong.