-
Notifications
You must be signed in to change notification settings - Fork 31
170 lines (148 loc) · 6.39 KB
/
NewReleaseAL.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: Check for new AL Language release
on:
workflow_dispatch:
inputs:
update-pre-release:
description: "Update Pre-Release assets"
required: true
default: "false"
update-release:
description: "Update Release assets"
required: true
default: "false"
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get AL Languages from Marketplace
id: marketplace
uses: ./.github/actions/marketplace
- name: Get LinterCop Release Assets
id: release-assets
uses: ./.github/actions/release-assets
with:
release: "${{ github.event.inputs.update-release }}"
pre-release: "${{ github.event.inputs.update-pre-release }}"
- name: Populate new sources
id: new-sources
shell: pwsh
run: |
Write-Host "Compare differences between the AL versions of the Marketplace and the current latest Release of the LinterCop"
$marketplace = '${{ steps.marketplace.outputs.sources }}' | ConvertFrom-Json
$assets = '${{ steps.release-assets.outputs.al-versions }}' | ConvertFrom-Json
$differences = Compare-Object -ReferenceObject $marketplace.version -DifferenceObject $assets -PassThru
$newVersions = $differences | Where-Object { $_.SideIndicator -eq '<=' }
$sources = $marketplace | Where-Object { $newVersions -contains $_.version }
echo "sources=$($sources | ConvertTo-Json -Compress)" >> $env:GITHUB_OUTPUT
- name: Populate matrix for build job strategy
id: setup-build-matrix
uses: ./.github/actions/build-matrix
with:
sources: ${{ steps.new-sources.outputs.sources }}
al-version-latest: ${{ steps.marketplace.outputs.al-version-latest }}
al-version-prerelease: ${{ steps.marketplace.outputs.al-version-prerelease }}
outputs:
release-tag-name: ${{ steps.release-assets.outputs.tag-name }}
release-upload-url: ${{ steps.release-assets.outputs.upload-url }}
matrix: ${{ steps.setup-build-matrix.outputs.matrix }}
matrix-isempty: ${{ steps.setup-build-matrix.outputs.isempty }}
build:
name: Build
runs-on: ubuntu-latest
needs: setup
if: ${{ needs.setup.outputs.matrix-isempty == 'false' }}
strategy:
matrix: ${{ fromJson(needs.setup.outputs.matrix) }}
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Build artifact
id: dotnet-build
uses: ./.github/actions/dotnet-build
with:
asset-version-number: ${{ needs.setup.outputs.release-tag-name }}
asset-name: ${{ matrix.assetname }}
asset-publish: "true"
al-version-number: ${{ matrix.version }}
al-asset-uri: ${{ matrix.assetUri }}
al-latest: ${{ matrix.latest }}
al-prerelease: ${{ matrix.prerelease }}
publish:
name: Publish
runs-on: windows-latest # Code signing must run on a Windows agent for Authenticode signing (dll/exe)
needs:
- setup
- build
if: github.event_name != 'pull_request' # Exclude this job for validation on the pull-request
steps:
- uses: actions/checkout@v4
- name: Azure Login
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Download artifacts
id: download-artifacts
uses: ./.github/actions/download-artifacts
with:
path: ${{ github.workspace }}\BuildArtifacts
- name: Code Sign artifacts
id: code-sign
uses: ./.github/actions/dotnet-sign
with:
base-directory: ${{ github.workspace }}\BuildArtifacts
description: "BusinessCentral.LinterCop"
description-url: https://github.com/${{ github.repository }}
azure-key-vault-url: ${{ secrets.KEY_VAULT_URL }}
azure-key-vault-certificate: ${{ secrets.KEY_VAULT_CERTIFICATE }}
- name: Publish Assets
id: upload-release-assets
shell: pwsh
env:
ARTIFACTS_PATH: ${{ github.workspace }}\BuildArtifacts
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TAG_NAME: ${{ needs.setup.outputs.release-tag-name }}
RELEASE_UPLOAD_URL: ${{ needs.setup.outputs.release-upload-url }}
run: |
# The upload-url contains "{?name,label}" at the end, which needs to be removed
$upload_url = $env:RELEASE_UPLOAD_URL -replace '{\?name,label}', ''
Write-Host "upload-url: $($upload_url)"
# Find all the .dll files in the directory
$artifacts = Get-ChildItem -Path $env:ARTIFACTS_PATH -Depth 0 -Filter *.dll
# Define headers for GitHub API requests
$headers = @{
'Accept' = 'application/vnd.github+json'
'Authorization' = "token $env:GITHUB_TOKEN"
'X-GitHub-Api-Version' = '2022-11-28'
}
$release = Invoke-RestMethod `
-Method Get `
-Headers $headers `
-Uri "https://api.github.com/repos/${{ github.repository }}/releases/tags/$env:RELEASE_TAG_NAME" `
-UseBasicParsing
# Find existing release assets that match build artifacts name
$existingAssets = $release.assets | Where-Object { $($artifacts | ForEach-Object { $_.Name }) -contains $_.name }
# Delete the matching assets
$existingAssets | ForEach-Object {
Write-Host "Deleting existing asset $($_.name) (ID: $($_.id))..."
Invoke-RestMethod `
-Method Delete `
-Headers $headers `
-Uri "https://api.github.com/repos/${{ github.repository }}/releases/assets/$($_.id)" `
-UseBasicParsing
}
# Loop through each artifact and upload it using curl (which handles multipart form data)
$artifacts | ForEach-Object {
$asset_name = $_.Name
$asset_path = $_.FullName
Write-Host "Uploading $asset_name..."
curl -L `
-X POST `
-H "Accept: application/vnd.github+json" `
-H "Authorization: token $env:GITHUB_TOKEN" `
-H "X-GitHub-Api-Version: 2022-11-28" `
-H "Content-Type: application/octet-stream" `
"$($upload_url)?name=$($asset_name)" `
--data-binary `@"$asset_path"
}