|
3 | 3 | # Add steps that build, test, save build artifacts, deploy, and more:
|
4 | 4 | # https://aka.ms/yaml
|
5 | 5 |
|
6 |
| -pool: |
7 |
| - vmImage: 'Ubuntu 16.04' |
| 6 | +jobs: |
| 7 | + - job: |
| 8 | + timeoutInMinutes: 120 |
| 9 | + pool: |
| 10 | + vmImage: 'ubuntu-latest' |
| 11 | + |
| 12 | + steps: |
| 13 | + - checkout: self |
| 14 | + persistCredentials: 'true' |
| 15 | + clean: 'true' |
| 16 | + - task: YodLabs.VariableTasks.SetVariablesWithCredentials.SetVariablesWithCredentials@0 |
| 17 | + displayName: 'Github auth' |
| 18 | + inputs: |
| 19 | + ConnectionName: gh-push-tc-org |
| 20 | + userNameVarName: U |
| 21 | + passwordVarName: P |
| 22 | + - task: YodLabs.VariableTasks.SetVariablesWithCredentials.SetVariablesWithCredentials@0 |
| 23 | + displayName: 'Github auth PR' |
| 24 | + inputs: |
| 25 | + ConnectionName: 'gh-pac' |
| 26 | + passwordVarName: 'GITHUB_TOKEN' |
| 27 | + - task: YodLabs.VariableTasks.SetVariablesWithCredentials.SetVariablesWithCredentials@0 |
| 28 | + displayName: 'Netlify auth' |
| 29 | + inputs: |
| 30 | + ConnectionName: netlify-quartz |
| 31 | + userNameVarName: NETLIFY_SITE_ID |
| 32 | + passwordVarName: NETLIFY_AUTH_TOKEN |
| 33 | + - task: Docker@0 |
| 34 | + displayName: 'Jekyll and all Ruby steps' |
| 35 | + inputs: |
| 36 | + containerRegistryType: 'Container Registry' |
| 37 | + action: 'Run an image' |
| 38 | + # should match Gemfile: |
| 39 | + imageName: 'jekyll/builder:3.7.3' |
| 40 | + volumes: | |
| 41 | + $(build.sourcesDirectory):/srv/jekyll |
| 42 | + $(build.binariesDirectory):/srv/jekyll/_site |
| 43 | + containerCommand: 'sh -x -c "chmod a+w Gemfile.lock && bundle install && bash -e get-deps.sh && JEKYLL_ENV=production jekyll build"' |
| 44 | + detached: false |
| 45 | + - bash: | |
| 46 | + set -e |
| 47 | + # not sure why some files are root owned, maybe docker |
| 48 | + sudo chown -R $(id -u):$(id -g) $BUILD_SOURCESDIRECTORY $BUILD_BINARIESDIRECTORY |
| 49 | +
|
| 50 | + COMMIT=$(git rev-parse HEAD) |
| 51 | +
|
| 52 | + # Determine whether to publish staging or live site |
| 53 | + if [ -n "$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER" ] ; then |
| 54 | + gh_url="https://$U:[email protected]/quartz-scheduler/quartz-scheduler.org-site.git" |
| 55 | + gh_branch=gh-pages |
| 56 | + gh_source="#${SYSTEM_PULLREQUEST_PULLREQUESTNUMBER}" |
| 57 | + echo "Publishing staging from $gh_source" |
| 58 | + elif [ "$BUILD_SOURCEBRANCHNAME" == 'master' ] ; then |
| 59 | + gh_url="https://$U:[email protected]/quartz-scheduler/quartz-scheduler.github.io.git" |
| 60 | + gh_branch=master |
| 61 | + gh_source=master |
| 62 | + echo "Publishing Live site" |
| 63 | + (bash add-analytics.sh $BUILD_SOURCESDIRECTORY $BUILD_BINARIESDIRECTORY) |
| 64 | + else |
| 65 | + echo "Unknown branch to deploy: $BUILD_SOURCEBRANCHNAME" |
| 66 | + exit 5 |
| 67 | + fi |
| 68 | +
|
| 69 | + rm -rf * .git* # start clean in source directory |
| 70 | + git clone --single-branch -b $gh_branch $gh_url remote-site |
| 71 | + cd remote-site |
| 72 | + echo "Target dir:"; ls -l |
| 73 | + echo "Generated dir:"; ls -l $BUILD_BINARIESDIRECTORY |
| 74 | + rsync -a --delete --exclude .git --exclude CNAME $BUILD_BINARIESDIRECTORY/ . |
| 75 | + echo "Result:"; ls -l |
| 76 | +
|
| 77 | + git config --local user.name "autogen" |
| 78 | + git config --local user.email "[email protected]" |
| 79 | + git add -A . |
| 80 | + git status |
| 81 | + git commit -m "Autogenerated from ${gh_source} ${COMMIT}" |
| 82 | + git push $gh_url $gh_branch |
| 83 | + condition: not(eq(variables['Build.Reason'], 'PullRequest')) |
| 84 | + displayName: 'Publish' |
| 85 | + - bash: | |
| 86 | + set -xe |
| 87 | + uname -a |
| 88 | + cat /etc/*elease* |
| 89 | + npm -v |
| 90 | + node -v |
| 91 | + npm install netlify-cli |
| 92 | + du -sh $BUILD_BINARIESDIRECTORY |
| 93 | + find $BUILD_BINARIESDIRECTORY | wc -l |
| 94 | + $(npm bin)/netlify deploy -d $BUILD_BINARIESDIRECTORY --json | tee netlify.json |
| 95 | +
|
| 96 | + NETLIFY_URL=$(jq -r '.deploy_url' netlify.json) |
| 97 | + echo "Informing GitHub about deploy url: ${NETLIFY_URL}" |
| 98 | + 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" |
| 99 | +
|
| 100 | + displayName: 'Netlify Publish' |
| 101 | + condition: eq(variables['Build.Reason'], 'PullRequest') |
| 102 | +
|
8 | 103 |
|
9 |
| -steps: |
10 |
| -- checkout: self |
11 |
| - persistCredentials: 'true' |
12 |
| - clean: 'true' |
13 |
| -- task: YodLabs.VariableTasks.SetVariablesWithCredentials.SetVariablesWithCredentials@0 |
14 |
| - displayName: 'Github auth' |
15 |
| - inputs: |
16 |
| - ConnectionName: gh-push-tc-org |
17 |
| - userNameVarName: U |
18 |
| - passwordVarName: P |
19 |
| -- task: Docker@0 |
20 |
| - displayName: 'Jekyll and all Ruby steps' |
21 |
| - inputs: |
22 |
| - containerRegistryType: 'Container Registry' |
23 |
| - action: 'Run an image' |
24 |
| - # should match Gemfile: |
25 |
| - imageName: 'jekyll/builder:3.7.3' |
26 |
| - volumes: | |
27 |
| - $(build.sourcesDirectory):/srv/jekyll |
28 |
| - $(build.binariesDirectory):/srv/jekyll/_site |
29 |
| - containerCommand: 'sh -x -c "chmod a+w Gemfile.lock && bundle install && bash -e get-deps.sh && JEKYLL_ENV=production jekyll build"' |
30 |
| - detached: false |
31 |
| -- bash: | |
32 |
| - set -e |
33 |
| - # not sure why some files are root owned, maybe docker |
34 |
| - sudo chown -R $(id -u):$(id -g) $BUILD_SOURCESDIRECTORY $BUILD_BINARIESDIRECTORY |
35 |
| - COMMIT=$(git rev-parse HEAD) |
36 |
| - # Determine whether to publish staging or live site |
37 |
| - if [ -n "$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER" ] ; then |
38 |
| - echo "Not publishing staging at this time" |
39 |
| - exit 0 # do not continue. we're OK. |
40 |
| - |
41 |
| - gh_url="https://$U:[email protected]/quartz-scheduler/quartz-scheduler.org-site.git" |
42 |
| - gh_branch=gh-pages |
43 |
| - gh_source="#${SYSTEM_PULLREQUEST_PULLREQUESTNUMBER}" |
44 |
| - echo "Publishing staging from $gh_source" |
45 |
| - elif [ "$BUILD_SOURCEBRANCHNAME" == 'master' ] ; then |
46 |
| - gh_url="https://$U:[email protected]/quartz-scheduler/quartz-scheduler.github.io.git" |
47 |
| - gh_branch=master |
48 |
| - gh_source=master |
49 |
| - echo "Publishing Live site" |
50 |
| - (bash add-analytics.sh $BUILD_SOURCESDIRECTORY $BUILD_BINARIESDIRECTORY) |
51 |
| - else |
52 |
| - echo "Unknown branch to deploy: $BUILD_SOURCEBRANCHNAME" |
53 |
| - exit 5 |
54 |
| - fi |
55 |
| - rm -rf * .git* # start clean in source directory |
56 |
| - git clone --single-branch -b $gh_branch $gh_url remote-site |
57 |
| - cd remote-site |
58 |
| - echo "Target dir:"; ls -l |
59 |
| - echo "Generated dir:"; ls -l $BUILD_BINARIESDIRECTORY |
60 |
| - rsync -a --delete --exclude .git --exclude CNAME $BUILD_BINARIESDIRECTORY/ . |
61 |
| - echo "Result:"; ls -l |
62 |
| - git config --local user.name "autogen" |
63 |
| - git config --local user.email "[email protected]" |
64 |
| - git add -A . |
65 |
| - git status |
66 |
| - git commit -m "Autogenerated from ${gh_source} ${COMMIT}" |
67 |
| - git push $gh_url $gh_branch |
68 |
| - condition: not(eq(variables['Build.Reason'], 'PullRequest')) |
69 |
| - displayName: 'Publish' |
|
0 commit comments