-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathazure-pipelines.yml
145 lines (118 loc) · 4.95 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
141
142
143
144
145
trigger:
- master
pool:
vmImage: 'windows-2019'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest@2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: CopyFiles@2
displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder: '$(system.defaultworkingdirectory)'
Contents: '**\bin\$(BuildConfiguration)\**'
TargetFolder: '$(build.artifactstagingdirectory)'
- task: NuGetCommand@2
displayName: 'NuGet pack'
inputs:
command: pack
packagesToPack: '**/*.nuspec'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
- task: CmdLine@2
displayName: 'Publish to Nuget'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
inputs:
script: 'nuget push $(Build.ArtifactStagingDirectory)\**\*.nupkg -ApiKey $(NugetApiKey) -Source https://api.nuget.org/v3/index.json -SkipDuplicate -NonInteractive'
- task: Bash@3
displayName: 'Read Package Version'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
inputs:
targetType: 'inline'
script: |
read_package_version () {
local nugetFile=$(find "$(Build.ArtifactStagingDirectory)" -path "**/$1*.nupkg")
[[ $nugetFile =~ (.*)($1)(.*)(.nupkg) ]]
echo ${BASH_REMATCH[3]}
}
expose_package_version () {
echo "##vso[task.setvariable variable=$1;]$2"
}
read_and_expose_package_versions () {
expose_package_version "AUTH0_OIDCCLIENT_CORE_VERSION" $(read_package_version "Auth0.OidcClient.Core.")
expose_package_version "AUTH0_OIDCCLIENT_WPF_VERSION" $(read_package_version "Auth0.OidcClient.WPF.")
expose_package_version "AUTH0_OIDCCLIENT_WINFORMS_VERSION" $(read_package_version "Auth0.OidcClient.WinForms.")
expose_package_version "AUTH0_OIDCCLIENT_UWP_VERSION" $(read_package_version "Auth0.OidcClient.UWP.")
expose_package_version "AUTH0_OIDCCLIENT_ANDROID_VERSION" $(read_package_version "Auth0.OidcClient.Android.")
expose_package_version "AUTH0_OIDCCLIENT_ANDROIDX_VERSION" $(read_package_version "Auth0.OidcClient.AndroidX.")
expose_package_version "AUTH0_OIDCCLIENT_IOS_VERSION" $(read_package_version "Auth0.OidcClient.iOS.")
}
read_and_expose_package_versions
- task: Bash@3
displayName: 'Publish to GitHub'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
inputs:
targetType: 'inline'
script: |
create_release () {
local TAG="$1"
if ! git show-ref --tags "$TAG"; then
echo "Tag with name '$TAG' not yet published."
# Create a well-formed JSON payload to send
RELEASE_JSON=$(jq --null-input \
--arg tag "$TAG" \
'{"tag_name": $tag, "name": $tag, "body": ""}')
# POST the Release
API_URL="https://api.github.com/repos/$PROJECT_USERNAME/$PROJECT_REPONAME/releases"
STATUS_CODE=$(curl \
--output /dev/stderr \
--write-out "%{http_code}" \
-H "Accept: application/json" \
-H "Authorization: token $GH_TOKEN" \
-d "$RELEASE_JSON" \
"$API_URL"
)
if [[ "$STATUS_CODE" -lt 200 ]] || [[ "$STATUS_CODE" -gt 299 ]]; then exit "$STATUS_CODE"; fi
else
echo "Tag with name '$TAG' is already published."
fi
}
release_to_github () {
GH_TOKEN="$(GH_TOKEN)"
# Check if $GH_TOKEN is defined
if [[ -z "$GH_TOKEN" ]]; then
echo "ERROR: The 'GH_TOKEN' variable must be set to a Github access token."
exit 1
fi
# Check if the API URL can be constructed
if [[ -z "$PROJECT_USERNAME" ]] || [[ -z "$PROJECT_REPONAME" ]]; then
echo "ERROR: The variables 'PROJECT_USERNAME' and/or 'PROJECT_REPONAME' are not defined."
exit 1
fi
echo "Pulling remote tags..."
git fetch --tags
create_release "core-$AUTH0_OIDCCLIENT_CORE_VERSION"
create_release "uwp-$AUTH0_OIDCCLIENT_UWP_VERSION"
create_release "wpf-$AUTH0_OIDCCLIENT_WPF_VERSION"
create_release "winforms-$AUTH0_OIDCCLIENT_WINFORMS_VERSION"
create_release "android-$AUTH0_OIDCCLIENT_ANDROID_VERSION"
create_release "androidx-$AUTH0_OIDCCLIENT_ANDROIDX_VERSION"
create_release "ios-$AUTH0_OIDCCLIENT_IOS_VERSION"
}
release_to_github