2019-03-26 09:50:54 +01:00
|
|
|
version: 2
|
|
|
|
|
jobs:
|
|
|
|
|
build:
|
|
|
|
|
docker:
|
2019-03-26 09:57:39 +01:00
|
|
|
- image: alpine:3.9.2
|
2019-03-26 09:50:54 +01:00
|
|
|
|
|
|
|
|
steps:
|
2019-03-26 09:57:39 +01:00
|
|
|
- run:
|
|
|
|
|
name: Install hugo
|
|
|
|
|
command: apk add hugo
|
|
|
|
|
|
2019-03-26 09:50:54 +01:00
|
|
|
- run:
|
|
|
|
|
name: Create site
|
|
|
|
|
command: hugo new site my-site
|
|
|
|
|
|
|
|
|
|
- run:
|
|
|
|
|
name: Clone the theme from the PR
|
|
|
|
|
working_directory: my-site
|
2019-03-26 09:57:39 +01:00
|
|
|
command: |
|
|
|
|
|
apk add git
|
|
|
|
|
git clone https://github.com/StefMa/hugo-fresh themes/hugo-fresh
|
2019-03-26 09:50:54 +01:00
|
|
|
- run:
|
|
|
|
|
working_directory: my-site/themes/hugo-fresh
|
|
|
|
|
command: |
|
2019-09-25 08:45:28 +02:00
|
|
|
isPrIfGreaterThanZero=$(expr $CIRCLE_BRANCH : "pull")
|
|
|
|
|
if [ isPrIfGreaterThanZero > 0 ]; then
|
|
|
|
|
echo "Hello World $CIRCLE_BRANCH"
|
2019-03-26 09:57:39 +01:00
|
|
|
git fetch origin ${CIRCLE_BRANCH}/head:BRANCHNAME
|
|
|
|
|
git checkout BRANCHNAME
|
|
|
|
|
else
|
2019-09-25 08:45:28 +02:00
|
|
|
echo "Hello World else $CIRCLE_BRANCH"
|
2019-03-26 09:57:39 +01:00
|
|
|
git checkout ${CIRCLE_BRANCH}
|
|
|
|
|
fi
|
2019-03-26 09:50:54 +01:00
|
|
|
|
|
|
|
|
- run:
|
|
|
|
|
name: Replace default config
|
|
|
|
|
working_directory: my-site
|
|
|
|
|
command: |
|
2019-09-25 08:45:28 +02:00
|
|
|
isPrIfGreaterThanZero=$(expr $CIRCLE_BRANCH : "pull")
|
|
|
|
|
if [ isPrIfGreaterThanZero > 0 ]; then
|
|
|
|
|
branch=${CIRCLE_SHA1}
|
2019-06-06 11:34:45 +02:00
|
|
|
else
|
|
|
|
|
branch=${CIRCLE_BRANCH}
|
|
|
|
|
fi
|
2019-03-26 09:50:54 +01:00
|
|
|
rm config.toml
|
2019-03-26 09:57:39 +01:00
|
|
|
apk add curl
|
2019-06-06 11:34:45 +02:00
|
|
|
curl https://codeload.github.com/stefma/hugo-fresh/tar.gz/$branch | tar -xz --strip=2 hugo-fresh-$branch/exampleSite/
|
2019-03-26 09:57:39 +01:00
|
|
|
- run:
|
|
|
|
|
name: Replace baseUrl in config
|
|
|
|
|
working_directory: my-site
|
|
|
|
|
command: |
|
|
|
|
|
apk add sed
|
2019-09-25 08:45:28 +02:00
|
|
|
URL=hugo-fresh-$(echo $CIRCLE_BRANCH | tr _ - | tr / -)
|
2019-03-26 09:57:39 +01:00
|
|
|
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
|
2019-03-26 09:50:54 +01:00
|
|
|
|
|
|
|
|
- run:
|
|
|
|
|
name: Create hugo site
|
|
|
|
|
working_directory: my-site
|
|
|
|
|
command: hugo
|
2019-03-26 09:57:39 +01:00
|
|
|
|
2019-03-26 09:50:54 +01:00
|
|
|
- run:
|
2019-03-26 09:57:39 +01:00
|
|
|
name: Create now.json
|
|
|
|
|
working_directory: my-site/public
|
2019-03-26 09:50:54 +01:00
|
|
|
command: |
|
2019-09-25 08:45:28 +02:00
|
|
|
URL=hugo-fresh-$(echo $CIRCLE_BRANCH | tr _ - | tr / -)
|
2019-03-26 09:57:39 +01:00
|
|
|
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: |
|
2019-10-02 10:42:50 +02:00
|
|
|
apk add --update npm
|
|
|
|
|
npm install -g now@16.3.0
|
2019-03-26 09:57:39 +01:00
|
|
|
- run:
|
|
|
|
|
name: Publish to now.sh
|
|
|
|
|
working_directory: my-site/public
|
|
|
|
|
command: now --target production --token ${NOW_TOKEN}
|