Skip to content

Commit

Permalink
Merge pull request #1 from taras/tm/publis-github-action
Browse files Browse the repository at this point in the history
Publish GitHub Action
  • Loading branch information
taras authored Jan 16, 2025
2 parents 9dbffbf + 7e69dba commit f07132d
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 10 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,8 +36,8 @@ Options:
-h, --help Show help
-V, --version Show version
-s, --site <string> URL of the website to staticalize. E.g. http://localhost:8000 [required]
-o, --outputdir <string> Directory to place the downloaded site (default: "dist")
--base-url <string> Base URL of the public website. E.g. http://frontside.com [required]
-o, --output <string> Directory to place the downloaded site (default: "dist")
--base <string> Base URL of the public website. E.g. http://frontside.com [required]
```

[sitemap]: https://sitemaps.org
46 changes: 46 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Staticalize
description: Create a static version of a website by traversing a dynamically evaluated sitemap.xml
author: Frontside Engineering <[email protected]>
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}}
23 changes: 16 additions & 7 deletions main.ts
Original file line number Diff line number Diff line change
@@ -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/), {
Expand All @@ -10,24 +11,24 @@ 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",
type: url(),
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",
Expand All @@ -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"
}
}

0 comments on commit f07132d

Please sign in to comment.