-
Notifications
You must be signed in to change notification settings - Fork 37
/
azure-pipelines.yml
106 lines (98 loc) · 4.6 KB
/
azure-pipelines.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Jekyll site
# Package your Jekyll site using the jekyll/builder Docker container image.
# Add steps that build, test, save build artifacts, deploy, and more:
# https://aka.ms/yaml
jobs:
- job:
timeoutInMinutes: 120
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: self
persistCredentials: 'true'
clean: 'true'
- task: SetVariablesWithCredentials@0
displayName: 'Github auth'
inputs:
ConnectionName: gh-push-tc-org
userNameVarName: U
passwordVarName: P
- task: SetVariablesWithCredentials@0
displayName: 'Github auth PR'
inputs:
ConnectionName: 'gh-pac'
passwordVarName: 'GITHUB_TOKEN'
- task: SetVariablesWithCredentials@0
displayName: 'Netlify auth'
inputs:
ConnectionName: netlify-ehcache
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 "apk add --no-cache fontconfig ttf-freefont && bundle install && bash -e get-deps.sh && JEKYLL_ENV=production jekyll build && bundle exec htmlproofer --only-4xx --empty-alt-ignore --check-html --checks-to-ignore ImageCheck --file-ignore \"/apidocs/,/generated/\" --log-level debug _site"'
containerCommand: 'sh -x -c "apk add --no-cache fontconfig ttf-freefont && 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]/ehcache/ehcache.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]/ehcache/ehcache.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 ; du -sh
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)
if [ -n "$NETLIFY_URL" ] ; then
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/ehcache/ehcache.org-site/issues/${SYSTEM_PULLREQUEST_PULLREQUESTNUMBER}/comments"
else
echo "Failed to deploy to netlify for preview"
fi
displayName: 'Netlify Publish'
condition: eq(variables['Build.Reason'], 'PullRequest')