version: 2 jobs: build: docker: - image: alpine:3.10.2 steps: - run: name: Install hugo command: apk add hugo - run: name: Create site command: hugo new site my-site - run: name: Clone the theme from the PR working_directory: my-site command: | apk add git git clone https://github.com/StefMa/hugo-fresh themes/hugo-fresh - run: working_directory: my-site/themes/hugo-fresh command: | isPrIfGreaterThanZero=$(expr $CIRCLE_BRANCH : "pull") if [ isPrIfGreaterThanZero > 0 ]; then echo "Hello World $CIRCLE_BRANCH" git fetch origin ${CIRCLE_BRANCH}/head:BRANCHNAME git checkout BRANCHNAME else echo "Hello World else $CIRCLE_BRANCH" git checkout ${CIRCLE_BRANCH} fi - run: name: Replace default config working_directory: my-site command: | isPrIfGreaterThanZero=$(expr $CIRCLE_BRANCH : "pull") if [ isPrIfGreaterThanZero > 0 ]; then branch=${CIRCLE_SHA1} else branch=${CIRCLE_BRANCH} fi rm config.toml apk add curl curl https://codeload.github.com/stefma/hugo-fresh/tar.gz/$branch | tar -xz --strip=2 hugo-fresh-$branch/exampleSite/ - run: name: Replace baseUrl in config working_directory: my-site command: | apk add sed URL=hugo-fresh-$(echo $CIRCLE_BRANCH | tr _ - | tr / -) if [ $CIRCLE_BRANCH == "master" ]; then URL=hugo-fresh fi sed -i "s,http://something-fresh.org,https://${URL}.now.sh,g" config.yaml cat config.yaml - run: name: Create hugo site working_directory: my-site command: hugo - run: name: Create now.json working_directory: my-site/public command: | URL=hugo-fresh-$(echo $CIRCLE_BRANCH | tr _ - | tr / -) if [ $CIRCLE_BRANCH == "master" ]; then URL=hugo-fresh fi echo "{ \"version\": 2, \"name\": \"hugo-fresh\", \"alias\": \"${URL}\", \"builds\": [{ \"src\": \"**\", \"use\": \"@now/static\" }] }" >> now.json - run: name: Install now CLI command: | apk add --update npm npm config set unsafe-perm true npm install -g now@16.3.0 - run: name: Publish to now.sh working_directory: my-site/public command: now --target production --token ${NOW_TOKEN}