Skip to content

Commit

Permalink
Yuge refactor of GHA workflow builder.
Browse files Browse the repository at this point in the history
  • Loading branch information
damianh committed Apr 17, 2022
1 parent a391626 commit e5c4a59
Show file tree
Hide file tree
Showing 91 changed files with 2,885 additions and 1,238 deletions.
57 changes: 33 additions & 24 deletions .github/WorkflowGen/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Logicality.GitHubActionsWorkflowBuilder;
using Logicality.GitHub.Actions.Workflow;

void WriteWorkflow(WorkflowBuilder workflow, string fileName)
void WriteWorkflow(Workflow workflow, string fileName)
{
var path = "../workflows";
var yaml = workflow.Generate();
var yaml = workflow.GetYaml();
var filePath = $"{path}/{fileName}.yml";

File.WriteAllText(filePath, yaml);
Expand All @@ -18,56 +18,61 @@ void GenerateWorkflowsForLibs()
"aspnet-core",
"bullseye",
"configuration",
"github-actions-workflow-builder",
"github",
"hosting",
"lambda",
"pulumi",
"system-extensions",
"testing"
};


foreach (var lib in libs)
{
var workflow = new WorkflowBuilder($"{lib}-ci");
var workflow = new Workflow($"{lib}-ci");

var paths = new[] { $".github/workflows/{lib}-**", $"libs/{lib}**", "build/**" };

workflow.OnPullRequest()
workflow.On
.PullRequest()
.Paths(paths);

workflow.OnPush()
workflow.On
.Push()
.Branches("main")
.Paths(paths)
.Tags($"'{lib}-**'");
.Tags($"{lib}-**");

var job = workflow.AddJob("build")
var buildJob = workflow
.Job("build")
.RunsOn("ubuntu-latest")
.WithEnvironment(new Dictionary<string, string>
.Env(new Dictionary<string, string>
{
{ "GITHUB_TOKEN", "${{secrets.GITHUB_TOKEN}}" }
});

job.Checkout();
buildJob.CheckoutStep();

job.LogIntoGitHubContainerRegistry();
buildJob.LogIntoGitHubContainerRegistryStep();

job.PrintEnvironment();
buildJob.PrintEnvironmentStep();

job.AddStep("Test")
buildJob.Step()
.Name("Test")
.Run($"./build.ps1 {lib}-test")
.ShellPowerShell();

job.AddStep("Pack")
buildJob.Step()
.Name("Pack")
.Run($"./build.ps1 {lib}-pack")
.ShellPowerShell();

job.AddStep("Push")
buildJob.Step()
.Name("Push")
.If("github.event_name == 'push'")
.Run("./build.ps1 push")
.ShellPowerShell();

job.UploadArtifacts();
buildJob.UploadArtifacts();

var fileName = $"{lib}-ci";

Expand All @@ -77,21 +82,25 @@ void GenerateWorkflowsForLibs()

void GenerateCodeAnalysisWorkflow()
{
var workflow = new WorkflowBuilder("CodeQL");
var workflow = new Workflow("CodeQL");

workflow.OnPush()
workflow.On
.Push()
.Branches("main");
workflow.OnPullRequest()
workflow.On
.PullRequest()
.Branches("main");
workflow.OnSchedule("'39 8 * * 1'");
workflow.On
.Schedule("'39 8 * * 1'");

var job = workflow.AddJob("analyze")
var job = workflow.Job("analyze")
.RunsOn("ubuntu-latest")
.Permissions(
actions: Permission.Read,
contents: Permission.Read,
securityEvents: Permission.Write);

job.AddStep("");
job.Step("");
}

GenerateWorkflowsForLibs();
5 changes: 1 addition & 4 deletions .github/WorkflowGen/WorkflowGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
</PropertyGroup>

<ItemGroup>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\libs\github-actions-workflow-builder\src\GitHubActionsWorkflowBuilder\GitHubActionsWorkflowBuilder.csproj" />
<ProjectReference Include="..\..\libs\github\src\Actions.Workflow\Actions.Workflow.csproj" />
</ItemGroup>

</Project>
26 changes: 7 additions & 19 deletions .github/workflows/aspnet-core-ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# This was generated by a tool (Logicality GitHub Actions Workflow Builder).
# Edits will be overwritten.
# This was generated by tool. Edits will be overwritten.

name: aspnet-core-ci

on:
pull_request_target: {}
pull_request:
paths:
- .github/workflows/aspnet-core-**
Expand All @@ -18,42 +15,33 @@ on:
- libs/aspnet-core**
- build/**
tags:
- 'aspnet-core-**'

- aspnet-core-**
jobs:
build:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

steps:

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Log into ghcr
run: echo "${{secrets.GITHUB_TOKEN}}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Print Environment
- name: Log into GitHub Container Registry
run: echo "${{secrets.GITHUB_TOKEN}}" | docker login ghcr.io -u ${{github.actor}} --password-stdin
- name: Print Env
run: printenv
shell: bash

- name: Test
run: ./build.ps1 aspnet-core-test
shell: pwsh

- name: Pack
run: ./build.ps1 aspnet-core-pack
shell: pwsh

- name: Push
if: github.event_name == 'push'
run: ./build.ps1 push
shell: pwsh

- name: Upload artifacts
- name: Upload Artifacts
uses: actions/upload-artifact@v2
with:
name: artifacts
Expand Down
25 changes: 7 additions & 18 deletions .github/workflows/bullseye-ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# This was generated by a tool (Logicality GitHub Actions Workflow Builder).
# Edits will be overwritten.
# This was generated by tool. Edits will be overwritten.

name: bullseye-ci

on:
pull_request:
paths:
Expand All @@ -17,42 +15,33 @@ on:
- libs/bullseye**
- build/**
tags:
- 'bullseye-**'

- bullseye-**
jobs:
build:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

steps:

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Log into ghcr
run: echo "${{secrets.GITHUB_TOKEN}}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Print Environment
- name: Log into GitHub Container Registry
run: echo "${{secrets.GITHUB_TOKEN}}" | docker login ghcr.io -u ${{github.actor}} --password-stdin
- name: Print Env
run: printenv
shell: bash

- name: Test
run: ./build.ps1 bullseye-test
shell: pwsh

- name: Pack
run: ./build.ps1 bullseye-pack
shell: pwsh

- name: Push
if: github.event_name == 'push'
run: ./build.ps1 push
shell: pwsh

- name: Upload artifacts
- name: Upload Artifacts
uses: actions/upload-artifact@v2
with:
name: artifacts
Expand Down
25 changes: 7 additions & 18 deletions .github/workflows/configuration-ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# This was generated by a tool (Logicality GitHub Actions Workflow Builder).
# Edits will be overwritten.
# This was generated by tool. Edits will be overwritten.

name: configuration-ci

on:
pull_request:
paths:
Expand All @@ -17,42 +15,33 @@ on:
- libs/configuration**
- build/**
tags:
- 'configuration-**'

- configuration-**
jobs:
build:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

steps:

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Log into ghcr
run: echo "${{secrets.GITHUB_TOKEN}}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Print Environment
- name: Log into GitHub Container Registry
run: echo "${{secrets.GITHUB_TOKEN}}" | docker login ghcr.io -u ${{github.actor}} --password-stdin
- name: Print Env
run: printenv
shell: bash

- name: Test
run: ./build.ps1 configuration-test
shell: pwsh

- name: Pack
run: ./build.ps1 configuration-pack
shell: pwsh

- name: Push
if: github.event_name == 'push'
run: ./build.ps1 push
shell: pwsh

- name: Upload artifacts
- name: Upload Artifacts
uses: actions/upload-artifact@v2
with:
name: artifacts
Expand Down
9 changes: 0 additions & 9 deletions .github/workflows/gen-workflows.ps1

This file was deleted.

59 changes: 0 additions & 59 deletions .github/workflows/github-actions-workflow-builder-ci.yml

This file was deleted.

Loading

0 comments on commit e5c4a59

Please sign in to comment.