diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5d406ce --- /dev/null +++ b/.github/workflows/ci.yml @@ -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/ diff --git a/.gitignore b/.gitignore index 36678c7..8b13789 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -/hugo diff --git a/Makefile b/Makefile index c2040ec..14935e0 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/docker/hugo/Dockerfile b/docker/hugo/Dockerfile new file mode 100644 index 0000000..55727c4 --- /dev/null +++ b/docker/hugo/Dockerfile @@ -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"] diff --git a/docker/hugo/Makefile b/docker/hugo/Makefile new file mode 100644 index 0000000..61da2df --- /dev/null +++ b/docker/hugo/Makefile @@ -0,0 +1,2 @@ +all: + docker build --pull --squash --tag fromcodetoprod/hugo:dev . diff --git a/scripts/test-urls.go b/scripts/test-urls.go new file mode 100644 index 0000000..46de461 --- /dev/null +++ b/scripts/test-urls.go @@ -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(`^