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

Add ability to generate more complex workflows with multiple stages/jobs #968

Open
dansiegel opened this issue Jul 3, 2022 · 0 comments

Comments

@dansiegel
Copy link
Contributor

Description

The existing Workflow/Job attributes are extremely limiting. As implemented to produce more than one job per triggered workflow in GitHubActions you would need to add multiple OS Images... One problem with this is that it assumes you want to run the same exact target each time.

A far better scenario is one in which I can create 1-N GitHub Workflows each of which could have 1-N Jobs, Jobs may define relationships such as a particular Job needs other jobs to pass before it can start, and Jobs may need to download artifacts from other jobs. This is currently implemented in the Nuke.Maui repo. You'll notice that the sample generates 2 workflows, one for CI each time the master branch is updated, and on for PRs. There are several jobs defined including one to publish the library which is excluded from the PRs while the other jobs are declared once and reused across multiple workflows.

Usage Example

[GitHubWorkflow("ci",
    FetchDepth = 0,
    AutoGenerate = true,
    OnPushBranches = new[] { MasterBranch },
    JobNames = new[] { "android-build", "ios-build", "compile-lib", "publish-internal" } )]
[GitHubWorkflow("pr",
    OnPullRequestBranches = new[] { MasterBranch },
    FetchDepth = 0,
    AutoGenerate = true,
    JobNames = new[] { "android-build", "ios-build", "compile-lib" } )]
[WorkflowJob(
    Name = "android-build",
    //ArtifactName = "android",
    Image = GitHubActionsImage.WindowsLatest,
    InvokedTargets = new[] { nameof(IHazAndroidBuild.CompileAndroid) },
    ImportSecrets = new[]
    {
        nameof(IHazAndroidKeystore.AndroidKeystoreName),
        nameof(IHazAndroidKeystore.AndroidKeystoreB64),
        nameof(IHazAndroidKeystore.AndroidKeystorePassword)
    })]

[WorkflowJob(
    Name = "ios-build",
    //ArtifactName = "ios",
    Image = GitHubActionsImage.MacOsLatest,
    InvokedTargets = new[] { nameof(IHazIOSBuild.CompileIos) },
    ImportSecrets = new[]
    {
         nameof(IHazAppleCertificate.P12B64),
         nameof(IHazAppleCertificate.P12Password),
         nameof(IRestoreAppleProvisioningProfile.AppleIssuerId),
         nameof(IRestoreAppleProvisioningProfile.AppleKeyId),
         nameof(IRestoreAppleProvisioningProfile.AppleAuthKeyP8),
         nameof(IRestoreAppleProvisioningProfile.AppleProfileId)
    })]
[WorkflowJob(
    Name = "compile-lib",
    ArtifactName = "nuget",
    InvokedTargets = new[] { nameof(ICompileLibrary.CompileLib), "--solution AvantiPoint.Nuke.Maui.sln" } )]
[WorkflowJob(
    Name = "publish-internal",
    Needs = new[] { "compile-lib", "android-build", "ios-build" },
    DownloadArtifacts = new[] { "nuget" },
    ImportSecrets = new[]
    {
        nameof(IPublishInternal.InHouseNugetFeed),
        nameof(IPublishInternal.InHouseApiKey),
        $"{nameof(ICodeSignNuget.CodeSignCertificate)}=CODESIGNCERTIFICATE",
        $"{nameof(ICodeSignNuget.CodeSignClientId)}=CODESIGNCLIENTID",
        $"{nameof(ICodeSignNuget.CodeSignClientSecret)}=CODESIGNCLIENTSECRET",
        $"{nameof(ICodeSignNuget.CodeSignKeyVault)}=CODESIGNKEYVAULT",
        $"{nameof(ICodeSignNuget.CodeSignTenantId)}=CODESIGNTENANTID"
    },
    InvokedTargets = new[] { nameof(IPublishInternal.PublishNuGet) })]
class Build : MauiBuild, ICompileLibrary, IPublishInternal, ICodeSignNuget
{
    public static int Main () => Execute<Build>();

    const string MasterBranch = "master";

    public GitHubActions GitHubActions => GitHubActions.Instance;

    [NerdbankGitVersioning]
    readonly NerdbankGitVersioning NerdbankVersioning;

    public override string ApplicationDisplayVersion => NerdbankVersioning.NuGetPackageVersion;
    public override long ApplicationVersion => IsLocalBuild ? DateTimeOffset.Now.ToUnixTimeSeconds() / 60 : GitHubActions.RunId;
}

Alternative

Currently multiple YAML files need to be generated. To bring these into a single file is a manual process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants