-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup version handling, pipelines, updated readme
- Loading branch information
Showing
7 changed files
with
166 additions
and
11 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,15 @@ | ||
name: Simple Go Pipeline - release | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v[0-9]+.[0-9]+.[0-9]+' | ||
jobs: | ||
call-workflow: | ||
uses: baalimago/simple-go-pipeline/.github/workflows/[email protected] | ||
with: | ||
go-version: '1.22' | ||
project-name: wd-40 | ||
branch: main | ||
version-var: "github.com/baalimago/wd-40/cmd/version.BUILD_VERSION" | ||
|
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,13 @@ | ||
name: Simple Go Pipeline - validate | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
call-workflow: | ||
uses: baalimago/simple-go-pipeline/.github/workflows/validate.yml@main | ||
with: | ||
go-version: '1.22' |
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 |
---|---|---|
@@ -1,6 +1,55 @@ | ||
# (W)eb (D)evelopment-(40) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/baalimago/wd-40)](https://goreportcard.com/report/github.com/baalimago/wd-40) | ||
[![wakatime](https://wakatime.com/badge/user/018cc8d2-3fd9-47ef-81dc-e4ad645d5f34/project/3bc921ec-dc23-4222-bf00-578f2eda0cbd.svg)](https://wakatime.com/badge/user/018cc8d2-3fd9-47ef-81dc-e4ad645d5f34/project/3bc921ec-dc23-4222-bf00-578f2eda0cbd) | ||
|
||
This is a static webserver which auto-reloads HTML files on any local filechanges. | ||
Test coverage: | ||
|
||
This is a static webserver which hot-reloads your web-browser on any local filechanges. | ||
|
||
## Usage | ||
`wd-40 serve <relative directory>` or `wd-40 serve` | ||
`wd-40 s|serve <relative directory>` or `wd-40 s|serve` | ||
|
||
## Architecture | ||
1. First the content of the website is copied to a temporary directory | ||
1. At every file, the MIME type is inspected, if it's text/html, a `delta-streamer.js` script is injected | ||
1. The web server is started, hosting the _mirrored_ content | ||
1. The `delta-streamer.js` in turn sets up a websocket connection to wd-40 | ||
1. The original file system is monitored, on any file changes: | ||
1. the new file is copied to the mirror | ||
1. the file name is propagated to the browser via the websocket | ||
1. if the browser's origin matches the recently updated file, the browser is told to reload via javascript | ||
|
||
``` | ||
┌───────────────┐ | ||
│ Web Developer │ | ||
└───────┬───────┘ | ||
│ | ||
[writes <content>] | ||
│ | ||
▼ | ||
┌─────────────────────────────┐ ┌─────────────────────┐ | ||
│ website-directory/<content> │ │ file system notify │ | ||
└─────────────┬───────────────┘ └─────────┬───────────┘ | ||
│ │ | ||
│ [update mirrored content] | ||
▼ │ | ||
┌────────────────────┐ │ | ||
│ ws-script injector │◄──────────────────────┘ | ||
└─────────┬──────────┘ | ||
│ | ||
│ | ||
▼ | ||
┌────────────────────────┐ | ||
│ tmp-abcd1234/<content> │ | ||
└───────────┬────────────┘ | ||
│ | ||
[serves <content>] | ||
│ ┌────────────────────────┐ | ||
▼ │ Browser │ | ||
┌──────────────────────────────┐ │ │ | ||
│ Web Server │ │ ┌────┐ ┌───────────┐ │ | ||
│ [localhost:<port>/<content>] │◄───[reload────┼─►│ ws │ │ <content> │ │ | ||
└──────────────────────────────┘ page] │ └────┘ └───────────┘ │ | ||
│ │ | ||
└────────────────────────┘ | ||
``` |
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,59 @@ | ||
package version | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"flag" | ||
"fmt" | ||
"runtime/debug" | ||
) | ||
|
||
// Set with buildflag if built in pipeline and not using go install | ||
var ( | ||
BUILD_VERSION = "" | ||
BUILD_CHECKSUM = "" | ||
) | ||
|
||
type command struct{} | ||
|
||
// Describe the version command | ||
func (c command) Describe() string { | ||
return "print the version of wd-40" | ||
} | ||
|
||
// Flagset for version, currently empty | ||
func (c command) Flagset() *flag.FlagSet { | ||
return flag.NewFlagSet("version", flag.ExitOnError) | ||
} | ||
|
||
// Help by printing out help | ||
func (c command) Help() string { | ||
return "Print the version of wd-40" | ||
} | ||
|
||
// Run the command, printing the version using either the debugbuild or tagged version | ||
func (c command) Run(context.Context) error { | ||
bi, ok := debug.ReadBuildInfo() | ||
if !ok { | ||
return errors.New("failed to read build info") | ||
} | ||
version := bi.Main.Version | ||
checksum := bi.Main.Sum | ||
if version == "" || version == "(devel)" { | ||
version = BUILD_VERSION | ||
} | ||
if checksum == "" { | ||
checksum = BUILD_CHECKSUM | ||
} | ||
fmt.Printf("version: %v, go version: %v, checksum: %v\n", version, bi.GoVersion, checksum) | ||
return nil | ||
} | ||
|
||
// Setup the command | ||
func (c command) Setup() error { | ||
return nil | ||
} | ||
|
||
func Command() *command { | ||
return &command{} | ||
} |
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 @@ | ||
package internal |