Check for new AL Language release #132
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
} |