microsoft / AL-Go

The plug-and-play DevOps solution for Business Central app development on GitHub
MIT License
285 stars 121 forks source link

Use GitHub Packages from different Organization #989

Closed AlexanderRichter closed 1 week ago

AlexanderRichter commented 7 months ago

Hello, we are trying to find our way through different scenarios on how to use Al-Go.

Our current idea is to have one GitHub Organization for our Producut Development Team. There we want to store all our Apps in GitHub Packages.

In a different we want to manage the individual Projects.

How could we configure Al-Go to use the Packages from the Product Org for depenendy resolution and still have the Packages from Custom Projects within the Project Orgainzation.

My question ist, is there a way to manage mulitple GitHubPackagesContext for one organization.

skeck commented 7 months ago

I had a similar question here: https://github.com/microsoft/AL-Go/issues/827. Feature https://github.com/microsoft/AL-Go/issues/261 should be in preview now (didn't check).

AlexanderRichter commented 7 months ago

i updated the al go settings with using freddydk/AL-Go@nuget and added a trusted nuget feed in my settings

"TrustedNuGetFeeds": [ { "Url": "https://nuget.pkg.github.com/**MYProductOrg**/index.json", "AuthTokenSecret": "GhTokenWorkflow" } ]

Then i went to my custom app in Project Org and and added a dependency as usual. Unfortunaley the build fails because dependency could not be resolved.

Checking the Log dont even see it that the Package gehts downloaded.

The Log shows for Step "Download Project Dependencies"

Settings: {"keyVaultCertificateUrlSecretName":"","microsoftTelemetryConnectionString":"InstrumentationKey=84bd9223-67d4-4378-8590-9e4a46023be2;IngestionEndpoint=https://westeurope-1.in.applicationinsights.azure.com/","type":"PTE","sendExtendedTelemetryToMicrosoft":false,"appBuild":13,"installTestApps":[],"versioningStrategy":0,"installApps":[],"installTestLibraries":false,"runNumberOffset":0,"codeSignCertificatePasswordSecretName":"codeSignCertificatePassword","vsixFile":"","country":"de","excludeEnvironments":[],"templateSha":"32b6eb33271eeec45ea8b3b238a67762a63ccbff","partnerTelemetryConnectionString":"","doNotRunTests":false,"enableCodeAnalyzersOnTestApps":false,"runs-on":"windows-latest","generateDependencyArtifact":false,"templateUrl":"https://github.com/freddydk/AL-Go@nuget","keyVaultCertificatePasswordSecretName":"","rulesetFile":"","licenseFileUrlSecretName":"licenseFileUrl","enableExternalRulesets":false,"memoryLimit":"","keyVaultClientIdSecretName":"","testFolders":[],"githubRunner":"windows-latest","doNotBuildTests":false,"environments":[],"companyName":"","assignPremiumPlan":false,"artifact":"bcartifacts/onprem/23.0.12034.12841/de","ghTokenWorkflowSecretName":"ghTokenWorkflow","enableTaskScheduler":false,"enableCodeCop":false,"TrustedNuGetFeeds":[{"AuthTokenSecret":"MyGitHubPackages","Url":"https://nuget.pkg.github.com/XXXXXXX/index.json"}],"repoVersion":"1.0","doNotPublishApps":true,"doNotSignApps":false,"unusedALGoSystemFiles":[],"githubRunnerShell":"powershell","cacheKeepDays":3,"bcptTestFolders":[],"updateDependencies":false,"cacheImageName":"my","treatTestFailuresAsWarnings":false,"additionalCountries":[],"alDoc":{"continuousDeployment":false,"deployToGitHubPages":true,"maxReleases":3,"groupByProject":true,"includeProjects":[],"excludeProjects":[],"header":"Documentation for {REPOSITORY}

freddydk commented 7 months ago

Yes, you should be able to add multiple trusted organizations. I haven't tried this myself - but will try next week, when I get back from vacation

AlexanderRichter commented 7 months ago

thanks freddy, enjoy your vacation :)

ronnykwon commented 5 months ago

I'm facing the problem here too. I have published nuget packages in my organisation account on github. I have generated a personal token with the package:read attribute.

In my personal github account, I've created a repo using the nuget branch template. I created an app. In this app I created a dependency to my organisation app. In the .AL-Go/settings.json I have added the settings

{
  "country": "fr",
  "appFolders": [],
  "testFolders": [],
  "bcptTestFolders": [],
  "TrustedNuGetFeeds": [
    {
        "Url": "https://nuget.pkg.github.com/MyOrg/index.json",
        "AuthTokenSecret": "GhNuGetMyOrg"
    }
  ]
}

in the Action secret I have added GhNuGetMyOrg with the previously generated personal token.

The build fails.

The following command works on my server :

PS C:\actions-runner> Get-BcNuGetPackage -nuGetServerUrl "https://nuget.pkg.github.com/MyOrgPF/index.json" -nuGetToken "ghp_MyOrgPackageReadToken" -packageName "a00a0000-aa00-0000-0000-0aaa00a00000"
Search NuGetFeed https://nuget.pkg.github.com/MyOrgPF/index.json
Search package using https://api.github.com/orgs/MyOrgPF/packages?package_type=nuget&per_page=100&page=1
1 matching packages found
- AL-Go-a00a0000-aa00-0000-0000-0aaa00a00000
PackageId: AL-Go-a00a0000-aa00-0000-0000-0aaa00a00000
Get versions using https://nuget.pkg.github.com/MyOrgPF/download/al-go-a00a0000-aa00-0000-0000-0aaa00a00000/index.json
3 versions found
First version is 24.1.17
Last version is 24.1.14.1
Latest version is 24.1.17
Best match for package name a00a0000-aa00-0000-0000-0aaa00a00000 Version 0.0.0.0: AL-Go-a00a0000-aa00-0000-0000-0aaa00a00000 Version 24.1.17 from https://nuget.pkg.github.com/MyOrgPF/index.json
Download package using https://nuget.pkg.github.com/MyOrgPF/download/al-go-a00a0000-aa00-0000-0000-0aaa00a00000/24.1.17/al-go-a00a0000-aa00-0000-0000-0aaa00a00000.24.1.17.nupkg
Package successfully downloaded

I've attached the debug log of the CI/CD action

hope it helps debug_nuget.zip

freddydk commented 5 months ago

Sorry for the delay on this - have been busy on BC24 / PS7 stuff, but will have a look at this next week.

ronnykwon commented 5 months ago

I would suggest to have custom script that would run on specific lifecycle event in the same spirit of BC integration

freddydk commented 4 months ago

You need to move the TrustedNuGetFeeds setting to the repository settings file (.github/AL-Go-Settings.json) The project settings file (.AL-Go/settings.json) cannot contain ContainerHelper settings as it is today.

freddydk commented 4 months ago

And sorry for the long wait here :-(

freddydk commented 4 months ago

This is an example of this: https://github.com/freddydk/GHP-W1/actions/runs/9286264549

AlexanderRichter commented 2 weeks ago

Hey @freddydk ,

after releasing the new nugte feature i thought its worth to give it another try but somethng is still not working.

Maybe there is just something off in my config but i would love to close this issue so i thought its easiest to reach out to you.

Running the CI/CD i get an error saying that the pipeline is not authorized to read the nuget feed:

  Error: Unexpected error when running action. Error Message: Response status code does not indicate success: 401 (Unauthorized). Response status code does not indicate success: 401 (Unauthorized)., StackTrace: at NuGetFeed, C:\ProgramData\BcContainerHelper\6.0.24\BcContainerHelper\NuGet\NuGetFeedClass.ps1: line 51 <- at Create, C:\ProgramData\BcContainerHelper\6.0.24\BcContainerHelper\NuGet\NuGetFeedClass.ps1: line 58 <- at Find-BcNuGetPackage, C:\ProgramData\BcContainerHelper\6.0.24\BcContainerHelper\NuGet\Find-BcNuGetPackage.ps1: line 62 <- at Download-BcNuGetPackageToFolder, C:\ProgramData\BcContainerHelper\6.0.24\BcContainerHelper\NuGet\Download-BcNuGetPackageToFolder.ps1: line 136 <- at <ScriptBlock>, C:\actions-runner\_work\_actions\microsoft\AL-Go-Actions\v5.3\RunPipeline\RunPipeline.ps1: line 304 <- at <ScriptBlock>, C:\actions-runner\_work\_actions\microsoft\AL-Go-Actions\v5.3\RunPipeline\RunPipeline.ps1: line 284 <- at <ScriptBlock>, C:\ProgramData\BcContainerHelper\6.0.24\BcContainerHelper\AppHandling\Run-AlPipeline.ps1: line 1354 <- at <ScriptBlock>, C:\ProgramData\BcContainerHelper\6.0.24\BcContainerHelper\AppHandling\Run-AlPipeline.ps1: line 1336 <- at <ScriptBlock>, C:\ProgramData\BcContainerHelper\6.0.24\BcContainerHelper\AppHandling\Run-AlPipeline.ps1: line 971 <- at Run-AlPipeline, C:\ProgramData\BcContainerHelper\6.0.24\BcContainerHelper\AppHandling\Run-AlPipeline.ps1: line 933 <- at <ScriptBlock>, C:\actions-runner\_work\_actions\microsoft\AL-Go-Actions\v5.3\RunPipeline\RunPipeline.ps1: line 355 <- at <ScriptBlock>, C:\actions-runner\_work\_temp\1fbad794-b630-4da9-84a6-d16875a3e434.ps1: line 3 <- at <ScriptBlock>, C:\actions-runner\_work\_actions\microsoft\AL-Go-Actions\v5.3\Invoke-AlGoAction.ps1: line 17 <- at <ScriptBlock>, C:\actions-runner\_work\_temp\1fbad794-b630-4da9-84a6-d16875a3e434.ps1: line 2 <- at <ScriptBlock>, <No file>: line 1

Here are my Settings

AL-Go-Settings.json

{
  "type": "PTE",
  "templateUrl": "https://github.com/microsoft/AL-Go-PTE@main",
  "templateSha": "72f3223b6a153cd1fae540f5d7388842e2f9ac1e",
  "githubrunner": "self-hosted,Windows",
  "runs-on": "ubuntu-latest",
  "TrustedNuGetFeeds": [
    {
        "url": "https://nuget.pkg.github.com/TestALGOPortfolio/index.json",
        "authTokenSecret": "PORTFOLIONUGETTOKEN"
    }
  ]
}

The authTokenSecret contains only the value of a classic token which has access to the Organization / Nuget Feed.

Here are soem parts of the log:

Read Settings

"TrustedNuGetFeeds": [
    {
      "authTokenSecret": "PORTFOLIONUGETTOKEN",
      "url": "https://nuget.pkg.github.com/TestALGOPortfolio/index.json"
    }
  ]

Read Secrets

  C:\actions-runner\_work\_actions\microsoft\AL-Go-Actions\v5.3\ReadSecrets/../Invoke-AlGoAction.ps1 -ActionName "ReadSecrets" -Action {
    C:\actions-runner\_work\_actions\microsoft\AL-Go-Actions\v5.3\ReadSecrets/ReadSecrets.ps1 -gitHubSecrets '{
    "PORTFOLIONUGETTOKEN": "***",
    "GITHUBPACKAGESCONTEXT": "***",
    "github_token": "***",
    "NUGETPACKAGES": "***",
    "ORGWORKFLOW": "***",
    "GHTOKENWORKFLOW": "***"
  }' -getSecrets $ENV:_getSecrets -useGhTokenWorkflowForPush $ENV:_useGhTokenWorkflowForPush

To verify that the token has sufficient permissions to read the NugetFeed from TestALGOPortfolio organisation i tried

Download-BcNuGetPackageToFolder -folder C:\Temp\nugettest\Nugets -packageName XYZ -nuGetServerUrl https://nuget.pkg.github.com/TestALGOPortfolio/index.json -nuGetToken Token

this worked as expected.

I assume that there is something wrong with the PORTFOLIONUGETTOKEN Ogrganizational Secret.

freddydk commented 2 weeks ago

The NuGet feature is still in preview in AL-Go It looks like you are on 5.3 - which doesn't have the support for this secret. You can run Update AL-Go System files with microsoft/AL-Go-PTE@preview - then it should work (looks correct at least)

AlexanderRichter commented 2 weeks ago

yes, you where right. updating to microsoft/AL-Go-PTE@preview helped to get over this step.

unfortunately the preview has the issue with altool as well when it comes to delivery

image

Guess thats the same issue like reported in #1217

AlexanderRichter commented 1 week ago

works now with Version 6.0