diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9bb7008..5cd21ca 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,12 +12,11 @@ jobs: contents: write steps: - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: oven-sh/setup-bun@v1 with: - python-version: '3.10' - check-latest: true + bun-version: latest - name: Generate release files - run: ./release.sh ${{ github.ref_name }} + run: bun ./scripts/release.js ${{ github.ref_name }} - name: Create pre-release uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/') diff --git a/makegen.py b/makegen.py deleted file mode 100755 index 605f9fa..0000000 --- a/makegen.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python3 - -import sys -import os - - -def main(dir: str) -> None: - os.chdir(dir) - with open('makefile', 'r') as file: - for line in file: - parse_line(line.strip()) - - -def parse_line(line: str) -> None: - if line.startswith('include ../'): - include(line) - else: - print(line) - - -def include(line: str) -> None: - _, filename = line.split(' ') - with open(filename, 'r') as file: - print(file.read()) - - -if __name__ == "__main__": - main(sys.argv[1]) diff --git a/release.sh b/release.sh deleted file mode 100755 index 67e1939..0000000 --- a/release.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -x - -TAG=${1:-"SNAPSHOT"} -TEMPLATES=('project' 'static' 'shared') - -SRC="src" -DIST="dist" - -rm -rf "$DIST" -mkdir -v "$DIST" - -for template in "${TEMPLATES[@]}" -do - make -C "$SRC/$template" clean - cp -R "$SRC/$template" "$DIST/$template" - ./makegen.py "$SRC/$template" | tee "$DIST/$template/makefile" - ( - cd "$DIST" || exit 1 - tar -czf "$template-$TAG.tar.gz" "$template" - md5sum "$template-$TAG.tar.gz" > "$template-$TAG.tar.gz.md5" - sha1sum "$template-$TAG.tar.gz" > "$template-$TAG.tar.gz.sha1" - rm -rf "$template" - ) -done diff --git a/scripts/release.js b/scripts/release.js new file mode 100644 index 0000000..3d46b31 --- /dev/null +++ b/scripts/release.js @@ -0,0 +1,77 @@ +import { $ } from 'bun'; +import { parseArgs } from 'util'; + +const { values } = parseArgs({ + args: Bun.argv, + options: { + tag: { + type: 'string', + default: 'SNAPSHOT' + }, + src: { + type: 'string', + default: 'src' + }, + dest: { + type: 'string', + default: 'dist' + }, + templates: { + type: 'string', + default: 'project,static,shared' + } + }, + allowPositionals: true, +}); + +const main = async ({ tag, src, dest, templates }) => { + await log(`cleaning up ${dest}...`); + + await $`rm -rfv ${dest}` + await $`mkdir -p ${dest}` + + await log(`parsing templates from ${src}...`); + + for (const template of templates.split(',')) { + await log(`generating ${template}...`); + + await $`rsync -r --exclude-from=${src}/${template}/.gitignore ${src}/${template} ${dest}` + await $`rsync -r ${src}/${template}/.vscode ${dest}/${template}` + + const lines = await generate(`${src}/${template}`) + await $`echo ${lines.join('\n')} | tee ${dest}/${template}/makefile` + + await log(`generating release files for ${template}...`); + + await $`tar -czvf ${template}-${tag}.tar.gz ${template}`.cwd(dest) + await $`md5sum ${template}-${tag}.tar.gz > ${template}-${tag}.tar.gz.md5`.cwd(dest) + await $`sha1sum ${template}-${tag}.tar.gz > ${template}-${tag}.tar.gz.sha1`.cwd(dest) + + await log(`cleaning up ${template}...`); + + await $`rm -rfv ${template}`.cwd(dest) + } +} + +const log = async (line) => { + await $`echo '\n\n'${line}'\n\n'` +} + +const generate = async (dir) => { + const lines = await $`cat ${dir}/makefile`.text() + return Promise.all(lines.split('\n').map(line => parseLine(line, dir))) +} + +const parseLine = async (line = '', dir = '.') => { + if (line.startsWith('include ../')) { + return await include(line, dir) + } + return line; +} + +const include = async (line, dir) => { + const [_, filename] = line.split(' ') + return await $`cat ${dir}/${filename}`.text() +} + +await main(values);