Skip to content

Commit f07132d

Browse files
authored
Merge pull request #1 from taras/tm/publis-github-action
Publish GitHub Action
2 parents 9dbffbf + 7e69dba commit f07132d

File tree

4 files changed

+142
-10
lines changed

4 files changed

+142
-10
lines changed

.github/workflows/publish.yaml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- uses: denoland/setup-deno@v2
16+
with:
17+
deno-version: v2.x
18+
19+
- run: mkdir bin
20+
21+
- name: Get Version
22+
id: vars
23+
run: echo ::set-output name=version::$(echo ${{github.ref_name}} | sed 's/^v//')
24+
25+
- name: Write Version file
26+
run: |
27+
touch VERSION
28+
echo ${{steps.vars.outputs.version}} > VERSION
29+
30+
- name: Compile for Linux arm64
31+
run: |
32+
deno compile \
33+
--target=aarch64-unknown-linux-gnu \
34+
--output=bin/staticalize-linux-arm64 \
35+
--include=VERSION \
36+
--allow-read --allow-write --allow-net main.ts
37+
38+
- name: Compile for macOS arm64
39+
run: |
40+
deno compile \
41+
--target=aarch64-apple-darwin \
42+
--output=bin/staticalize-macos-arm64 \
43+
--include=VERSION \
44+
--allow-read --allow-write --allow-net main.ts
45+
46+
- name: Compile for Linux x64
47+
run: |
48+
deno compile \
49+
--target=x86_64-unknown-linux-gnu \
50+
--output=bin/staticalize-linux \
51+
--include=VERSION \
52+
--allow-read --allow-write --allow-net main.ts
53+
54+
- name: Compile for Windows x64
55+
run: |
56+
deno compile \
57+
--target=x86_64-pc-windows-msvc \
58+
--output=bin/staticalize-windows \
59+
--include=VERSION \
60+
--allow-read --allow-write --allow-net main.ts
61+
62+
- name: Compile for macOS x64
63+
run: |
64+
deno compile \
65+
--target=x86_64-apple-darwin \
66+
--output=bin/staticalize-macos \
67+
--include=VERSION \
68+
--allow-read --allow-write --allow-net main.ts
69+
70+
- name: Release
71+
uses: softprops/action-gh-release@v2
72+
with:
73+
make_latest: true
74+
files: |
75+
bin/*
76+
action.yaml
77+
README.md

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ port `8000`, you can build a static version of the website fit to serve on
1818
`frontside.com` into the `dist/` directory with the following command:
1919

2020
```ts
21-
$ staticalize --site https://localhost:8000 --base-url http://frontside.com --outdir dist
21+
$ staticalize --site https://localhost:8000 --base http://frontside.com --output dist
2222
```
2323

2424
This will read `https://localhost:800/sitemap.xml` and download the entire
@@ -36,8 +36,8 @@ Options:
3636
-h, --help Show help
3737
-V, --version Show version
3838
-s, --site <string> URL of the website to staticalize. E.g. http://localhost:8000 [required]
39-
-o, --outputdir <string> Directory to place the downloaded site (default: "dist")
40-
--base-url <string> Base URL of the public website. E.g. http://frontside.com [required]
39+
-o, --output <string> Directory to place the downloaded site (default: "dist")
40+
--base <string> Base URL of the public website. E.g. http://frontside.com [required]
4141
```
4242

4343
[sitemap]: https://sitemaps.org

action.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Staticalize
2+
description: Create a static version of a website by traversing a dynamically evaluated sitemap.xml
3+
author: Frontside Engineering <[email protected]>
4+
inputs:
5+
site:
6+
description: "URL of the website to staticalize. E.g. http://localhost:8000"
7+
required: true
8+
output:
9+
description: Directory to place the downloaded site
10+
required: false
11+
default: dist
12+
base:
13+
description: "Base URL of the public website. E.g. http://frontside.com"
14+
required: true
15+
runs:
16+
using: "composite"
17+
steps:
18+
# Define the binary to use based on the OS
19+
- name: Set binary path
20+
shell: bash
21+
run: |
22+
if [ "${{ runner.os }}" = "Linux" ] && [ "${{ runner.arch }}" = "X64" ]; then
23+
echo "BINARY=./bin/staticalize-linux-x64" >> $GITHUB_ENV
24+
elif [ "${{ runner.os }}" = "Linux" ] && [ "${{ runner.arch }}" = "ARM64" ]; then
25+
echo "BINARY=./bin/staticalize-linux-arm64" >> $GITHUB_ENV
26+
elif [ "${{ runner.os }}" = "Windows" ]; then
27+
echo "BINARY=./bin/staticalize-windows.exe" >> $GITHUB_ENV
28+
elif [ "${{ runner.os }}" = "macOS" ]; then
29+
echo "BINARY=./bin/staticalize-macos" >> $GITHUB_ENV
30+
else
31+
echo "Unsupported OS or architecture: ${{ runner.os }} / ${{ runner.arch }}"
32+
exit 1
33+
fi
34+
# Make the binary executable (if needed)
35+
- name: Ensure executable permissions (Linux/macOS only)
36+
shell: bash
37+
if: startsWith(runner.os, 'Linux') || startsWith(runner.os, 'macOS')
38+
run: chmod +x $BINARY
39+
40+
# Run the binary
41+
- name: Run the selected binary
42+
shell: bash
43+
run: $BINARY \
44+
--site=${{inputs.site}} \
45+
--output=${{inputs.output}} \
46+
--base=${{inputs.base}}

main.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { main } from "effection";
1+
import { call, main } from "effection";
22
import { parser } from "npm:zod-opts";
33
import { z } from "npm:zod";
44
import { staticalize } from "./staticalize.ts";
5+
import { join } from "jsr:@std/path";
56

67
const url = () =>
78
z.string().refine((str) => str.match(/^http/), {
@@ -10,24 +11,24 @@ const url = () =>
1011

1112
await main(function* (args) {
1213
let options = parser()
13-
.name("statical")
14+
.name("staticalize")
1415
.description(
1516
"Create a static version of a website by traversing a dynamically evaluated sitemap.xml",
1617
)
17-
.version("0.0.0")
18+
.version(yield* version())
1819
.options({
1920
site: {
2021
alias: "s",
2122
type: url(),
2223
description:
2324
"URL of the website to staticalize. E.g. http://localhost:8000",
2425
},
25-
outputdir: {
26+
output: {
2627
type: z.string().default("dist"),
2728
description: "Directory to place the downloaded site",
2829
alias: "o",
2930
},
30-
"base-url": {
31+
"base": {
3132
type: url(),
3233
description:
3334
"Base URL of the public website. E.g. http://frontside.com",
@@ -36,8 +37,16 @@ await main(function* (args) {
3637
.parse(args);
3738

3839
yield* staticalize({
39-
base: new URL(options["base-url"]),
40+
base: new URL(options.base),
4041
host: new URL(options.site),
41-
dir: options.outputdir,
42+
dir: options.output,
4243
});
4344
});
45+
46+
function* version() {
47+
try {
48+
return yield* call(() => Deno.readTextFile(join(import.meta.dirname ?? "./", "VERSION")));
49+
} catch {
50+
return "0.0.0"
51+
}
52+
}

0 commit comments

Comments
 (0)