diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..c0f9107 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,77 @@ +name: Publish + +on: + push: + tags: + - v* + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: denoland/setup-deno@v2 + with: + deno-version: v2.x + + - run: mkdir bin + + - name: Get Version + id: vars + run: echo ::set-output name=version::$(echo ${{github.ref_name}} | sed 's/^v//') + + - name: Write Version file + run: | + touch VERSION + echo ${{steps.vars.outputs.version}} > VERSION + + - name: Compile for Linux arm64 + run: | + deno compile \ + --target=aarch64-unknown-linux-gnu \ + --output=bin/staticalize-linux-arm64 \ + --include=VERSION \ + --allow-read --allow-write --allow-net main.ts + + - name: Compile for macOS arm64 + run: | + deno compile \ + --target=aarch64-apple-darwin \ + --output=bin/staticalize-macos-arm64 \ + --include=VERSION \ + --allow-read --allow-write --allow-net main.ts + + - name: Compile for Linux x64 + run: | + deno compile \ + --target=x86_64-unknown-linux-gnu \ + --output=bin/staticalize-linux \ + --include=VERSION \ + --allow-read --allow-write --allow-net main.ts + + - name: Compile for Windows x64 + run: | + deno compile \ + --target=x86_64-pc-windows-msvc \ + --output=bin/staticalize-windows \ + --include=VERSION \ + --allow-read --allow-write --allow-net main.ts + + - name: Compile for macOS x64 + run: | + deno compile \ + --target=x86_64-apple-darwin \ + --output=bin/staticalize-macos \ + --include=VERSION \ + --allow-read --allow-write --allow-net main.ts + + - name: Release + uses: softprops/action-gh-release@v2 + with: + make_latest: true + files: | + bin/* + action.yaml + README.md \ No newline at end of file diff --git a/README.md b/README.md index 24366c1..b3d49ad 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ port `8000`, you can build a static version of the website fit to serve on `frontside.com` into the `dist/` directory with the following command: ```ts -$ staticalize --site https://localhost:8000 --base-url http://frontside.com --outdir dist +$ staticalize --site https://localhost:8000 --base http://frontside.com --output dist ``` This will read `https://localhost:800/sitemap.xml` and download the entire @@ -36,8 +36,8 @@ Options: -h, --help Show help -V, --version Show version -s, --site URL of the website to staticalize. E.g. http://localhost:8000 [required] - -o, --outputdir Directory to place the downloaded site (default: "dist") - --base-url Base URL of the public website. E.g. http://frontside.com [required] + -o, --output Directory to place the downloaded site (default: "dist") + --base Base URL of the public website. E.g. http://frontside.com [required] ``` [sitemap]: https://sitemaps.org diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..04c31ed --- /dev/null +++ b/action.yml @@ -0,0 +1,46 @@ +name: Staticalize +description: Create a static version of a website by traversing a dynamically evaluated sitemap.xml +author: Frontside Engineering +inputs: + site: + description: "URL of the website to staticalize. E.g. http://localhost:8000" + required: true + output: + description: Directory to place the downloaded site + required: false + default: dist + base: + description: "Base URL of the public website. E.g. http://frontside.com" + required: true +runs: + using: "composite" + steps: + # Define the binary to use based on the OS + - name: Set binary path + shell: bash + run: | + if [ "${{ runner.os }}" = "Linux" ] && [ "${{ runner.arch }}" = "X64" ]; then + echo "BINARY=./bin/staticalize-linux-x64" >> $GITHUB_ENV + elif [ "${{ runner.os }}" = "Linux" ] && [ "${{ runner.arch }}" = "ARM64" ]; then + echo "BINARY=./bin/staticalize-linux-arm64" >> $GITHUB_ENV + elif [ "${{ runner.os }}" = "Windows" ]; then + echo "BINARY=./bin/staticalize-windows.exe" >> $GITHUB_ENV + elif [ "${{ runner.os }}" = "macOS" ]; then + echo "BINARY=./bin/staticalize-macos" >> $GITHUB_ENV + else + echo "Unsupported OS or architecture: ${{ runner.os }} / ${{ runner.arch }}" + exit 1 + fi + # Make the binary executable (if needed) + - name: Ensure executable permissions (Linux/macOS only) + shell: bash + if: startsWith(runner.os, 'Linux') || startsWith(runner.os, 'macOS') + run: chmod +x $BINARY + + # Run the binary + - name: Run the selected binary + shell: bash + run: $BINARY \ + --site=${{inputs.site}} \ + --output=${{inputs.output}} \ + --base=${{inputs.base}} \ No newline at end of file diff --git a/main.ts b/main.ts index a61a747..22fdbce 100644 --- a/main.ts +++ b/main.ts @@ -1,7 +1,8 @@ -import { main } from "effection"; +import { call, main } from "effection"; import { parser } from "npm:zod-opts"; import { z } from "npm:zod"; import { staticalize } from "./staticalize.ts"; +import { join } from "jsr:@std/path"; const url = () => z.string().refine((str) => str.match(/^http/), { @@ -10,11 +11,11 @@ const url = () => await main(function* (args) { let options = parser() - .name("statical") + .name("staticalize") .description( "Create a static version of a website by traversing a dynamically evaluated sitemap.xml", ) - .version("0.0.0") + .version(yield* version()) .options({ site: { alias: "s", @@ -22,12 +23,12 @@ await main(function* (args) { description: "URL of the website to staticalize. E.g. http://localhost:8000", }, - outputdir: { + output: { type: z.string().default("dist"), description: "Directory to place the downloaded site", alias: "o", }, - "base-url": { + "base": { type: url(), description: "Base URL of the public website. E.g. http://frontside.com", @@ -36,8 +37,16 @@ await main(function* (args) { .parse(args); yield* staticalize({ - base: new URL(options["base-url"]), + base: new URL(options.base), host: new URL(options.site), - dir: options.outputdir, + dir: options.output, }); }); + +function* version() { + try { + return yield* call(() => Deno.readTextFile(join(import.meta.dirname ?? "./", "VERSION"))); + } catch { + return "0.0.0" + } +} \ No newline at end of file