Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi committed Dec 8, 2019
1 parent bcdafe6 commit a3bc835
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 12 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI
on: [push, pull_request]

jobs:
test:
name: Test URLs
runs-on: ubuntu-18.04

steps:
- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: 1.13.x

- name: Checkout
uses: actions/checkout@v1

- name: Test URLs on production
run: go run scripts/test-urls.go https://fromcodetoprod.com/

- name: Setup Hugo
run: make hugo

- name: Serve local version
run: make serve &

- name: Wait
run: sleep 1

- name: Test local URLs
run: go run scripts/test-urls.go http://localhost:1313/
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/hugo

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

hugo:
wget https://github.com/gohugoio/hugo/releases/download/v0.59.1/hugo_0.59.1_macOS-64bit.tar.gz -O hugo.tar.gz
echo '4f9fad9a6a8da91f016a1f566281cbe6cfc11c16d8cd215d394813e5eaa318d6 hugo.tar.gz' | shasum -a 256 -c
tar -xzf hugo.tar.gz
rm hugo.tar.gz
./hugo version

build: hugo ## Build site.
build: ## Build site.
rm -fr public
./hugo
docker run --rm -v $(PWD):/site fromcodetoprod/hugo:0.60.1-1

serve: hugo ## Serve development version.
serve: ## Serve development version.
rm -fr public
./hugo serve --buildDrafts
docker run --rm -p 1313:1313 -v $(PWD):/site fromcodetoprod/hugo:0.60.1-1 serve --bind=0.0.0.0 --buildDrafts
14 changes: 14 additions & 0 deletions docker/hugo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM busybox

RUN wget https://github.com/gohugoio/hugo/releases/download/v0.60.1/hugo_0.60.1_Linux-64bit.tar.gz
RUN echo '54efec73f8aca18a3fa90e539dbe3b3b53e5d0c802ee724b2cbc63dae2fc17d3 hugo_0.60.1_Linux-64bit.tar.gz' | sha256sum -cw
RUN tar xzvf hugo_0.60.1_Linux-64bit.tar.gz hugo
RUN ./hugo version
RUN rm hugo_0.60.1_Linux-64bit.tar.gz

VOLUME /site
WORKDIR /site

EXPOSE 1313

ENTRYPOINT ["/hugo"]
2 changes: 2 additions & 0 deletions docker/hugo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all:
docker build --pull --squash --tag fromcodetoprod/hugo:dev .
66 changes: 66 additions & 0 deletions scripts/test-urls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package main

import (
"errors"
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"regexp"
)

func main() {
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [base URL]\n", os.Args[0])
flag.PrintDefaults()
}
flag.Parse()

baseURL := flag.Arg(0)
if baseURL == "" {
fmt.Fprintf(flag.CommandLine.Output(), "base URL argument is required.\n\n")
flag.Usage()
os.Exit(2)
}

testURLs(baseURL)
}

func testURLs(baseURL string) {
u, err := url.Parse(baseURL)
if err != nil {
log.Fatal(err)
}

for path, re := range map[string]*regexp.Regexp{
"/episodes/index.rss": regexp.MustCompile(`^<rss`),
} {
url := u.ResolveReference(&url.URL{
Path: path,
})
if err = testURL(url.String(), re); err != nil {
log.Printf("%s: %s", url, err)
}
}
}

func testURL(url string, re *regexp.Regexp) error {
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()

b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}

if !re.Match(b) {
return errors.New("unexpected content")
}
return nil
}

0 comments on commit a3bc835

Please sign in to comment.