Skip to content

Commit

Permalink
Merge pull request #61 from chrisdennis/netlify-integration
Browse files Browse the repository at this point in the history
Generate Netlify previews for PRs
  • Loading branch information
akomakom authored Oct 28, 2019
2 parents 94f5ac5 + 0569dcc commit 1f1eb3c
Showing 1 changed file with 97 additions and 63 deletions.
160 changes: 97 additions & 63 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,101 @@
# Add steps that build, test, save build artifacts, deploy, and more:
# https://aka.ms/yaml

pool:
vmImage: 'Ubuntu 16.04'
jobs:
- job:
timeoutInMinutes: 120
pool:
vmImage: 'ubuntu-latest'

steps:
- checkout: self
persistCredentials: 'true'
clean: 'true'
- task: YodLabs.VariableTasks.SetVariablesWithCredentials.SetVariablesWithCredentials@0
displayName: 'Github auth'
inputs:
ConnectionName: gh-push-tc-org
userNameVarName: U
passwordVarName: P
- task: YodLabs.VariableTasks.SetVariablesWithCredentials.SetVariablesWithCredentials@0
displayName: 'Github auth PR'
inputs:
ConnectionName: 'gh-pac'
passwordVarName: 'GITHUB_TOKEN'
- task: YodLabs.VariableTasks.SetVariablesWithCredentials.SetVariablesWithCredentials@0
displayName: 'Netlify auth'
inputs:
ConnectionName: netlify-quartz
userNameVarName: NETLIFY_SITE_ID
passwordVarName: NETLIFY_AUTH_TOKEN
- task: Docker@0
displayName: 'Jekyll and all Ruby steps'
inputs:
containerRegistryType: 'Container Registry'
action: 'Run an image'
# should match Gemfile:
imageName: 'jekyll/builder:3.7.3'
volumes: |
$(build.sourcesDirectory):/srv/jekyll
$(build.binariesDirectory):/srv/jekyll/_site
containerCommand: 'sh -x -c "chmod a+w Gemfile.lock && bundle install && bash -e get-deps.sh && JEKYLL_ENV=production jekyll build"'
detached: false
- bash: |
set -e
# not sure why some files are root owned, maybe docker
sudo chown -R $(id -u):$(id -g) $BUILD_SOURCESDIRECTORY $BUILD_BINARIESDIRECTORY
COMMIT=$(git rev-parse HEAD)
# Determine whether to publish staging or live site
if [ -n "$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER" ] ; then
gh_url="https://$U:[email protected]/quartz-scheduler/quartz-scheduler.org-site.git"
gh_branch=gh-pages
gh_source="#${SYSTEM_PULLREQUEST_PULLREQUESTNUMBER}"
echo "Publishing staging from $gh_source"
elif [ "$BUILD_SOURCEBRANCHNAME" == 'master' ] ; then
gh_url="https://$U:[email protected]/quartz-scheduler/quartz-scheduler.github.io.git"
gh_branch=master
gh_source=master
echo "Publishing Live site"
(bash add-analytics.sh $BUILD_SOURCESDIRECTORY $BUILD_BINARIESDIRECTORY)
else
echo "Unknown branch to deploy: $BUILD_SOURCEBRANCHNAME"
exit 5
fi
rm -rf * .git* # start clean in source directory
git clone --single-branch -b $gh_branch $gh_url remote-site
cd remote-site
echo "Target dir:"; ls -l
echo "Generated dir:"; ls -l $BUILD_BINARIESDIRECTORY
rsync -a --delete --exclude .git --exclude CNAME $BUILD_BINARIESDIRECTORY/ .
echo "Result:"; ls -l
git config --local user.name "autogen"
git config --local user.email "[email protected]"
git add -A .
git status
git commit -m "Autogenerated from ${gh_source} ${COMMIT}"
git push $gh_url $gh_branch
condition: not(eq(variables['Build.Reason'], 'PullRequest'))
displayName: 'Publish'
- bash: |
set -xe
uname -a
cat /etc/*elease*
npm -v
node -v
npm install netlify-cli
du -sh $BUILD_BINARIESDIRECTORY
find $BUILD_BINARIESDIRECTORY | wc -l
$(npm bin)/netlify deploy -d $BUILD_BINARIESDIRECTORY --json | tee netlify.json
NETLIFY_URL=$(jq -r '.deploy_url' netlify.json)
echo "Informing GitHub about deploy url: ${NETLIFY_URL}"
curl -H "Authorization: token ${GITHUB_TOKEN}" -X POST -d "{\"body\": \"[A Live Preview](${NETLIFY_URL}) of this Pull Request at commit ${SYSTEM_PULLREQUEST_SOURCECOMMITID} is now available\", \"commit_id\": \"${SYSTEM_PULLREQUEST_SOURCECOMMITID}\"}" "https://api.github.com/repos/quartz-scheduler/quartz-scheduler.org-site/issues/${SYSTEM_PULLREQUEST_PULLREQUESTNUMBER}/comments"
displayName: 'Netlify Publish'
condition: eq(variables['Build.Reason'], 'PullRequest')
steps:
- checkout: self
persistCredentials: 'true'
clean: 'true'
- task: YodLabs.VariableTasks.SetVariablesWithCredentials.SetVariablesWithCredentials@0
displayName: 'Github auth'
inputs:
ConnectionName: gh-push-tc-org
userNameVarName: U
passwordVarName: P
- task: Docker@0
displayName: 'Jekyll and all Ruby steps'
inputs:
containerRegistryType: 'Container Registry'
action: 'Run an image'
# should match Gemfile:
imageName: 'jekyll/builder:3.7.3'
volumes: |
$(build.sourcesDirectory):/srv/jekyll
$(build.binariesDirectory):/srv/jekyll/_site
containerCommand: 'sh -x -c "chmod a+w Gemfile.lock && bundle install && bash -e get-deps.sh && JEKYLL_ENV=production jekyll build"'
detached: false
- bash: |
set -e
# not sure why some files are root owned, maybe docker
sudo chown -R $(id -u):$(id -g) $BUILD_SOURCESDIRECTORY $BUILD_BINARIESDIRECTORY
COMMIT=$(git rev-parse HEAD)
# Determine whether to publish staging or live site
if [ -n "$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER" ] ; then
echo "Not publishing staging at this time"
exit 0 # do not continue. we're OK.
gh_url="https://$U:[email protected]/quartz-scheduler/quartz-scheduler.org-site.git"
gh_branch=gh-pages
gh_source="#${SYSTEM_PULLREQUEST_PULLREQUESTNUMBER}"
echo "Publishing staging from $gh_source"
elif [ "$BUILD_SOURCEBRANCHNAME" == 'master' ] ; then
gh_url="https://$U:[email protected]/quartz-scheduler/quartz-scheduler.github.io.git"
gh_branch=master
gh_source=master
echo "Publishing Live site"
(bash add-analytics.sh $BUILD_SOURCESDIRECTORY $BUILD_BINARIESDIRECTORY)
else
echo "Unknown branch to deploy: $BUILD_SOURCEBRANCHNAME"
exit 5
fi
rm -rf * .git* # start clean in source directory
git clone --single-branch -b $gh_branch $gh_url remote-site
cd remote-site
echo "Target dir:"; ls -l
echo "Generated dir:"; ls -l $BUILD_BINARIESDIRECTORY
rsync -a --delete --exclude .git --exclude CNAME $BUILD_BINARIESDIRECTORY/ .
echo "Result:"; ls -l
git config --local user.name "autogen"
git config --local user.email "[email protected]"
git add -A .
git status
git commit -m "Autogenerated from ${gh_source} ${COMMIT}"
git push $gh_url $gh_branch
condition: not(eq(variables['Build.Reason'], 'PullRequest'))
displayName: 'Publish'

0 comments on commit 1f1eb3c

Please sign in to comment.