forked from Sitecore/jss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yml
140 lines (132 loc) · 5.06 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
branches:
include:
- master
- dev
- release/*
paths:
include:
- /
# should trigger builds for PRs targeting any of the listed branches
pr:
branches:
include:
- master
- dev
- release/*
paths:
include:
- /
pool:
vmImage: 'ubuntu-latest'
variables:
shouldPublish: $[or(eq(variables['Build.SourceBranch'], 'refs/heads/dev'), startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'))]
${{ if startsWith(variables['Build.SourceBranch'], 'refs/heads/') }}:
branchName: $[ replace(variables['Build.SourceBranch'], 'refs/heads/', '') ]
${{ if startsWith(variables['Build.SourceBranch'], 'refs/pull/') }}:
branchName: $[ replace(variables['System.PullRequest.SourceBranch'], 'refs/heads/', '') ]
lernaSinceFlag: "--since=origin/dev"
# disable `PublishCodeCoverageResults` report generation, as `reportgenerator` provides custom report
disable.coverage.autogenerate: 'true'
# Some steps here scaffold jss apps and check if they build and lint correctly
# build apps step currently excluded: RAV apps have issues with yarn build, nextjs has some with all builds without Sitecore connection
# TODO: add step for lerna run build --scope sample-* when RAV and nextjs yarn build issues are resolved
steps:
- task: NodeTool@0
inputs:
versionSpec: '20.x'
- script: |
yarn cache clean --all && yarn install --immutable
displayName: 'yarn install - initial'
- script: |
yarn lint-packages ${{ variables.lernaSinceFlag }}
displayName: 'lint packages'
- script: |
npm run build
displayName: 'build packages'
- script: |
yarn coverage-packages
displayName: 'running tests'
env: {
testEnv: 'ci'
}
- task: reportgenerator@5
displayName: 'generate code coverage report'
inputs:
reports: '$(System.DefaultWorkingDirectory)/**/cobertura-coverage.xml'
targetdir: '$(Build.SourcesDirectory)/coverlet'
reporttypes: 'HtmlInline_AzurePipelines;Cobertura'
verbosity: 'Verbose'
- task: PublishCodeCoverageResults@1
displayName: 'publish code coverage report'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(Build.SourcesDirectory)/coverlet/Cobertura.xml'
reportDirectory: '$(Build.SourcesDirectory)/coverlet'
- script: |
yarn scaffold-samples
displayName: 'scaffold samples'
condition: and(succeeded(), ne(variables.shouldPublish, true))
- script: |
yarn install
displayName: 'yarn install - refresh'
condition: and(succeeded(), ne(variables.shouldPublish, true))
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: false
- script: |
yarn lint-samples ${{ variables.lernaSinceFlag }}
displayName: 'lint samples'
condition: and(succeeded(), ne(variables.shouldPublish, true))
# * Configure git with a commit user
# * Update git remote to include a Personal Access Token, so lerna can push
# * Explicitly check out the current branch since Pipelines will use disconnected HEAD by default
# * Only run for 'dev' and 'release' branches
- script: |
git config user.email [email protected]
git config user.name "Automated Build"
git remote set-url origin https://[email protected]/Sitecore/jss.git
git checkout $(branchName)
displayName: 'apply git configuration'
condition: and(succeeded(), eq(variables.shouldPublish, true))
env:
GITHUB_PAT_ENV: $(GITHUB-PAT)
# Only run for 'dev' and 'release' branches
# in order to don't produce extra changes in the Pull Request
- script: |
yarn generate-docs
git add ./ref-docs/**/*
git commit -m "Update API docs [skip ci]"
displayName: 'generate API docs'
condition: and(succeeded(), eq(variables.shouldPublish, true))
#
# LERNA VERSION
# * Increment pre-release version
# * Force version update even if lerna doesn't detect changes
# * Include [skip ci] in commit message to stop pipeline from triggering again when lerna pushes
# * Only run for 'dev' and 'release' branches
#
- script: |
npm exec -- lerna version prerelease --exact --preid canary --force-publish --message "version %s [skip ci]" --yes
displayName: 'pre-release version update'
condition: and(succeeded(), eq(variables.shouldPublish, true))
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: false
#
# LERNA PUBLISH
# * Configure npm to use the provided access token, so lerna can publish
# * Do a lerna canary publish of the version we've already updated and pushed
# * Disable access verification (no-verify-access) as this doesn't seem to work behind Azure DevOps' npm proxy
# * https://github.com/lerna/lerna/issues/1685
# * Only run for 'dev' and 'release' branches
#
- script: |
echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc
npm exec -- lerna publish from-git --canary --pre-dist-tag canary --preid canary --no-verify-access --yes
displayName: 'pre-release canary publish'
condition: and(succeeded(), eq(variables.shouldPublish, true))
env:
NPM_TOKEN: $(NPM-TOKEN)