Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync workflows and scripts from BCApps #25281

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 50 additions & 54 deletions .github/workflows/CreateBuildTag.yaml
Original file line number Diff line number Diff line change
@@ -1,54 +1,50 @@
name: 'Create Build Tag'

on:
workflow_run:
workflows: [' CI/CD']
types: ['completed']
branches: ['main', 'release/*']

run-name: Create build tag on branch ${{ github.ref_name }}.

jobs:
TagSuccessfulBuild:
if: github.event.workflow_run.conclusion == 'success' && github.repository_owner == 'microsoft'
runs-on: windows-latest
steps:
- name: Create version tag
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Query all artifacts from the build workflow
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});

if(!allArtifacts) {
console.log(`Could not fetch artifacts from run ID ${context.payload.workflow_run.id}`)
return;
}

// Determine the build number, based on the apps artifact name
const appsArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name.match(/.*-Apps-.*/)
})[0];

if(!appsArtifact) {
console.log(`Could not find apps artifact from run ID ${context.payload.workflow_run.id}`)
return;
}

// The build number is after -Apps-
const buildNumber = appsArtifact.name.replace(/.*-Apps-/, "")
const tag = `refs/tags/builds/${buildNumber}`

console.log(`Creating tag: ${tag}`)

github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: tag,
sha: context.sha
});
name: 'Create Build Tag'

on:
workflow_run:
workflows: [' CI/CD']
types: [completed]
branches: ['main']

run-name: "[${{ github.ref_name }}] Create build tag"

permissions:
contents: write

jobs:
CreateTag:
if: github.event.workflow_run.conclusion == 'success'
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Get Build Version
id: GetBuildVersion
env:
buildNumber: ${{ github.event.workflow_run.run_number }}
run: |
Import-Module ".\build\scripts\EnlistmentHelperFunctions.psm1"
$majorMinor = Get-ConfigValue -ConfigType "AL-GO" -Key RepoVersion
$buildVersion = "$($majorMinor).$($env:buildNumber)"
Write-Host "Build Version: $buildVersion"
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "BuildVersion=$buildVersion"

- name: Create version tag
uses: actions/github-script@v6
env:
BuildVersion: ${{ steps.GetBuildVersion.outputs.BuildVersion}}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const {BuildVersion} = process.env
const tag = `refs/tags/builds/${BuildVersion}`

console.log(`Creating tag: ${tag}`)

github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: tag,
sha: context.sha
});
54 changes: 0 additions & 54 deletions .github/workflows/PublishNuget.yaml

This file was deleted.

18 changes: 10 additions & 8 deletions Build/Scripts/AppTranslations.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,26 @@ function Restore-TranslationsForApp {
# Translations need to be restored in the Translations folder in the app folder
$appTranslationsFolder = Join-Path $AppProjectFolder "Translations"
New-Directory -Path "$appTranslationsFolder" -ForceEmpty

$appName = (Get-ChildItem -Path $AppProjectFolder -Filter "app.json" | Get-Content | ConvertFrom-Json).name

Write-Host "Restoring translations for app $appName in $appTranslationsFolder"

$translationsOutputFolder = Join-Path (Get-BaseFolder) "out/translations/"
$translationPackagePath = Install-PackageFromConfig -PackageName "Microsoft.Dynamics.BusinessCentral.Translations" -OutputPath $translationsOutputFolder
$tranlationsPath = Join-Path $translationPackagePath "Translations"

$translationsFound = $false

# Copy the translations from the package to the app folder
Get-ChildItem $tranlationsPath -Filter *-* -Directory | ForEach-Object {
$localeFolder = $_.FullName
$locale = $_.Name

$translationFolders = Get-ChildItem $tranlationsPath -Filter *-* -Directory

foreach($translationFolder in $translationFolders) {
$localeFolder = $translationFolder.FullName
$locale = $translationFolder.Name

# Translations are located in the ExtensionsV2 folder
$translationFilePath = Join-Path $localeFolder "ExtensionsV2/$appName.$locale.xlf"
$translationFilePath = Join-Path $localeFolder "ExtensionsV2/$appName.$locale.xlf"
if(Test-Path $translationFilePath) {
Write-Host "Using translation for $appName in locale $locale."
$translationsFound = $true
Expand Down
43 changes: 43 additions & 0 deletions Build/Scripts/AutomatedSubmission.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,45 @@ function New-TopicBranch
return $BranchName
}

function New-TopicBranchIfNeeded
{
param
(
[Parameter(Mandatory=$true)]
[string] $Repository,
[Parameter(Mandatory=$true, ParameterSetName = 'BranchName')]
[string] $BranchName,
[Parameter(Mandatory=$true, ParameterSetName = 'Category')]
[string] $Category,
[Parameter(Mandatory=$false)]
[string] $PullRequestTitle
)
$openPullRequests = gh api "/repos/$Repository/pulls" --method GET -f state=open | ConvertFrom-Json

$openPullRequests = $openPullRequests | Where-Object { $_.head.ref -match $Category }
if ($PullRequestTitle) {
$openPullRequests = $openPullRequests | Where-Object { $_.title -eq $PullRequestTitle }
}

$existingPullRequest = $openPullRequests | Select-Object -First 1

if ($existingPullRequest) {
$BranchName = $existingPullRequest.head.ref
git fetch origin $BranchName
git checkout $BranchName | Out-Null
} else {
$BranchName = New-TopicBranch -Category $Category
}

return $BranchName
}

function New-GitHubPullRequest
{
param
(
[Parameter(Mandatory=$true)]
[string] $Repository,
[Parameter(Mandatory=$true)]
[string] $BranchName,
[Parameter(Mandatory=$true)]
Expand All @@ -81,6 +116,14 @@ function New-GitHubPullRequest
[string] $label = "automation"
)

$openPullRequests = gh api "/repos/$Repository/pulls" --method GET -f state=open | ConvertFrom-Json
$existingPullRequest = $openPullRequests | Where-Object {$_.head.ref -eq $BranchName} | Select-Object -First 1

if ($existingPullRequest) {
Write-Host "Pull request already exists for branch ($BranchName): $($existingPullRequest.html_url)"
return
}

$availableLabels = gh label list --json name | ConvertFrom-Json
if ($label -in $availableLabels.name) {
gh pr create --fill --head $BranchName --base $TargetBranch --label $label
Expand Down
4 changes: 1 addition & 3 deletions Build/Scripts/CompileAppInBcContainer.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Param(
[Parameter(Mandatory=$true)]
[string] $currentProjectFolder,
[Hashtable] $parameters
)

Expand All @@ -13,7 +11,7 @@ $appType = switch ($true) {
}

$PreCompileApp = (Get-Command "$PSScriptRoot\PreCompileApp.ps1" | Select-Object -ExpandProperty ScriptBlock)
Invoke-Command -ScriptBlock $PreCompileApp -ArgumentList $currentProjectFolder, $appType, ([ref] $parameters)
Invoke-Command -ScriptBlock $PreCompileApp -ArgumentList $appType, ([ref] $parameters)

$appFile = Compile-AppInBcContainer @parameters

Expand Down
5 changes: 5 additions & 0 deletions Build/Scripts/GitHub/GitHubAPI.class.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class GitHubAPI {
static $GitHubAPIHeader = "X-GitHub-Api-Version: 2022-11-28"
static $AcceptJsonHeader = "Accept: application/vnd.github+json"
}

64 changes: 64 additions & 0 deletions Build/Scripts/GitHub/GitHubIssue.class.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using module .\GitHubAPI.class.psm1

<#
Class that represents a GitHub issue.
#>
class GitHubIssue {
$IssueId
$Repository
$Issue

hidden GitHubIssue([int] $IssueId, [string] $Repository) {
$this.IssueId = $IssueId
$this.Repository = $Repository

$gitHubIssue = gh api "/repos/$Repository/issues/$IssueId" -H ([GitHubAPI]::AcceptJsonHeader) -H ([GitHubAPI]::GitHubAPIHeader) | ConvertFrom-Json
if ($gitHubIssue.message) {
# message property is populated when the issue is not found
Write-Host "::Warning:: Could not get issue $IssueId from repository $Repository. Error: $($gitHubIssue.message)"
$this.Issue = $null
return
}
$this.Issue = $gitHubIssue
}

<#
Gets the issue from GitHub.
#>
static [GitHubIssue] Get([int] $IssueId, [string] $Repository) {
$gitHubIssue = [GitHubIssue]::new($IssueId, $Repository)

if (-not $gitHubIssue.Issue) {
return $null
}

return $gitHubIssue
}

<#
Returns true if the issue is approved, otherwise returns false.
Issue is considered approved if it has a label named "approved".
#>
[bool] IsApproved() {
if(-not $this.Issue.labels) {
return $false
}

return $this.Issue.labels.name -contains "approved"
}

<#
Returns true if the issue is open, otherwise returns false.
#>
[bool] IsOpen() {
if (-not $this.Issue.state) {
return $false
}

return $this.Issue.state -eq "open"
}

[bool] IsPullRequest() {
return $this.Issue.PSobject.Properties.name -eq "pull_request"
}
}
Loading
Loading