-
Notifications
You must be signed in to change notification settings - Fork 1
136 lines (113 loc) · 5 KB
/
build.yml
File metadata and controls
136 lines (113 loc) · 5 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
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
# For more information on GitHub Actions, refer to https://github.com/features/actions
name: Build
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
inputs:
release:
description: 'Publish extension to the Visual Studio Marketplace?'
required: true
default: 'false'
jobs:
build:
strategy:
matrix:
configuration: [Debug, Release]
runs-on: windows-latest
# For a list of available runner types, refer to
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
permissions:
# Write access is required to publish artifacts as Github Releases
contents: write
env:
Solution_Name: .\src\MigratePackagesConfigToPackageReferences.sln
steps:
- name: Set version number
run: |
$majorVersion = 1
$minorVersion = 0
$firstBuildYear = 2024
$currentDate = Get-Date
$currentDate = $currentDate.ToUniversalTime()
$currentYear = $currentDate.ToString("yyyy")
$buildYear = [Convert]::ToInt32($currentYear)
$currentMonthDay = $currentDate.ToString("MMdd")
$buildVersion = (($buildYear - $firstBuildYear) * 1200) + ([Convert]::ToInt32($currentMonthDay))
echo "VERSION=$majorVersion.$minorVersion.$buildVersion.${{ github.RUN_NUMBER }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf-8 -Append
- name: Read environmental variables
run: |
echo VERSION=${{ env.VERSION }}
echo GITHUB_WORKSPACE=${{ github.WORKSPACE }}
- name: Checkout
uses: actions/checkout@v4
- name: Update vsixmanifest files
run: |
$files = Get-ChildItem "${{ github.WORKSPACE }}" -recurse -include "source.extension.vsixmanifest"
if (-not $files)
{
Write-Host "Didn't find any files to update."
exit 1
}
else
{
foreach ($file in $files) {
$xml = [xml](Get-Content($file))
attrib $file -r
$node = $xml.PackageManifest.Metadata.Identity
$node.Version = "${{ env.VERSION }}"
$xml.Save($file)
Write-Host "Version applied to '$file'"
}
}
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v2
# Adds MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Restore NuGet packages
run: msbuild $env:Solution_Name /t:Restore /p:Configuration=${{matrix.Configuration}}
- name: Build
run: msbuild $env:Solution_Name /p:Configuration=${{matrix.Configuration}}
- name: Upload build artifacts
uses: actions/upload-artifact@v4
# https://github.com/marketplace/actions/upload-a-build-artifact
with:
name: MigratePackagesConfigToPackageReferencesExtension-${{ env.VERSION }} ${{matrix.Configuration}}
path: .\src\MigratePackagesConfigToPackageReferencesExtension\bin\${{matrix.Configuration}}\MigratePackagesConfigToPackageReferencesExtension.vsix
if-no-files-found: error
- name: Publish GitHub Release
if: ${{ matrix.Configuration == 'Release' && github.event.inputs.release == 'true' }}
uses: softprops/action-gh-release@v2.0.8
with:
name: v${{ env.VERSION }}
tag_name: v${{ env.VERSION }}
generate_release_notes: true
draft: true
prerelease: false
fail_on_unmatched_files: true
files: |
./src/MigratePackagesConfigToPackageReferencesExtension/bin/${{matrix.Configuration}}/MigratePackagesConfigToPackageReferencesExtension.vsix
- name: Publish to Open VSIX
if: ${{ matrix.Configuration == 'Release' && github.event.inputs.release == 'true' }}
run: |
[Reflection.Assembly]::LoadWithPartialName("System.Web") | Out-Null
$vsixFile = ".\src\MigratePackagesConfigToPackageReferencesExtension\bin\${{matrix.Configuration}}\MigratePackagesConfigToPackageReferencesExtension.vsix"
$url = "https://www.vsixgallery.com/api/upload"
[byte[]]$bytes = [System.IO.File]::ReadAllBytes($vsixFile)
try {
$webclient = New-Object System.Net.WebClient
$webclient.UploadFile($url, $vsixFile) | Out-Null
'OK' | Write-Host -ForegroundColor Green
}
catch{
'FAIL' | Write-Error
$_.Exception.Response.Headers["x-error"] | Write-Error
}
- name: Publish extension to the Visual Studio Marketplace
if: ${{ matrix.Configuration == 'Release' && github.event.inputs.release == 'true' }}
uses: cezarypiatek/VsixPublisherAction@1.1
with:
extension-file: .\src\MigratePackagesConfigToPackageReferencesExtension\bin\${{matrix.Configuration}}\MigratePackagesConfigToPackageReferencesExtension.vsix
publish-manifest-file: .\src\MigratePackagesConfigToPackageReferencesExtension\publishManifest.json
personal-access-code: ${{ secrets.VS_PUBLISHER_ACCESS_TOKEN }}