Skip to content

Commit

Permalink
🔧 (main.yml): add inputs for forced change detection and improve rele…
Browse files Browse the repository at this point in the history
…ase conditions

Add inputs to force the `src` and `docs` folders to be considered changed.
Improve the release conditions by introducing a `RunRelease` flag to control
when releases should be executed. This enhances the flexibility and control
over the CI/CD pipeline, allowing for more granular and conditional execution
based on specific folder changes or forced inputs.

🔧 (main.yml): update release conditions and simplify folder decision logic

Simplifies the release condition by checking a single output variable `nkdAgility_RunRelease` instead of multiple conditions. Removes the redundant folder decision logic and directly uses the `nkdAgility_DocsDeployFolder` output for the SFTP upload path. This streamlines the workflow and reduces potential points of failure.

♻️ (TfsWorkItemEmbededLinkEnricher.cs, TfsWorkItemMigrationClient.cs, WorkItemMigrationClientMock.cs, IWorkItemMigrationClient.cs, WorkItemMigrationClientBase.cs): add stopOnError parameter to GetWorkItem methods

Introduce a `stopOnError` parameter to the `GetWorkItem` methods to provide more control over error handling. This change allows the caller to decide whether the application should exit on error or continue execution. This improves the flexibility and robustness of the error handling mechanism in the work item migration process.
  • Loading branch information
MrHinsh committed Aug 12, 2024
2 parents bf4258c + ebb8f6d commit a9e2585
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 53 deletions.
139 changes: 99 additions & 40 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ on:
pull_request:
branches: ["main"]
workflow_dispatch:
inputs:
ForceHasChanged_src:
description: 'Force the src folder to be considered changed'
required: false
default: false
type: boolean
ForceHasChanged_docs:
description: 'Force the docs folder to be considered changed'
required: false
default: false
type: boolean

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -40,9 +51,14 @@ jobs:
HasChanged_automation: ${{ steps.filter.outputs.automation }}
nkdAgility_Ring: ${{ steps.nkdagility.outputs.Ring }}
nkdAgility_WingetApplicationId: ${{ steps.nkdagility.outputs.WingetApplicationId }}
nkdAgility_IsBuildEditBranch: ${{ steps.nkdagility.outputs.IsBuildEditBranch }}
nkdAgility_ReleaseDescription: ${{ steps.nkdagility.outputs.release_description }}
nkdAgility_ReleaseDescriptionState: ${{ steps.nkdagility.outputs.release_description_state }}
nkdAgility_HasChanged_src: ${{ steps.nkdagility.outputs.HasChanged_src }}
nkdAgility_HasChanged_docs: ${{ steps.nkdagility.outputs.HasChanged_docs }}
nkdAgility_HasChanged_automation: ${{ steps.nkdagility.outputs.HasChanged_automation }}
nkdAgility_DocsDeployFolder: ${{ steps.nkdagility.outputs.docs_deploy_folder }}
nkdAgility_DocsVersionFolder: ${{ steps.nkdagility.outputs.docs_version_folder }}
nkdAgility_RunRelease: ${{ steps.nkdagility.outputs.RunRelease }}
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -80,34 +96,57 @@ jobs:
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
# Ring Setup
Write-Output "-------------------------------------------"
Write-Output "Ring Control Setup"
Write-Output "-------------------------------------------"
$Ring = "Canary"
$WingetApplicationId = "nkdagility.azure-devops-migration-tools"
$docs_deploy_folder = "./azure-devops-migration-tools/";
$RunCodeRelease = 'false'
$RunDocsRelease = 'false'
switch ($Env:GitVersion_PreReleaseLabel) {
"" {
$Ring = "Release";
$WingetApplicationId = "nkdagility.azure-devops-migration-tools";
$docs_deploy_folder = "./azure-devops-migration-tools/"
$RunRelease = 'true'
}
"Preview" {
$Ring = "Preview";
$WingetApplicationId = "nkdagility.azure-devops-migration-tools.Preview";
$docs_deploy_folder = "./azure-devops-migration-tools/preview/";
$RunRelease = (('${{ steps.filter.outputs.src }}' -eq 'true') -or ('${{ steps.filter.outputs.docs }}' -eq 'true') )
}
default {
$Ring = "Canary";
$WingetApplicationId = "nkdagility.azure-devops-migration-tools.Canary";
$docs_deploy_folder = "./azure-devops-migration-tools/canary/"
$RunRelease = 'false'
}
}
Write-Output "We are running for the $Ring Ring!"
Write-Output "We are focused on Winget ID $WingetApplicationId!"
echo "Ring=$Ring" >> $env:GITHUB_OUTPUT
Write-Output "We are focused on Winget ID $WingetApplicationId!"
echo "WingetApplicationId=$WingetApplicationId" >> $env:GITHUB_OUTPUT
Write-Output "docs_deploy_folder=$docs_deploy_folder"
echo "docs_deploy_folder=$docs_deploy_folder" >> $env:GITHUB_OUTPUT
Write-Output "RunRelease=$RunRelease"
echo "RunRelease=$RunRelease" >> $env:GITHUB_OUTPUT
Write-Output "-------------------------------------------"
# Docs Setup
Write-Output "-------------------------------------------"
Write-Output "Docs"
Write-Output "-------------------------------------------"
$docs_version_folder = "/azure-devops-migration-tools/$Env:GitVersion_SemVer"
Write-Output "docs_version_folder=$docs_version_folder"
echo "docs_version_folder=$docs_version_folder" >> $env:GITHUB_OUTPUT
Write-Output "-------------------------------------------"
$IsBuildEditBranch = $false;
if (("${{ github.ref_name }}").contains("build/")) {
$IsBuildEditBranch = $true;
}
Write-Output "IsBuildEditBranch=$IsBuildEditBranch"
echo "IsBuildEditBranch=$IsBuildEditBranch" >> $env:GITHUB_OUTPUT
# Get-ReleaseDescription
Write-Output "-------------------------------------------"
Write-Output "Get-ReleaseDescription"
Write-Output "-------------------------------------------"
Write-Output "Running Get-ReleaseDescription.ps1"
. .\build\include\Get-ReleaseDescription.ps1
$description = Get-ReleaseDescription -mode log -OPEN_AI_KEY ${{ secrets.OPENAI_API_KEY }}
Expand All @@ -122,7 +161,35 @@ jobs:
echo "release_description<<$EOF" >> $env:GITHUB_OUTPUT
echo $description >> $env:GITHUB_OUTPUT
echo "$EOF" >> $env:GITHUB_OUTPUT
Write-Output "-------------------------------------------"
# HasChanged Setup
Write-Output "-------------------------------------------"
Write-Output "HasChanged Setup"
Write-Output "-------------------------------------------"
if ('${{ steps.filter.outputs.src }}' -eq 'true') {
echo "HasChanged_src=true" >> $env:GITHUB_OUTPUT;
} else {
if ('${{ inputs.ForceHasChanged_src }}' -eq 'true') {
echo "HasChanged_src=true" >> $env:GITHUB_OUTPUT;
} else {
echo "HasChanged_src=false" >> $env:GITHUB_OUTPUT;
}
}
if ('${{ steps.filter.outputs.docs }}' -eq 'true') {
echo "HasChanged_docs=true" >> $env:GITHUB_OUTPUT;
} else {
if ('${{ inputs.ForceHasChanged_docs }}' -eq 'true') {
echo "HasChanged_docs=true" >> $env:GITHUB_OUTPUT;
} else {
echo "HasChanged_docs=false" >> $env:GITHUB_OUTPUT;
}
}
if ('${{ steps.filter.outputs.automation }}' -eq 'true') {
echo "HasChanged_automation=true" >> $env:GITHUB_OUTPUT;
} else {
echo "HasChanged_automation=false" >> $env:GITHUB_OUTPUT;
}
Write-Output "-------------------------------------------"
- uses: actions/upload-artifact@v4
with:
Expand All @@ -144,10 +211,14 @@ jobs:
## ${{needs.Setup.outputs.GitVersion_SemVer}} (${{needs.Setup.outputs.nkdAgility_Ring}})
### NKDAgility
- nkdAgility_Ring: ${{needs.Setup.outputs.nkdAgility_Ring}}
- nkdAgility_IsBuildEditBranch: ${{needs.Setup.outputs.nkdAgility_IsBuildEditBranch}}
- nkdAgility_WingetApplicationId: ${{needs.Setup.outputs.nkdAgility_WingetApplicationId}}
- nkdAgility_DocsVersionFolder: ${{needs.Setup.outputs.nkdAgility_DocsVersionFolder}}
- nkdAgility_DocsDeployFolder: ${{needs.Setup.outputs.nkdAgility_DocsDeployFolder}}
- nkdAgility_ReleaseDescriptionState: ${{needs.Setup.outputs.nkdAgility_ReleaseDescriptionState}}
- nkdAgility_HasChanged_src: ${{needs.Setup.outputs.nkdAgility_HasChanged_src}}
- nkdAgility_HasChanged_docs: ${{needs.Setup.outputs.nkdAgility_HasChanged_docs}}
- nkdAgility_HasChanged_automation: ${{needs.Setup.outputs.nkdAgility_HasChanged_automation}}
- nkdAgility_RunRelease: ${{needs.Setup.outputs.nkdAgility_RunRelease}}
### GitVersion
- GitVersion_BranchName: ${{needs.Setup.outputs.GitVersion_BranchName}}
- GitVersion_SemVer: ${{needs.Setup.outputs.GitVersion_SemVer}}
Expand Down Expand Up @@ -262,8 +333,13 @@ jobs:
- uses: cschleiden/replace-tokens@v1
with:
files: '["**/*.html"]'
tokenPrefix: "${"
tokenSuffix: "}"
tokenPrefix: "#{"
tokenSuffix: "}#"
env:
GitVersion_SemVer: ${{ needs.Setup.outputs.GitVersion_SemVer }}
GitVersion_AssemblySemVer: ${{ needs.Setup.outputs.GitVersion_AssemblySemVer }}
GitVersion_InformationalVersion: ${{ needs.Setup.outputs.GitVersion_InformationalVersion }}
GitVersion.SemVer: ${{ needs.Setup.outputs.GitVersion_SemVer }}
- uses: igsekor/[email protected]
id: spellcheck
name: Spellcheck
Expand All @@ -286,11 +362,8 @@ jobs:
GitVersion_InformationalVersion: ${{ needs.Setup.outputs.GitVersion_InformationalVersion }}
GitVersion_NuGetVersion: ${{ needs.Setup.outputs.GitVersion_NuGetVersion }}
GitVersion_PreReleaseLabel: ${{ needs.Setup.outputs.GitVersion_PreReleaseLabel }}
HasChanged_src: ${{ needs.Setup.outputs.HasChanged_src }}
HasChanged_docs: ${{ needs.Setup.outputs.HasChanged_docs }}
HasChanged_automation: ${{ needs.Setup.outputs.HasChanged_automation }}
needs: [build, Setup]
if: ${{ success() && ( needs.Setup.outputs.nkdAgility_Ring != 'Canary' ) && ( needs.Setup.outputs.HasChanged_src == 'true' ) }}
if: ${{ success() && ( needs.Setup.outputs.nkdAgility_RunRelease == 'true' ) }}
steps:
- uses: actions/download-artifact@v4
with:
Expand All @@ -314,11 +387,7 @@ jobs:
run: |
if ($Env:nkdAgility_Ring -eq 'Release') {
echo "discussion_category_name=Anouncement" >> $env:GITHUB_OUTPUT
}
. .\build\include\Get-ReleaseDescription.ps1
$description = Get-ReleaseDescription -mode log -OPEN_AI_KEY ${{ secrets.OPENAI_API_KEY }}
echo "release_description=$description" >> $env:GITHUB_OUTPUT
}
- name: Release
uses: softprops/action-gh-release@v2
with:
Expand Down Expand Up @@ -355,7 +424,7 @@ jobs:
env:
GitVersion_SemVer: ${{ needs.Setup.outputs.GitVersion_SemVer }}
needs: [GitHubRelease, Setup]
if: ${{ success() && ( needs.Setup.outputs.nkdAgility_Ring != 'Canary' ) }}
if: ${{ success() && ( needs.Setup.outputs.nkdAgility_RunRelease == 'true' ) }}
steps:
- name: Create Deployment on elmah.io
uses: elmahio/github-create-deployment-action@v1
Expand All @@ -370,7 +439,7 @@ jobs:
name: "Release to Marketplace"
runs-on: ubuntu-latest
needs: [Setup, GitHubRelease]
if: ${{ success() && ( needs.Setup.outputs.nkdAgility_Ring != 'Canary' ) && (needs.Setup.outputs.HasChanged_src == 'true') }}
if: ${{ success() && ( needs.Setup.outputs.nkdAgility_Ring == 'Release' ) }}
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -399,7 +468,7 @@ jobs:
name: "Release to Chocolatey"
runs-on: windows-latest
needs: [Setup, GitHubRelease]
if: ${{ success() && ( needs.Setup.outputs.nkdAgility_Ring != 'Canary' ) && (needs.Setup.outputs.HasChanged_src == 'true') }}
if: ${{ success() && ( needs.Setup.outputs.nkdAgility_RunRelease == 'true' ) }}
steps:
- uses: actions/download-artifact@v4
with:
Expand All @@ -423,7 +492,7 @@ jobs:
name: "Release to Winget"
runs-on: windows-latest
needs: [Setup, GitHubRelease]
if: ${{ success() && ( needs.Setup.outputs.nkdAgility_Ring != 'Canary' ) && (needs.Setup.outputs.HasChanged_src == 'true') }}
if: ${{ success() && ( needs.Setup.outputs.nkdAgility_RunRelease == 'true' ) }}
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -444,7 +513,7 @@ jobs:
name: "Release to Docs"
runs-on: ubuntu-latest
needs: [Setup, BuildDocs, GitHubRelease]
if: ${{ success() && ( needs.Setup.outputs.nkdAgility_Ring != 'Canary' ) && (needs.Setup.outputs.HasChanged_docs == 'true') }}
if: ${{ success() && ( needs.Setup.outputs.nkdAgility_RunRelease == 'true' ) }}
steps:
- name: Download a single artifact
uses: actions/download-artifact@v4
Expand All @@ -454,17 +523,7 @@ jobs:
- name: "Find files"
shell: pwsh
run: |
Get-Item -Path .\
- name: "Folder Desider"
id: Folder-Decision
shell: pwsh
run: |
if ($Env:nkdAgility_Ring -ne 'Release') {
echo "subfolder=$Env:nkdAgility_Ring" >> $env:GITHUB_OUTPUT
Write-Output "subfolder=$Env:nkdAgility_Ring"
} else {
Write-Output "subfolder="
}
Get-Item -Path .\
- name: SFTP Upload ${{ (needs.Setup.outputs.nkdAgility_Ring) }}
uses: Dylan700/[email protected]
with:
Expand All @@ -476,6 +535,6 @@ jobs:
dry-run: ${{ (needs.Setup.outputs.nkdAgility_Ring) == 'Canary' }}
# A list of folders to upload in the format of `folder/ => upload_folder/`
uploads: |
./_site/ => ./azure-devops-migration-tools/${{ steps.Folder-Decision.outputs.subfolder }}
./_site/ => ${{needs.Setup.outputs.nkdAgility_DocsDeployFolder}}
# If true, any existing files in the remote upload directories are deleted.
delete: false
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public override int Enrich(WorkItemData sourceWorkItem, WorkItemData targetWorkI
{
var workItemId = workItemLinkMatch.Groups["id"].Value;
Log.LogDebug("{LogTypeName}: Source work item {workItemId} mention link traced on field {fieldName} on target work item {targetWorkItemId}.", LogTypeName, workItemId, field.Name, targetWorkItem.Id);
var sourceLinkWi = Engine.Source.WorkItems.GetWorkItem(workItemId);
var sourceLinkWi = Engine.Source.WorkItems.GetWorkItem(workItemId, false);
if (sourceLinkWi != null)
{
var linkWI = Engine.Target.WorkItems.FindReflectedWorkItemByReflectedWorkItemId(sourceLinkWi);
Expand All @@ -113,7 +113,9 @@ public override int Enrich(WorkItemData sourceWorkItem, WorkItemData targetWorkI
}
else
{
Log.LogInformation("{LogTypeName}: [SKIP] Source work item {workItemId} mention link on field {fieldName} on target work item {targetWorkItemId} was not found on the source collection.", LogTypeName, workItemId, field.Name, targetWorkItem.Id);
var replaceValue = value;
field.Value = field.Value.ToString().Replace(anchorTagMatch.Value, replaceValue);
Log.LogInformation("{LogTypeName}: [SKIP] Source work item {workItemId} mention link on field {fieldName} was not found on the source collection.", LogTypeName, workItemId, field.Name, targetWorkItem.Id);
}
}
else if ((href.StartsWith("mailto:") || href.StartsWith("#")) && value.StartsWith("@"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ public override WorkItemData GetRevision(WorkItemData workItem, int revision)
throw new NotImplementedException("GetRevision in combination with WorkItemData is buggy");
}

public override WorkItemData GetWorkItem(string id)
public override WorkItemData GetWorkItem(string id, bool stopOnError = true)
{
return GetWorkItem(int.Parse(id));
return GetWorkItem(int.Parse(id), stopOnError);
}

public override WorkItemData GetWorkItem(int id)
public override WorkItemData GetWorkItem(int id, bool stopOnError = true)
{
if (id == 0)
{
Expand Down Expand Up @@ -175,7 +175,10 @@ public override WorkItemData GetWorkItem(int id)
{ "Time",timer.ElapsedMilliseconds }
});
Log.Error(ex, "Unable to GetWorkItem with id[{id}]", id);
Environment.Exit(-1);
if (stopOnError)
{
Environment.Exit(-1);
}
} finally
{
timer.Stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public ProjectData GetProject()
throw new System.NotImplementedException();
}

public WorkItemData GetWorkItem(string id)
public WorkItemData GetWorkItem(string id, bool stopOnError = true)
{
throw new System.NotImplementedException();
}
Expand All @@ -127,7 +127,7 @@ public List<WorkItemData> FilterWorkItemsThatAlreadyExist(List<WorkItemData> sou
throw new System.NotImplementedException();
}

public WorkItemData GetWorkItem(int id)
public WorkItemData GetWorkItem(int id, bool stopOnError = true)
{
throw new System.NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public interface IWorkItemMigrationClient

List<WorkItemData> GetWorkItems();

WorkItemData GetWorkItem(string id);
WorkItemData GetWorkItem(string id, bool stopOnError = true);

WorkItemData GetWorkItem(int id);
WorkItemData GetWorkItem(int id, bool stopOnError = true);

List<int> GetWorkItemIds(string WIQLQuery);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using MigrationTools._EngineV1.Configuration;
using MigrationTools._EngineV1.DataContracts;
Expand Down Expand Up @@ -44,9 +44,9 @@ public void Configure(IMigrationClient migrationClient, bool bypassRules = true)

public abstract WorkItemData GetRevision(WorkItemData workItem, int revision);

public abstract WorkItemData GetWorkItem(string id);
public abstract WorkItemData GetWorkItem(string id, bool stopOnError = true);

public abstract WorkItemData GetWorkItem(int id);
public abstract WorkItemData GetWorkItem(int id, bool stopOnError = true);

public abstract List<WorkItemData> GetWorkItems();

Expand Down

0 comments on commit a9e2585

Please sign in to comment.