-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathazure-pipelines.yml
More file actions
84 lines (70 loc) · 2.49 KB
/
azure-pipelines.yml
File metadata and controls
84 lines (70 loc) · 2.49 KB
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
pool:
vmImage: 'windows-latest'
variables:
- group: 'github-config'
stages:
- stage: collect
displayName: Collect Data
jobs:
- job: collect_data
displayName: Archive and Publish
steps:
- checkout: self
- task: ArchiveFiles@2
displayName: 'Create Zip archive'
inputs:
rootFolderOrFile: 'src'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/OpenHolidaysApi.Data.zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts@1
displayName: 'Publish build artifacts'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
- stage: github
displayName: Publish Data
dependsOn: collect
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
jobs:
- job: push_to_github
displayName: Push Data to GitHub
steps:
- checkout: self
fetchTags: true
fetchDepth: 0
- task: PowerShell@2
displayName: 'Push to GitHub'
inputs:
targetType: 'inline'
pwsh: true
script: |
$ErrorActionPreference = 'Stop'
try {
# Configure Git identity
git config user.name 'azure-devops-bot'
git config user.email 'azuredevops@stueber.nomail'
# Add 'github' remote
git remote add github "https://$($env:PAT)@github.com/openpotato/openholidaysapi.data.git"
# Fetch remote main if it exists (ok to fail if repo is empty)
git fetch --prune github main
$fetchCode = $LASTEXITCODE
# If remote branch exists, only push when remote is an ancestor of HEAD (fast-forward safe)
if ($fetchCode -eq 0) {
git merge-base --is-ancestor github/main HEAD
if ($LASTEXITCODE -ne 0) {
Write-Error "Remote has commits not in local (or histories diverged). Aborting push."
}
}
# Push only the main branch (fast-forward or create remote if missing)
git push --tags github HEAD:refs/heads/main
if ($LASTEXITCODE -ne 0) { throw "git push failed with exit code $LASTEXITCODE" }
}
finally {
# Remove the remote so the PAT isn't left in .git/config
git remote remove github 2>$null | Out-Null
}
env:
PAT: $(PAT)