Skip to content

Commit a3bc835

Browse files
committed
WIP
1 parent bcdafe6 commit a3bc835

File tree

6 files changed

+117
-12
lines changed

6 files changed

+117
-12
lines changed

.github/workflows/ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
on: [push, pull_request]
3+
4+
jobs:
5+
test:
6+
name: Test URLs
7+
runs-on: ubuntu-18.04
8+
9+
steps:
10+
- name: Setup Go
11+
uses: actions/setup-go@v1
12+
with:
13+
go-version: 1.13.x
14+
15+
- name: Checkout
16+
uses: actions/checkout@v1
17+
18+
- name: Test URLs on production
19+
run: go run scripts/test-urls.go https://fromcodetoprod.com/
20+
21+
- name: Setup Hugo
22+
run: make hugo
23+
24+
- name: Serve local version
25+
run: make serve &
26+
27+
- name: Wait
28+
run: sleep 1
29+
30+
- name: Test local URLs
31+
run: go run scripts/test-urls.go http://localhost:1313/

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
/hugo
21

Makefile

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,10 @@ help: ## Display this help message.
33
@grep '^[a-zA-Z]' $(MAKEFILE_LIST) | \
44
awk -F ':.*?## ' 'NF==2 {printf " %-26s%s\n", $$1, $$2}'
55

6-
hugo:
7-
wget https://github.com/gohugoio/hugo/releases/download/v0.59.1/hugo_0.59.1_macOS-64bit.tar.gz -O hugo.tar.gz
8-
echo '4f9fad9a6a8da91f016a1f566281cbe6cfc11c16d8cd215d394813e5eaa318d6 hugo.tar.gz' | shasum -a 256 -c
9-
tar -xzf hugo.tar.gz
10-
rm hugo.tar.gz
11-
./hugo version
12-
13-
build: hugo ## Build site.
6+
build: ## Build site.
147
rm -fr public
15-
./hugo
8+
docker run --rm -v $(PWD):/site fromcodetoprod/hugo:0.60.1-1
169

17-
serve: hugo ## Serve development version.
10+
serve: ## Serve development version.
1811
rm -fr public
19-
./hugo serve --buildDrafts
12+
docker run --rm -p 1313:1313 -v $(PWD):/site fromcodetoprod/hugo:0.60.1-1 serve --bind=0.0.0.0 --buildDrafts

docker/hugo/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM busybox
2+
3+
RUN wget https://github.com/gohugoio/hugo/releases/download/v0.60.1/hugo_0.60.1_Linux-64bit.tar.gz
4+
RUN echo '54efec73f8aca18a3fa90e539dbe3b3b53e5d0c802ee724b2cbc63dae2fc17d3 hugo_0.60.1_Linux-64bit.tar.gz' | sha256sum -cw
5+
RUN tar xzvf hugo_0.60.1_Linux-64bit.tar.gz hugo
6+
RUN ./hugo version
7+
RUN rm hugo_0.60.1_Linux-64bit.tar.gz
8+
9+
VOLUME /site
10+
WORKDIR /site
11+
12+
EXPOSE 1313
13+
14+
ENTRYPOINT ["/hugo"]

docker/hugo/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
all:
2+
docker build --pull --squash --tag fromcodetoprod/hugo:dev .

scripts/test-urls.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package main
2+
3+
import (
4+
"errors"
5+
"flag"
6+
"fmt"
7+
"io/ioutil"
8+
"log"
9+
"net/http"
10+
"net/url"
11+
"os"
12+
"regexp"
13+
)
14+
15+
func main() {
16+
flag.Usage = func() {
17+
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [base URL]\n", os.Args[0])
18+
flag.PrintDefaults()
19+
}
20+
flag.Parse()
21+
22+
baseURL := flag.Arg(0)
23+
if baseURL == "" {
24+
fmt.Fprintf(flag.CommandLine.Output(), "base URL argument is required.\n\n")
25+
flag.Usage()
26+
os.Exit(2)
27+
}
28+
29+
testURLs(baseURL)
30+
}
31+
32+
func testURLs(baseURL string) {
33+
u, err := url.Parse(baseURL)
34+
if err != nil {
35+
log.Fatal(err)
36+
}
37+
38+
for path, re := range map[string]*regexp.Regexp{
39+
"/episodes/index.rss": regexp.MustCompile(`^<rss`),
40+
} {
41+
url := u.ResolveReference(&url.URL{
42+
Path: path,
43+
})
44+
if err = testURL(url.String(), re); err != nil {
45+
log.Printf("%s: %s", url, err)
46+
}
47+
}
48+
}
49+
50+
func testURL(url string, re *regexp.Regexp) error {
51+
resp, err := http.Get(url)
52+
if err != nil {
53+
return err
54+
}
55+
defer resp.Body.Close()
56+
57+
b, err := ioutil.ReadAll(resp.Body)
58+
if err != nil {
59+
return err
60+
}
61+
62+
if !re.Match(b) {
63+
return errors.New("unexpected content")
64+
}
65+
return nil
66+
}

0 commit comments

Comments
 (0)