Skip to content

Commit

Permalink
Change to Build Automation
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanMaron committed Oct 15, 2024
1 parent 626b032 commit 9ca7bb3
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 339 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/BuildNewCommits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: BuildNewCommits

on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:

jobs:
prepare:
name: Prepare Matrix
runs-on: ubuntu-latest

outputs:
countries: ${{ steps.load_countries.outputs.countries }}

steps:
- name: Install BC Container Helper
shell: pwsh
run: Install-Module bccontainerhelper -force

- name: Check out the repository to the runner
uses: actions/checkout@v4.1.2
with:
ref: master

- name: Load Countries
id: load_countries
shell: pwsh
run: ./scripts/GetAllCountries.ps1

- name: ShowOutput
shell: pwsh
run: Write-Host '${{ steps.load_countries.outputs.countries }}'

buildCommits:
needs: prepare
name: Build Commits
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare.outputs.countries) }}

steps:
- name: Install BC Container Helper
shell: pwsh
run: Install-Module bccontainerhelper -force

- name: Check out the repository to the runner
uses: actions/checkout@v4.1.2

- name: Build Commits
shell: pwsh
run: |
./scripts/Auto_load_versions.ps1 -country ${{matrix.countries}}

80 changes: 0 additions & 80 deletions Misc-apps.code-workspace

This file was deleted.

90 changes: 89 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,95 @@ This repository holds all versions of the Buisness Central Apps. The purpose is

There is one separate branch per country-major version.

Go the one of the `w1` branches to find most of the code:
https://github.com/StefanMaron/MSDyn365BC.Code.History/branches/all?query=w1

Check out the country specific branches to view the localized base app. For example `DE`:
https://github.com/StefanMaron/MSDyn365BC.Code.History/branches/all?query=de

## Schedule

The repository will automatically update itself from the artifacts once a day:

- Regular/current branches will run at midnight UTC and pull the last 24 hours of artifacts
- vNext/insider branches will run at 2 am UTC and pull the last 24 hours of artifacts

## Differences

Main differences between the https://github.com/StefanMaron/MSDyn365BC.Code.History repo:
- Builds on sandbox instead of OnPrem artifacts to include hotfixes
- localization branches only include the localized code, so some of them are empty, some just have the base app (Check w1 branches for all the other code)
- the commits are added by pipelines to reduce runtime
- the pipelines will be scheduled to run daily once the initial load is done.
- there will be branches to cover NextMajor/Minor as well (Look out for suffix vNext in the branches)
- the main branch is just holding the scripts, switch branch to see the BC Code
- Because of the crazy number of versions, I did limit this repo to start with 23.5
- to keep the size of this repo at least in some boundaries, I decided to not include any translation files.

## Partial Clone (Subset of Branches)
To reduce the size of the local clone you can use those commands to clone only the branches you need:

First, clone with those parameters and set it to whatever branch you need:
```
git clone -b w1-24 --single-branch https://github.com/StefanMaron/MSDyn365BC.Code.History
```
if you want to add additional branches you can do it like this
```
git remote set-branches --add origin de-24
git remote set-branches --add origin de-23
git fetch
```
You can also use wildcards for [remote-branch], e.g.
```
git remote set-branches --add origin us-*
git fetch
```

Removing tracking branches is a little more complicated.
First you need to manually edit the `.git/config` file and remove the branches in the `[remote "origin"]` section
```
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = https://github.com/StefanMaron/MSDyn365BC.Code.History
fetch = +refs/heads/w1-23:refs/remotes/origin/w1-23
fetch = +refs/heads/de-24:refs/remotes/origin/de-24
fetch = +refs/heads/us-*:refs/remotes/origin/us-*
[branch "w1-23"]
remote = origin
merge = refs/heads/w1-23
```
once thats done you need to delete the local reference of the remote branches like this
```
git branch -d -r origin/us-23
git branch -d -r origin/us-24
```
if you had one of those branches checked out locally (a local copy of the branch) you want to delete those as well
```
git branch -D us-23
git branch -D us-24
```

and thats it, now `git fetch` should not pull the branches anymore

## Partial Clone (Shallow Clone)
To further reduce the size of your local repository, you can also utilize the `--depth` parameter with the `git clone` command.
This creates a shallow clone, fetching only the most recent commits up to the specified depth, thereby ignoring the entire history that you might not need.

For instance, to clone only the latest commit (depth of 1), you would use the following command:

```
git clone -b w1-24 --depth 1 https://github.com/StefanMaron/MSDyn365BC.Code.History
```

> [!TIP]
> Using `--depth` implies `--single-branch` unless `--no-single-branch` is given to fetch the histories near the tips of all branches.
Later, you can deepen your clone by 3 commits (or any other number of commits) with `git fetch --deepen 3` or convert it to a complete clone using `git fetch --unshallow`.

## Disclaimer

All code is owned by Microsoft. You can not do any pull request on this repository.
All code is owned by Microsoft. You can not do any pull request on this repository.
21 changes: 0 additions & 21 deletions base-app.code-workspace

This file was deleted.

77 changes: 51 additions & 26 deletions scripts/Auto_load_versions.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
$ErrorActionPreference = "SilentlyContinue"
param (
[string]$country = 'w1'
)

Set-Alias sz "C:\Program Files\7-Zip\7z.exe"
$ErrorActionPreference = "SilentlyContinue"

[System.Collections.ArrayList]$Versions = @()
Get-BCArtifactUrl -select All -Type OnPrem | % {
$Url = $_
$TempString = $Url.Substring(41)
[version]$Version = $TempString.Substring(0, $TempString.IndexOf('/'))
$country = $TempString.Substring($TempString.IndexOf('/') + 1)
# Get-BCArtifactUrl -select All -Type OnPrem -country $country -after ([DateTime]::Today.AddDays(-1)) | % {
Get-BCArtifactUrl -select All -Type OnPrem -country $country | % {
[System.Uri]$Url = $_
$TempString = $Url.AbsolutePath
[version]$Version = $TempString.Split('/')[2]
$country = $TempString.Split('/')[3]

[hashtable]$objectProperty = @{}
$objectProperty.Add('Version', $Version)
Expand All @@ -22,57 +25,79 @@ Get-BCArtifactUrl -select All -Type OnPrem | % {

$Versions | Sort-Object -Property Country, Version | % {
[version]$Version = $_.Version
$country = $_.Country
$country = $_.Country.Trim()
Write-Host ($($country)-$($version.ToString()))

git fetch --all

$CommitDoesNotExist = (git log --all --grep="$($country)-$($version.ToString())") -eq $null
$LastCommit = git log --all --grep="^$($country)-$($version.ToString())$"

if ($CommitDoesNotExist) {
if ($LastCommit.Length -eq 0) {
Write-Host "###############################################"
Write-Host "Processing $($country) - $($Version.ToString())"
Write-Host "###############################################"


$LatestCommitIDOfBranchEmpty = git log -n 1 --pretty=format:"%h" "empty"

$LatestCommitIDOfBranchEmpty = git log -n 1 --pretty=format:"%h" "master"
if ($LatestCommitIDOfBranchEmpty -eq $null) {
$LatestCommitIDOfBranchEmpty = git log -n 1 --pretty=format:"%h" "origin/empty"
$LatestCommitIDOfBranchEmpty = git log -n 1 --pretty=format:"%h" "origin/master"
}

if ($Version.Major -gt 15 -and $Version.Build -gt 5) {
$CommitIDLastCUFromPreviousMajor = git log --all --grep="$($country)-$($version.Major - 1).5" --pretty=format:"%h"
$CommitIDLastCUFromPreviousMajor = git log --all -n 1 --grep="^$($country)-$($version.Major - 1).5" --pretty=format:"%h"
}
else {
$CommitIDLastCUFromPreviousMajor = $null
}

$BranchAlreadyExists = ((git branch --list -r "*$($country)-$($Version.Major)*") -ne $null) -or ((git branch --list "*$($country)-$($Version.Major)*") -ne $null)
$BranchAlreadyExists = ((git branch --list -r "origin/$($country)-$($Version.Major)") -ne $null) -or ((git branch --list "$($country)-$($Version.Major)") -ne $null)

if ($BranchAlreadyExists) {
git checkout "$($country)-$($Version.Major)"
git switch "$($country)-$($Version.Major)"
}
else {
if ($CommitIDLastCUFromPreviousMajor -ne $null) {
git checkout -b "$($country)-$($Version.Major)" $CommitIDLastCUFromPreviousMajor
git switch -c "$($country)-$($Version.Major)" $CommitIDLastCUFromPreviousMajor
}
else {
git checkout -b "$($country)-$($Version.Major)" $LatestCommitIDOfBranchEmpty
git switch -c "$($country)-$($Version.Major)" $LatestCommitIDOfBranchEmpty
}
}

$Paths = Download-Artifacts -artifactUrl $_.URL -includePlatform
$TargetPathOfVersion = $Paths[0]
if ($country -eq 'w1'){
$Paths = Download-Artifacts -artifactUrl $_.URL -includePlatform
$LocalizationPath = $Paths[0]
$PlatformPath = $Paths[1]
}
else {
$Paths = Download-Artifacts -artifactUrl $_.URL
$LocalizationPath = $Paths
$PlatformPath = ''
}

#Localization folder

$TargetPathOfVersion = (Join-Path $LocalizationPath (Get-ChildItem -Path $LocalizationPath -filter "Applications")[0].Name)

if (-not (Test-Path (Join-Path $TargetPathOfVersion 'Applications'))) {
$TargetPathOfVersion = $Paths[1]
if (-not (Test-Path $TargetPathOfVersion)) {
#Platform Folder
$TargetPathOfVersion = (Join-Path $PlatformPath (Get-ChildItem -Path $PlatformPath -filter "Applications")[0].Name)
}

& "$PSScriptRoot\UpdateALRepo.ps1" -SourcePath (Join-Path $TargetPathOfVersion Applications) -RepoPath (Split-Path $PSScriptRoot -Parent)
& "$PSScriptRoot\BuildTestsWorkSpace.ps1"
& "scripts/UpdateALRepo.ps1" -SourcePath $TargetPathOfVersion -RepoPath (Split-Path $PSScriptRoot -Parent) -Version $version -Localization $country
& "scripts/BuildTestsWorkSpace.ps1"

Get-ChildItem -Recurse -Filter "*.xlf" | Remove-Item

"$($country)-$($version.ToString())" > version.txt

git config user.email "stefanmaron@outlook.de"
git config user.name "Stefan Maron"
git add -A | out-null
git commit -a -m "$($country)-$($version.ToString())" | out-null
git gc | out-null
git push --set-upstream origin "$($country)-$($Version.Major)"

Remove-Item $Paths[0] -Recurse
Flush-ContainerHelperCache -keepDays 0 -ErrorAction SilentlyContinue

Write-Host "$($country)-$($version.ToString())"
}
Expand Down
9 changes: 9 additions & 0 deletions scripts/GetAllCountries.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$countries = [System.Collections.ArrayList]::new()
Get-BCArtifactUrl -select All -Type OnPrem | % {
[System.Uri]$Url = $_
[version]$Version = $Url.AbsolutePath.Split('/')[2]
if ($Version -ge [version]::Parse('15.0.0.0')) {
$Url.AbsolutePath.Split('/')[3]
}
}| Sort-object -unique | % { $countries.Add($_)}
Write-Output "countries={""countries"":$($countries | ConvertTo-Json -Compress)}" >> $Env:GITHUB_OUTPUT
Loading

0 comments on commit 9ca7bb3

Please sign in to comment.